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 deploy --hotswap: set the same value as the stack, it won't be deployed. #31728

Open
2 tasks
toyotest2 opened this issue Oct 11, 2024 · 1 comment
Open
2 tasks
Labels
@aws-cdk/aws-lambda Related to AWS Lambda @aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI

Comments

@toyotest2
Copy link

Describe the feature

Problem:

cdk deploy --hotswap does not update the Lambda function's environment value.
This happens when set to the same value as the CFn stack.

Cause:

To compare the CFn stack template with the CDK project code. If the value is the same as the CFn stack template, no change is detected.

Reproduce:

  1. Continue the tutorial below to step 5. (Step 5: Deploy your application)
    https://docs.aws.amazon.com/cdk/v2/guide/serverless_example.html

  2. cdk-hello-world/lib/cdk-hello-world-stack.ts : Add environment

    const helloWorldFunction = new lambda.Function(this, 'HelloWorldFunction', {
      runtime: lambda.Runtime.NODEJS_20_X, // Choose any supported Node.js runtime
      code: lambda.Code.fromAsset('lambda'), // Points to the lambda directory
      handler: 'hello.handler', // Points to the 'hello' file in the lambda directory
      environment: { key1: "value1" },
    });
  1. cdk deploy

  2. cdk-hello-world/lib/cdk-hello-world-stack.ts: Change value2

      environment: { key1: "value2" },
  1. cdk deploy --hotswap

  2. cdk-hello-world/lib/cdk-hello-world-stack.ts: Change value1

      environment: { key1: "value1" },
  1. cdk deploy --hotswap

  2. It does not change the environment value.

Deploy Console(no changes was displayed)

$ cdk-hello-world % cdk deploy --hotswap-fallback

✨  Synthesis time: 3.01s

⚠️ The --hotswap and --hotswap-fallback flags deliberately introduce CloudFormation drift to speed up deployments
⚠️ They should only be used for development - never use them for your production Stacks!

CdkHelloWorldStack: deploying... [1/1]

 ✅  CdkHelloWorldStack (no changes)

✨  Deployment time: 0.39s

Outputs:
CdkHelloWorldStack.HelloWorldApiEndpointAD496187 = https://10gdekgh98.execute-api.ap-northeast-1.amazonaws.com/prod/
Stack ARN:
arn:aws:cloudformation:ap-northeast-1:794364220926:stack/CdkHelloWorldStack/0f7906a0-87a8-11ef-88b8-0e8ab4b43885

✨  Total time: 3.4s

Use Case

I want to do a test by returning to the values in the CFn stack template.

Proposed Solution

No response

Other Information

No response

Acknowledgements

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

CDK version used

2.158.0

Environment details (OS name and version, etc.)

macOS Sonoma

@toyotest2 toyotest2 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Oct 11, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 11, 2024
@khushail khushail self-assigned this Oct 11, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-reproduction This issue needs reproduction. labels Oct 14, 2024
@khushail
Copy link
Contributor

Hi @toyotest2 , thanks for reaching out.

The issue is reproducible -

  1. using the code, I was able to successfully deploy and see the generated environment values in lambda function -
Screenshot 2024-10-14 at 2 15 39 PM
  1. Changed the value and deployed again with hotswap -
Screenshot 2024-10-14 at 2 19 25 PM Screenshot 2024-10-14 at 2 18 47 PM
  1. changed the value back to 'value1' and deployed, there is no change and lambda function keeps the 'value2' -
Screenshot 2024-10-14 at 2 25 02 PM Screenshot 2024-10-14 at 2 27 17 PM

I tried to do the same using cdk watch but that also produced the same issue as cdk watch is on the same line of implementation as cdk deploy --hotswap and suffers the same limitations.

IMO, this should be a bug but I would leave it upto you. Also I would be marking this as P2 means it won't be immediately addressed by the team but would be on their radar. Contributions from the community are also welcome in this regard.
Thanks.

@khushail khushail added effort/medium Medium work item – several days of effort and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Oct 14, 2024
@khushail khushail removed their assignment Oct 14, 2024
@khushail khushail added @aws-cdk/core Related to core CDK functionality package/tools Related to AWS CDK Tools or CLI labels Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda @aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
Development

No branches or pull requests

2 participants