Closed garretwilson closed 9 months ago
The default is only used the first time a parameter is added to a stack (so in your case on create).
They are meant for values you want to change when you deploy the stack, you can do this with Parameter Overrides:
aws cloudformation deploy [...] --parameter-overrides Key1=Value1 Key2=Value2
If you want to update the template to change the value, you can either hardcode it in the resource:
FunctionCode: !Sub
- |
function handler(event) {
var myParam = "${MyParam}";
return request;
}
- MyParam: SomeValue
Or "misuse" a mapping
Mappings:
Constants:
default:
MyKey: SomeValue
FunctionCode: !Sub
- |
function handler(event) {
var myParam = "${MyParam}";
return request;
}
- MyParam: !FindInMap [Constants, default, MyKey]
see input provided by @benbridts
I have CloudFormation parameter:
And I have a CloudFront functiont that interpolates it using
!Sub
:I can deploy that fine:
The function shows up in the console like this, as expected:
But then I try to change the default value of my parameter:
Now if I try to deploy the CloudFormation template, it doesn't even recognize that there is a change!
If I try to find some way to force the deployment (for example changing
AutoPublish
totrue
), then the stack redeploys. But the!Sub
is not reevaluated, and even thoughMyParam
is now set to""
, the CloudFront function doesn't change and still contains a value ("FooBar"
) that no longer even exists in the template:But it gets worse. Let's say I manually modify my function so that it doesn't even contain a reference:
I can redeploy the template, and I can verify in the console that the function now simple an empty
var myParam = ""
as expected. But then I put the reference back:Remember that
MyParam
is still set to the empty string in the template file. Nevertheless, CloudFormation somehow "remembered" the old value ofMyParam
(before I changed it to""
), even and putsFooBar
back, even thoughFooBar
is nowhere in the template file at all!So I thought maybe the problem was with the empty string, so I set
MyParam
to "some other value":CloudFormation
deploy
tells me:🤦♂️
So I force an update by mucking with
AutoPublish
and get it to redeploy. ButMyFunction
still containsvar myParam = "FooBar"
even thoughMyParam
is now set to"some other value"
!This is frustrating.
But then it gets even worse!
I went to the CloudFront console and deleted the function altogether! Then I redeployed the template with the function removed from the template. Then finally I put the function back in and redeployed the stack. The function still has
"FooBar"
even though it should be a brand new function, andMyParam
is set to"some other value"
!!!🤯