ECS parameter last modified date does not match
:question: ECS parameter last modified date does not match
The Question
cdk deploy stops when creating the change set with the following error:
Parameters: [ssm:/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id:58:1618452653926] last modified date does not match with the last modified date of the retrieved parameters.

Yesterday it was still working. I did not change anything.
The ECS configuration is nothing fancy:
from aws_cdk import aws_ecs as ecs, aws_ec2 as ec2, core
class Ecs:
def __init__(self, stack: core.Stack, vpc: ec2.Vpc):
self.cluster = ecs.Cluster(
stack,
"EcsCluster",
vpc=vpc,
)
self.cluster.add_capacity(
"EcsCluserCapacity",
instance_type=ec2.InstanceType.of(
instance_class=ec2.InstanceClass.BURSTABLE3,
instance_size=ec2.InstanceSize.SMALL,
),
allow_all_outbound=True,
vpc_subnets=ec2.SubnetSelection(subnet_type=ec2.SubnetType.PRIVATE),
)
If you have an idea or need more information, please let me know :-)
Environment
- CDK CLI Version: 1.101.0 (build 149f0fc)
- Module Version: aws-cdk.aws-ecs==1.101.0
- Node.js Version: v12.16.0
- OS: OSX Big Sur 11.2.1
- Language: Python
Other information
ApiStagingStack failed: Error: Failed to create ChangeSet cdk-deploy-change-set on ApiStagingStack: FAILED, Parameters: [ssm:/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id:58:1618452653926] last modified date does not match with the last modified date of the retrieved parameters.
at /Users/tobiasnawa/.nvm/versions/node/v12.16.0/lib/node_modules/aws-cdk/lib/api/util/cloudformation.ts:227:11
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at waitFor (/Users/tobiasnawa/.nvm/versions/node/v12.16.0/lib/node_modules/aws-cdk/lib/api/util/cloudformation.ts:188:20)
at Object.waitForChangeSet (/Users/tobiasnawa/.nvm/versions/node/v12.16.0/lib/node_modules/aws-cdk/lib/api/util/cloudformation.ts:213:15)
at Object.deployStack (/Users/tobiasnawa/.nvm/versions/node/v12.16.0/lib/node_modules/aws-cdk/lib/api/deploy-stack.ts:260:32)
at CdkToolkit.deploy (/Users/tobiasnawa/.nvm/versions/node/v12.16.0/lib/node_modules/aws-cdk/lib/cdk-toolkit.ts:180:24)
at initCommandLine (/Users/tobiasnawa/.nvm/versions/node/v12.16.0/lib/node_modules/aws-cdk/bin/cdk.ts:209:9)
Failed to create ChangeSet cdk-deploy-change-set on ApiStagingStack: FAILED, Parameters: [ssm:/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id:58:1618452653926] last modified date does not match with the last modified date of the retrieved parameters.
If I do
aws ssm get-parameters --names /aws/service/ecs/optimized-ami/amazon-linux-2/recommended
it shows version 60 of the image. The error shows 58. Maybe this could be the source of the error?
{
"Parameters": [
{
"Name": "/aws/service/ecs/optimized-ami/amazon-linux-2/recommended",
"Type": "String",
"Value": "{\"schema_version\":1,\"image_name\":\"amzn2-ami-ecs-hvm-2.0.20210428-x86_64-ebs\",\"image_id\":\"ami-006fdf54c9b918959\",\"os\":\"Amazon Linux 2\",\"ecs_runtime_version\":\"Docker version 19.03.13-ce\",\"ecs_agent_version\":\"1.52.0\"}",
"Version": 60,
"LastModifiedDate": "2021-04-30T03:18:06.721000+02:00",
"ARN": "arn:aws:ssm:eu-central-1::parameter/aws/service/ecs/optimized-ami/amazon-linux-2/recommended",
"DataType": "text"
}
],
"InvalidParameters": []
}
Workaround: I changed the Ids of the ECS cluster and capacity. This created a new cluster, which has no parameter issues.
From my side the issue is resolved with this workaround. Not sure if the ticket should be kept open for further investigations of the root cause. Let me know if you need help.
I hit this, too. Following your workaround - I commented out all my ECS clusters and ran the stack to delete them. Then uncommented them, and ran again.
It's a bug in latest CDK version. I've downgraded my CDK to 1.100.0 and it works. It's broken in 1.101.0.
Not 100% sure if it's a CDK bug. If you try to update the existing CloudFormation stack with the same template it will show this error on the "Change set preview" section:
There was an error creating this change set
Parameters: [ssm:/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id:58:1618451993931] were updated before values were used
See also here: https://github.com/aws/aws-cli/issues/6106#issuecomment-825275055
I'm seeing this issue in code pipelines that run 'cdk deploy', as well as in pipelines that update my stacks usign aws cloudformation update-stack ....
Seems like it's a combination of a glitch in cloudformation and/or awscli and/or CDK...
I got this one today after updating to 1.102.0 (though I'm not sure if the update is related or not). I am not using codepipelines in this stack. The error was triggered in a parent stack that created some shared VPC resources including an ECS cluster.
❌ STACKNAME failed: Error: Failed to create ChangeSet cdk-deploy-change-set on STACKNAME: FAILED, Parameters: [ssm:/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2:46:1619654080554] last modified date does not match with the last modified date of the retrieved parameters.
I just downgraded to 1.101.0 from 1.102.0 and it fixed my issue... partially.
I have a stack that is managed by cdk and I'm getting a similar error when I try to update it by doing:
if aws cloudformation update-stack --stack-name staging-legacy-ecs --use-previous-template --parameters "$(aws cloudformation describe-stacks --stack-name staging-legacy-ecs --query 'Stacks[0].Parameters')" --capabilities CAPABILITY_IAM CAPABILITY_NAMED_IAM 2>err.log; then aws cloudformation wait stack-update-complete --stack-name staging-legacy-ecs; else grep 'No updates are to be performed' err.log || (cat err.log && exit 1); fi
An error occurred (ValidationError) when calling the UpdateStack operation: Parameters: [ssm:/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id:58:1618453901392] were updated before values were used
The current template of that stack was generated with CDK 1.101.0.
Ran into the same issue with the amazon linux AMI parameter for the BastionHostLinux construct.
Error:
Parameters: [ssm:/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2:45:1619654082094] last modified date does not match with the last modified date of the retrieved parameters.
Latest version, and the one in the changeset, was actually "{{resolve:ssm:/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2:46:1620093000908}}"
Downgrading back to 1.101.0 as mentioned in above comments also solved it.
@encron had it with the BastionHost as well. I believe the reason why downgrading fixes it is that CDK no longer tries to update the stack because the template stays the same. I suspect that if you try to update the template of this stack, you will see this failure again, despite having downgraded to 1.101.0
I've encountered this not in ECS but in my VPC stack that contains bastion instance (ec2.BastionHostLinux):
vpc (vpc) failed: Error: Failed to create ChangeSet cdk-deploy-change-set on vpc: FAILED, Parameters: [ssm:/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2:45:1619654085749] last modified date does not match with the last modified date of the retrieved parameters.
at /home/malanius/.nvm/versions/node/v16.0.0/lib/node_modules/aws-cdk/lib/api/util/cloudformation.ts:227:11
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at waitFor (/home/malanius/.nvm/versions/node/v16.0.0/lib/node_modules/aws-cdk/lib/api/util/cloudformation.ts:188:20)
at Object.waitForChangeSet (/home/malanius/.nvm/versions/node/v16.0.0/lib/node_modules/aws-cdk/lib/api/util/cloudformation.ts:213:15)
at Object.deployStack (/home/malanius/.nvm/versions/node/v16.0.0/lib/node_modules/aws-cdk/lib/api/deploy-stack.ts:260:32)
at CdkToolkit.deploy (/home/malanius/.nvm/versions/node/v16.0.0/lib/node_modules/aws-cdk/lib/cdk-toolkit.ts:180:24)
at initCommandLine (/home/malanius/.nvm/versions/node/v16.0.0/lib/node_modules/aws-cdk/bin/cdk.ts:209:9)
Failed to create ChangeSet cdk-deploy-change-set on vpc: FAILED, Parameters: [ssm:/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2:45:1619654085749] last modified date does not match with the last modified date of the retrieved parameters.
Same result with 1.102.0, 1.101.0 and 1.100.0. Won't try more as it takes too much time from the deploy command to that error to occur.
Interesting is that the diff on the vpc stack doesn't show any changes but during deployment of another stack that has a dependency on the vpc one it tries to create that failing changeset.
The workaround worked for a couple of days. Yesterday I had to use the workaround again.
Same error here using ecs. The only workaround that worked for me was to comment the ecs, deploy destroying the cluster, and uncommenting to recreate everything.
I had exactly the same problem as @Bullettoothtobi. It broke overnight 6 days ago and then again yesterday. I also “solved” it by undeploying the stack and then redeploying it.
To be honest, I am not sure that this is a CDK problem, but our AWS support team is as silent as the CDK team until now, so there is no way to know what is going on.
I have been plagued by this issue recently too. Luckily the work has been in dev so I can just delete and recreate the stack, but I don't want to have to do that in production.
One thing I've noticed which may be helpful in troubleshooting is that when I hit this issue, it takes a very long time in the "creating CloudFormation changeset" step. Normally this happens in seconds. When I hit this error, that step takes closer to 5 minutes.
Run cdk synth and update stack manually using generated CFN template through AWS console (update stack, not create changeset). After that it will work.
So it seems like this is related to the new cloudformation feature for dynamic parameter references https://aws.amazon.com/about-aws/whats-new/2021/04/now-reference-latest-aws-systems-manager-parameter-values-in-aws-cloudformation-templates-without-specifying-parameter-versions/.
We are removing the usage of this feature in the next cdk release which should prevent stacks from getting into this state and are working with cloudformation on a solution to the stacks that are currently stuck. Will provide updates here as they come.
@Bullettoothtobi and anyone else experiencing this issue. Can you test the latest release, v1.103.0, and see if this resolves your issue?
This is hard for us to reproduce because CFN has made multiple changes related to the dynamic params feature since they discovered this breakage and we can no longer get new stacks into the state where this error occurs.
I'd be happy to test but I recently ported to 2.0 RC1. Any chance a fix for that can be released as well?
@blaenk v2 is automatically released periodically and should pick up this change as part of that. I'm not sure why the latest release was 12 days ago but we will check on that process and see if we can get it unstuck.