Skip to content

(ECS): Missing support for environment files for Fargate deployments #18226

@sergekukharev

Description

@sergekukharev

Description

I'm trying to configure my Fargate service to use Environment Files. The official documentation says 1:

Support for environment files is restricted to the EC2 launch type for files hosted on S3.

At the same time, Fargate supports Environment Files for a long time 23.

Is there any chance this feature will be added soon? Since it's supported by EC2 already, should be an easy win.

Use Case

I need this to manage my secrets and env variables in a more secure way. Any workaround ideas are appreciated.

Proposed Solution

Environment files are supported fully for Fargate deployments. Bonus points - it's possible to provide env files configuration in ApplicationLoadBalancedTaskImageOptions

Other information

Unit tests are misleading for this configuration. The following test will pass, while cdk synth won't add the environment file to the template:

// Code
// ...
taskDefinition.addContainer("StaticoonBotContainerWeb", ContainerDefinitionOptions.builder()
                        .containerName("web")
                        .portMappings(List.of(PortMapping.builder().hostPort(1234).containerPort(1234).build()))
                        .image(image)
                        .environmentFiles(List.of(new S3EnvironmentFile(bucket, "<key>")))
                        .build());
// ...

// Test
@Test
void usesS3EnvironmentFile() {
    template.hasResourceProperties("AWS::ECS::TaskDefinition", Map.of(
            "ContainerDefinitions", Match.arrayWith(List.of(Match.objectLike(Map.of(
                    "EnvironmentFiles", List.of(Map.of(
                            "Type", "s3",
                            "Value", "arn:aws:s3:::<bucket>/<key>"
                    ))
            ))))
    ));
}

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change

Footnotes

  1. https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ecs-readme.html#environment-variables

  2. https://aws.amazon.com/blogs/containers/latest-updates-to-aws-fargate-for-amazon-ecs/

  3. https://github.com/aws/containers-roadmap/issues/371

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-ecsRelated to Amazon Elastic Containereffort/mediumMedium work item – several days of effortfeature-requestA feature should be added or improved.p2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions