Skip to content

Commit

Permalink
fix(cli): support attributes of DynamoDB Tables for hotswapping
Browse files Browse the repository at this point in the history
Fixes aws#19421
  • Loading branch information
skinny85 committed Mar 29, 2022
1 parent 6eb775e commit 4b37410
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
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',
}),
});
});

0 comments on commit 4b37410

Please sign in to comment.