I have a custom resource used to get the API key from API gateway and send it as a header to Cloudfront. When i am creating a stack my custom:resource
is triggering since it is creating logical ID for first time. But when i update the stack(i.e Changing the API KEY name) Then the API key resource of type AWS::ApiGateway::ApiKey
will create a new Logical ID when in turn create a new API key, At this point my custom:resource
is not invoking since it has same same logical ID because of this my cloudfront is having old API Key rather than new one.
Is there a way to invoke my custom:resource
everytime a update happened to my stack?
As a workaround i am changing the Logical Id
of custom:resource
to trigger it whenever i am updating a resource in my stack. But this is little difficult since logicalId is shared as a reference to many resources.
BTW my custom resource is attached to a lambda function. I even tried changing the Version
field and also tried adding values to properties field (i.e.Stackname,parameters etc) but still it is not invoking.
{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
"MyFrontEndTest" : {
"Type": "Custom::PingTester",
"Version" : "1.0", -->Even changed the version to 2.0
"Properties" : {
"ServiceToken": "arn:aws:lambda:us-east-1:*****",
"InputparameterName" : "MYvalue" -->Added this field
}
}
}
Thanks Any help is appreciated
AWS CloudFormation provides two methods for updating stacks: direct update or creating and executing change sets. When you directly update a stack, you submit changes and AWS CloudFormation immediately deploys them. Use direct updates when you want to quickly deploy your updates.
Sign in to the Amazon Web Services Management Console and open the Amazon CloudFormation console at https://console.amazonaws.cn/cloudformation . In the Amazon CloudFormation console , from the list of stacks, select the running stack that you want to update. In the stack details pane, choose Update.
Update with No Interruption. AWS CloudFormation updates the resource without disrupting operation of that resource and without changing the resource's physical ID. For example, if you update certain properties on an AWS::CloudTrail::Trail resource, AWS CloudFormation updates the trail without disruption.
One trick to get the custom resource to execute a lambda when the stack is updated is to configure the custom resource to pass all stack parameters to the lambda function. If any parameters change on stack update, the custom resource will change and trigger the lambda. Just ignore the unneeded keys in the lambda event data. This won't do anything for the scenario when just the template is updated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With