Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-ecs-patterns: Ability to add a Cloudfront Distribution to the ApplicationLoadBalancedFargateService #30912

Open
2 tasks
mdvertola opened this issue Jul 21, 2024 · 1 comment
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p3

Comments

@mdvertola
Copy link

Describe the feature

The ApplicationLoadBalancedFargateService makes for super easy deployments of modern SSR web applications (among many other things of course). The construct appears to be fundamentally designed as a "one stop shop" for these services as it handles everything from networking, scaling, domain and cert setup, etc.

Following the ethos of this design pattern, I feel it would be useful if there were a way to attach a CloudFront distribution between the domain and the load balancer out of the box with the ApplicationLoadBalancedFargateService construct.

Use Case

When deploying a NextJS site (for example) via the ApplicationLoadBalancedFargateService, large static content such as images and videos take a longer time to load than they would if they were served with Cloudfront.

Serving this content behind a Cloudfront distribution would drastically improve this performance. Incorporating it into the ApplicationLoadBalancedFargateService would further the design pattern of a "one-stop shop"/easily deployable fargate service to support a variety of tasks.

Proposed Solution

// Create a load-balanced Fargate service for a nextjs landing page/website
    const landingService =
      new ecsPatterns.ApplicationLoadBalancedFargateService(
        this,
        "landingService",
        {
          cluster: this.cluster,
          desiredCount: 1,
          ...
          cloudfrontDistribution: new cdk.aws_cloudfront.Distribution(...),  <---- addition of CloudFront dist in construct
          redirectHTTP: true,
          certificate: this.cert,
          domainName: `www.${props.domainName}`,
          domainZone: route53.HostedZone.fromLookup(
            this,
            "landingServiceDomainZone",
            {
              domainName: props.domainName,
            }
          ),
        }
      );

Other Information

Another thing that may be worth considering here is a forced full invalidation (i.e., invalidate /*) on the distribution when a change is detected in the service so that we don't have any hanging cache across deployments.

Acknowledgements

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

CDK version used

2.149.0

Environment details (OS name and version, etc.)

macOS Sonoma 14.5

@mdvertola mdvertola added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 21, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ecs-patterns Related to ecs-patterns library label Jul 21, 2024
@pahud
Copy link
Contributor

pahud commented Jul 22, 2024

Thank you. aws-ecs-patterns is an opinionated L3 construct. Having additional cloudfront support is awesome but it may add the maintenance complexity. For example, other people might suggest to have optional AWS Global Accelerator support or WAF support. I am not sure if it's a good idea to keep adding features like this on it but you can definitely build your own L3 construct on top of it. Making this a p3 feat request and please help us prioritize with 👍 .

@pahud pahud added p3 effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ecs-patterns Related to ecs-patterns library effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p3
Projects
None yet
Development

No branches or pull requests

2 participants