View a markdown version of this page

ECS architecture - Dynamic Image Transformation for Amazon CloudFront

ECS architecture

For the ECS architecture, deploy the solution as-is to provision all necessary resources. Then manually configure your existing CloudFront distribution to use the solution’s resources.

Deploy the solution

  1. Deploy the ECS architecture CloudFormation template without specifying an existing CloudFront distribution.

  2. The solution will create its own CloudFront distribution along with all required resources including the Application Load Balancer and CloudFront function.

Configure your existing distribution

After the solution deployment is complete:

  1. In the CloudFront console, navigate to your existing CloudFront distribution.

  2. Select the Origins tab and click Create origin.

  3. Set the Origin domain as the Application Load Balancer DNS name. This value can be found in the CloudFormation stack outputs under the key LoadBalancerDNS.

  4. Leave the Origin path empty (default).

  5. Select Create origin.

Create behavior for image processing

  1. In your existing CloudFront distribution, select the Behaviors tab and choose Create behavior.

  2. Set the Path pattern for image requests (e.g., /images/* or your preferred pattern).

  3. Set the Origin to the ALB origin created in the previous step.

  4. Set the Viewer Protocol policy to Redirect HTTP to HTTPS.

  5. Set the Cache Policy to the one named dit-chache-policy (created by the solution).

  6. Set the Response headers policy to the one named SecurityHeadersPolicy (created by the solution).

  7. Set the Viewer request Function type to CloudFront Functions, and the Function ARN to the one named dit-header-normalization (created by the solution).

  8. Select Create behavior.

This approach allows you to leverage the solution’s provisioned resources while maintaining control over your existing CloudFront distribution configuration.