Skip to content

Commit 32654f5

Browse files
authored
fix(cli): hotswap doesn't update SSM parameter environment variables properly (#26382)
Closes #25387 Closes #25483 The actual value for a CfnParameter backed by a SSM parameter is returned via `ResolvedValue` (and only for SSM parameters, [doc](https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_Parameter.html#API_Parameter_Contents)). We use the field from DescirbeStacks API response to populate `stackParams`, instead of `ParameterValue`, which is just a parameter's name. As far as I checked it is not a breaking change. The `parameter` field is not a public API, and internally the values of SSM parameters are only used for hotswap. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 576a851 commit 32654f5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

packages/aws-cdk/lib/api/util/cloudformation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ export class CloudFormationStack {
156156
if (!this.exists) { return {}; }
157157
const ret: Record<string, string> = {};
158158
for (const param of this.stack!.Parameters ?? []) {
159-
ret[param.ParameterKey!] = param.ParameterValue!;
159+
ret[param.ParameterKey!] = param.ResolvedValue ?? param.ParameterValue!;
160160
}
161161
return ret;
162162
}

packages/aws-cdk/test/api/deploy-stack.test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,36 @@ test('correctly passes CFN parameters when hotswapping', async () => {
149149
expect(tryHotswapDeployment).toHaveBeenCalledWith(expect.anything(), { A: 'A-value', B: 'B=value' }, expect.anything(), expect.anything(), HotswapMode.FALL_BACK);
150150
});
151151

152+
test('correctly passes SSM parameters when hotswapping', async () => {
153+
// GIVEN
154+
givenStackExists({
155+
Parameters: [
156+
{ ParameterKey: 'SomeParameter', ParameterValue: 'ParameterName', ResolvedValue: 'SomeValue' },
157+
],
158+
});
159+
160+
// WHEN
161+
await deployStack({
162+
...standardDeployStackArguments(),
163+
stack: testStack({
164+
stackName: 'stack',
165+
template: {
166+
Parameters: {
167+
SomeParameter: {
168+
Type: 'AWS::SSM::Parameter::Value<String>',
169+
Default: 'ParameterName',
170+
},
171+
},
172+
},
173+
}),
174+
hotswap: HotswapMode.FALL_BACK,
175+
usePreviousParameters: true,
176+
});
177+
178+
// THEN
179+
expect(tryHotswapDeployment).toHaveBeenCalledWith(expect.anything(), { SomeParameter: 'SomeValue' }, expect.anything(), expect.anything(), HotswapMode.FALL_BACK);
180+
});
181+
152182
test('call CreateStack when method=direct and the stack doesnt exist yet', async () => {
153183
// WHEN
154184
await deployStack({

0 commit comments

Comments
 (0)