Skip to content

Commit a1dcaa6

Browse files
authored
fix(cli): handle attributes of AWS::KMS::Key when hotswapping (#30112)
### Issue # (if applicable) Closes #25418. ### Reason for this change KMS Keys cannot be referenced in hotswappable resources. CDK complains that this is a limitation: ``` Could not perform a hotswap deployment, because the CloudFormation template could not be resolved: We don't support attributes of the 'AWS::KMS::Key' resource. This is a CDK limitation. Please report it at https://github.com/aws/aws-cdk/issues/new/choose. ``` ### Description of changes Add KMS keys to the supported list of resource attributes for hotswapping. ### Description of how you validated changes Tests ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9def360 commit a1dcaa6

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

packages/aws-cdk/lib/api/evaluate-cloudformation-template.ts

+1
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ const RESOURCE_TYPE_ATTRIBUTES_FORMATS: { [type: string]: { [attribute: string]:
504504
'AWS::AppSync::GraphQLApi': { ApiId: appsyncGraphQlApiApiIdFmt },
505505
'AWS::AppSync::FunctionConfiguration': { FunctionId: appsyncGraphQlFunctionIDFmt },
506506
'AWS::AppSync::DataSource': { Name: appsyncGraphQlDataSourceNameFmt },
507+
'AWS::KMS::Key': { Arn: stdSlashResourceArnFmt },
507508
};
508509

509510
function iamArnFmt(parts: ArnParts): string {

packages/aws-cdk/test/api/hotswap/state-machine-hotswap-deployments.test.ts

+63
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,69 @@ describe.each([HotswapMode.FALL_BACK, HotswapMode.HOTSWAP_ONLY])('%p mode', (hot
677677
});
678678
});
679679

680+
test('knows how to handle attributes of the AWS::KMS::Key resource', async () => {
681+
// GIVEN
682+
setup.setCurrentCfnStackTemplate({
683+
Resources: {
684+
Key: {
685+
Type: 'AWS::KMS::Key',
686+
Properties: {
687+
Description: 'magic-key',
688+
},
689+
},
690+
Machine: {
691+
Type: 'AWS::StepFunctions::StateMachine',
692+
Properties: {
693+
DefinitionString: '{}',
694+
StateMachineName: 'my-machine',
695+
},
696+
},
697+
},
698+
});
699+
setup.pushStackResourceSummaries(
700+
setup.stackSummaryOf('Key', 'AWS::KMS::Key', 'a-key'),
701+
);
702+
const cdkStackArtifact = setup.cdkStackArtifactOf({
703+
template: {
704+
Resources: {
705+
Key: {
706+
Type: 'AWS::KMS::Key',
707+
Properties: {
708+
Description: 'magic-key',
709+
},
710+
},
711+
Machine: {
712+
Type: 'AWS::StepFunctions::StateMachine',
713+
Properties: {
714+
DefinitionString: {
715+
'Fn::Join': ['', [
716+
'{"KeyId":"',
717+
{ Ref: 'Key' },
718+
'","KeyArn":"',
719+
{ 'Fn::GetAtt': ['Key', 'Arn'] },
720+
'"}',
721+
]],
722+
},
723+
StateMachineName: 'my-machine',
724+
},
725+
},
726+
},
727+
},
728+
});
729+
730+
// THEN
731+
const result = await hotswapMockSdkProvider.tryHotswapDeployment(hotswapMode, cdkStackArtifact);
732+
733+
expect(result).not.toBeUndefined();
734+
expect(mockUpdateMachineDefinition).toHaveBeenCalledWith({
735+
stateMachineArn: 'arn:aws:states:here:123456789012:stateMachine:my-machine',
736+
definition: JSON.stringify({
737+
KeyId: 'a-key',
738+
KeyArn: 'arn:aws:kms:here:123456789012:key/a-key',
739+
}),
740+
});
741+
});
742+
680743
test('does not explode if the DependsOn changes', async () => {
681744
// GIVEN
682745
setup.setCurrentCfnStackTemplate({

0 commit comments

Comments
 (0)