Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): support attributes of DynamoDB Tables for hotswapping #19620

Merged
merged 2 commits into from
Apr 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ const RESOURCE_TYPE_ATTRIBUTES_FORMATS: { [type: string]: { [attribute: string]:
// the name attribute of the EventBus is the same as the Ref
Name: parts => parts.resourceName,
},
'AWS::DynamoDB::Table': { Arn: stdSlashResourceArnFmt },
'AWS::AppSync::GraphQLApi': { ApiId: appsyncGraphQlApiApiIdFmt },
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,3 +558,82 @@ test('knows how to handle attributes of the AWS::Events::EventBus resource', asy
}),
});
});

test('knows how to handle attributes of the AWS::DynamoDB::Table resource', async () => {
// GIVEN
setup.setCurrentCfnStackTemplate({
Resources: {
Table: {
Type: 'AWS::DynamoDB::Table',
Properties: {
KeySchema: [{
AttributeName: 'name',
KeyType: 'HASH',
}],
AttributeDefinitions: [{
AttributeName: 'name',
AttributeType: 'S',
}],
BillingMode: 'PAY_PER_REQUEST',
},
},
Machine: {
Type: 'AWS::StepFunctions::StateMachine',
Properties: {
DefinitionString: '{}',
StateMachineName: 'my-machine',
},
},
},
});
setup.pushStackResourceSummaries(
setup.stackSummaryOf('Table', 'AWS::DynamoDB::Table', 'my-dynamodb-table'),
);
const cdkStackArtifact = setup.cdkStackArtifactOf({
template: {
Resources: {
Table: {
Type: 'AWS::DynamoDB::Table',
Properties: {
KeySchema: [{
AttributeName: 'name',
KeyType: 'HASH',
}],
AttributeDefinitions: [{
AttributeName: 'name',
AttributeType: 'S',
}],
BillingMode: 'PAY_PER_REQUEST',
},
},
Machine: {
Type: 'AWS::StepFunctions::StateMachine',
Properties: {
DefinitionString: {
'Fn::Join': ['', [
'{"TableName":"',
{ Ref: 'Table' },
'","TableArn":"',
{ 'Fn::GetAtt': ['Table', 'Arn'] },
'"}',
]],
},
StateMachineName: 'my-machine',
},
},
},
},
});

// THEN
const result = await hotswapMockSdkProvider.tryHotswapDeployment(cdkStackArtifact);

expect(result).not.toBeUndefined();
expect(mockUpdateMachineDefinition).toHaveBeenCalledWith({
stateMachineArn: 'arn:aws:states:here:123456789012:stateMachine:my-machine',
definition: JSON.stringify({
TableName: 'my-dynamodb-table',
TableArn: 'arn:aws:dynamodb:here:123456789012:table/my-dynamodb-table',
}),
});
});