Skip to content

Commit

Permalink
fix(cli): hotswap doesn't update SSM parameter environment variables …
Browse files Browse the repository at this point in the history
…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*
  • Loading branch information
tmokmss committed Jul 18, 2023
1 parent 576a851 commit 32654f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/aws-cdk/lib/api/util/cloudformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export class CloudFormationStack {
if (!this.exists) { return {}; }
const ret: Record<string, string> = {};
for (const param of this.stack!.Parameters ?? []) {
ret[param.ParameterKey!] = param.ParameterValue!;
ret[param.ParameterKey!] = param.ResolvedValue ?? param.ParameterValue!;
}
return ret;
}
Expand Down
30 changes: 30 additions & 0 deletions packages/aws-cdk/test/api/deploy-stack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,36 @@ test('correctly passes CFN parameters when hotswapping', async () => {
expect(tryHotswapDeployment).toHaveBeenCalledWith(expect.anything(), { A: 'A-value', B: 'B=value' }, expect.anything(), expect.anything(), HotswapMode.FALL_BACK);
});

test('correctly passes SSM parameters when hotswapping', async () => {
// GIVEN
givenStackExists({
Parameters: [
{ ParameterKey: 'SomeParameter', ParameterValue: 'ParameterName', ResolvedValue: 'SomeValue' },
],
});

// WHEN
await deployStack({
...standardDeployStackArguments(),
stack: testStack({
stackName: 'stack',
template: {
Parameters: {
SomeParameter: {
Type: 'AWS::SSM::Parameter::Value<String>',
Default: 'ParameterName',
},
},
},
}),
hotswap: HotswapMode.FALL_BACK,
usePreviousParameters: true,
});

// THEN
expect(tryHotswapDeployment).toHaveBeenCalledWith(expect.anything(), { SomeParameter: 'SomeValue' }, expect.anything(), expect.anything(), HotswapMode.FALL_BACK);
});

test('call CreateStack when method=direct and the stack doesnt exist yet', async () => {
// WHEN
await deployStack({
Expand Down

0 comments on commit 32654f5

Please sign in to comment.