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

CDK Hotswap Feature : AWS::CloudFront::Distribution Attribute Support #29224

Open
bellomal opened this issue Feb 22, 2024 · 4 comments
Open

CDK Hotswap Feature : AWS::CloudFront::Distribution Attribute Support #29224

bellomal opened this issue Feb 22, 2024 · 4 comments
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. effort/medium Medium work item – several days of effort p3

Comments

@bellomal
Copy link

Describe the bug

When doing a hotswap deployment of an ECS instance, the following error was thrown:

Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: We don't support attributes of the 'AWS::CloudFront::Distribution' resource. This is a CDK limitation. Please report it at https://github.com/aws/aws-cdk/issues/new/choose

Looking at the cdk synth output (check current behavior), we can see that one of the ECS instance environment variables is a Distribution DomainName.

Opening this ticket as instructed by the error message. If this isn't the correct place for this ticket, let me know and I can reroute it to the appropriate location.

Expected Behavior

The hotswap deployment to succeed, since the Distribution DomainName has not changed.

Current Behavior

The hotswap deployment fails. As far as I can tel, this is because the DomainName attribute of the Distribution resource is not supported. See the below snippet of the cdk synth result for more context.

  ServiceClusterTaskDefF486EB2A:
    Type: AWS::ECS::TaskDefinition
    Properties:
      ContainerDefinitions:
        - Cpu: 4096
          Environment:
            - Name: STAGE
              Value: beta
            - Name: APPLICATION_NAME
              Value: Service
            - Name: ENDPOINT
              Value:
                Fn::GetAtt:
                  - ASVSelectionServiceCuratedChannelscuratedChannelDistribution0D56EA6F
                  - DomainName

Reproduction Steps

Run a hotswap deployment for an ECS instance that contains a Distribution attribute in it's definition.

Possible Solution

Similar to #21320, allow hotswap to tolerate the use of this attribute if it's value hasn't been changed.

Additional Information/Context

No response

CDK CLI Version

2.127.0

Framework Version

No response

Node.js Version

14.x

OS

Linux

Language

TypeScript

Language Version

No response

Other information

No response

@bellomal bellomal added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 22, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Feb 22, 2024
@pahud
Copy link
Contributor

pahud commented Feb 23, 2024

I guess your CDK application might contain the cloudfront distribution and you are referencing the distribution ID in the container env var. The hotswap would not be able to resolve the ENDPOINT locally from the DomainName attribute. But this is just my guess. Would you be able to provide a tiny minimal reproducible and self-contained code snippet that we can copy/paste to deploy in our environment?

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Feb 23, 2024
@bellomal
Copy link
Author

Thanks for taking a look! That's right - the CDK code creates a cloudfront distribution and exports the DomainName. Later, the DomainName is added to the environment variables for the ECS container.

I'll see if I can get together a code snippet - it might take a while to put something together since I can't publish the code directly.

@bellomal
Copy link
Author

bellomal commented Feb 23, 2024

Created a public Github repo that you can use to reproduce the issue:

https://github.com/bellomal/HelloWorldCDKApp/tree/main

Steps to reproduce are in the README. I'll paste them here just in case:

  1. cdk deploy
  2. Update the container image registry on line 45 of hello_world_cdk_app-stack.ts to something else (eg amazon/amazon-ecs-sample or public.ecr.aws/ecs-sample-image/amazon-ecs-sample:latest)
  3. cdk deploy --hotswap

@bellomal
Copy link
Author

bellomal commented Feb 23, 2024

Side question - is there some way I can least pull the value of distributionName out and pass it as a string instead of using Fn::GetAtt: for that environment variable in the CF template?

EDIT:
Looked into this further, and as a hacky solution I tried adding the following line of code: const distributionEndpoint = new CfnOutput(this, "DistributionEndpoint", { value: bucketEndpoint.distributionDomainName }) and referenced distributionEndpoint.value in the environment variables instead. The hotswap still failed with the same error.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Feb 24, 2024
@pahud pahud added p3 and removed p2 labels Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. effort/medium Medium work item – several days of effort p3
Projects
None yet
Development

No branches or pull requests

2 participants