aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.56k stars 3.87k forks source link

aws-cdk: deploy metadata changes without resource changes #28205

Open JohnYoungers opened 10 months ago

JohnYoungers commented 10 months ago

Describe the bug

I have an embedded secret resolve that I'd like re-calculated on-demand for a given stack: it sounds like the easiest way to accomplish this is to add an item to the template that will result in a small change in order to trigger checking the secret's latest value.

To do so I've added this to the example stack: this.addMetadata("SecretResolveTrigger", new Date());

Running cdk diff will display the change:

Metadata
[~] Metadata SecretResolveTrigger: 2023-11-29T20:27:19.233Z to 2023-11-30T13:49:58.970Z

However, running cdk deploy will not update the value:

my-stack
my-stack: deploying... [1/1]
my-stack: creating CloudFormation changeset...

 ✅  my-stack (no changes)

Is there a way to update the template even when there are no changes? Or is there a better way to re-trigger an embedded resolve?

Expected Behavior

I'd expect the metadata to be updated in the template even though no other resource was updated

Current Behavior

Nothing is updated in cloudformation

Reproduction Steps

Create a stack, including an .addMetadata("SecretResolveTrigger", new Date()); entry, and run npx cdk deploy twice: notice the metadata was not updated the second time

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.81.0

Framework Version

No response

Node.js Version

21.2.0

OS

Windows 10

Language

TypeScript

Language Version

5.2.2

Other information

No response

khushail commented 10 months ago

Hi @JohnYoungers ,thanks for reaching out. You could try using this flag "--force" - https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/README.md#cdk-deploy

cdk deploy --force -v

Here is a detailed explanation of how to use '--force'.

Let us know if this works for you.

JohnYoungers commented 10 months ago

Hi @khushail - adding --force -v seems to result in the same behavior:

[12:06:49] Command line arguments: {
  _: [ 'deploy' ],
  force: true,
  f: true,
  v: 1,
  verbose: 1,
  ...
...
[12:07:05] my-stack: checking if we can skip deploy
[12:07:05] my-stack: forced deployment
[12:07:05] my-stack: deploying...
[12:07:05] Removing existing change set with name cdk-deploy-change-set if it exists
[12:07:05] Attempting to create ChangeSet with name cdk-deploy-change-set to update stack my-stack
my-stack: creating CloudFormation changeset...
[12:07:05] Initiated creation of changeset: arn:aws:cloudformation:us-east-1:{account}:changeSet/cdk-deploy-change-set/{guid}; waiting for it to finish creating...
[12:07:05] Waiting for changeset cdk-deploy-change-set on stack my-stack to finish creating...
[12:07:06] No changes are to be performed on my-stack.
[12:07:06] Deleting empty change set arn:aws:cloudformation:us-east-1:{account}:changeSet/cdk-deploy-change-set/{guid}
jkoepcke commented 8 months ago

We had the same issue, even though for us it was not an issue. However, since recently we can see that behavior changed, now metadata updates are not only showing in diff, but lead to a Stack update. Not sure if a change in Cloudformation or CDK caused this.

jkoepcke commented 8 months ago

Here we have to opposite request.