(aws-ecs) FargateTaskDefinition EnvironmentFile.fromBucket fails
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
Description
### Description
When creating a Fargate Task Definition with CDK the task pulling an env file from S3 fails with this error "ResourceInitializationError: failed to download env files: file download command: non empty error stream: RequestCanceled: request context canceled caused by: context deadline exceeded" but what appears to be the exact same configuration created in the console by hand works.
### What I'm trying
```
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecr from '@aws-cdk/aws-ecr';
import * as ecs from '@aws-cdk/aws-ecs';
import * as ecs_patterns from '@aws-cdk/aws-ecs-patterns';
import * as s3 from '@aws-cdk/aws-s3';
import * as cdk from '@aws-cdk/core';
import * as iam from '@aws-cdk/aws-iam';
export class EcsFargateService extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const vpc = ec2.Vpc.fromLookup(this, 'DefaultVPC',{isDefault: true});
const cluster = new ecs.Cluster(this, "docker-demo", {
vpc: vpc
});
const ecRepo = ecr.Repository.fromRepositoryName(this, 'ecRepo', 'docker-demo');
const iamRole = iam.Role.fromRoleArn(
this,
'IamRole',
'arn:aws:iam::##########:role/ecsTaskExecutionRole'
);
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDef', {
executionRole: iamRole,
taskRole: iamRole
});
const s3Bucket = s3.Bucket.fromBucketName(this, 's3Bucket', 'cdk-docker-demo');
taskDefinition.addContainer('DefaultContainer', {
image: ecs.ContainerImage.fromEcrRepository(ecRepo),
memoryLimitMiB: 256,
environmentFiles: [
ecs.EnvironmentFile.fromBucket(s3Bucket, 'demo-env-file.env'),
],
});
const ecsService = new ecs.FargateService(this, 'Service', {
cluster,
taskDefinition,
platformVersion: ecs.FargatePlatformVersion.VERSION1_4
});
}
}
```
### IAM (that works in the console just fine)
```
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:Get*",
"s3:List*"
],
"Resource": "*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ecr:GetAuthorizationToken",
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "*"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"ecr:BatchCheckLayerAvailability",
"ecr:GetDownloadUrlForLayer",
"ecr:BatchGetImage"
],
"Resource": "arn:aws:ecr:us-east-1:#######:repository/docker-demo",
"Effect": "Allow"
},
{
"Action": "ecr:GetAuthorizationToken",
"Resource": "*",
"Effect": "Allow"
}
]
}
```
### Environment
- **CDK CLI Version :** 1.84.0
- **Framework Version:** ????
- **Node.js Version:** v12.19.0
- **OS :** MacOS 10.15.7
- **Language (Version):** TypeScript
### Other
Maybe related: https://stackoverflow.com/questions/65807337/fargate-containers-intermittently-fail-due-to-s3-environment-files-timeout/65913027#65913027
---
This is :bug: Bug Report
Contributor guide
Assessment
This issue has not been assessed yet.