Skip to content
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
48 changes: 36 additions & 12 deletions src/__tests__/__snapshots__/dataSources.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ exports[`DataSource DynamoDB should generate Resource with default deltaSync 1`]
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"dynamodb",
{
"Ref": "AWS::Region",
Expand All @@ -344,7 +346,9 @@ exports[`DataSource DynamoDB should generate Resource with default deltaSync 1`]
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"dynamodb",
{
"Ref": "AWS::Region",
Expand Down Expand Up @@ -449,7 +453,9 @@ exports[`DataSource DynamoDB should generate Resource with default role 1`] = `
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"dynamodb",
{
"Ref": "AWS::Region",
Expand All @@ -474,7 +480,9 @@ exports[`DataSource DynamoDB should generate Resource with default role 1`] = `
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"dynamodb",
{
"Ref": "AWS::Region",
Expand Down Expand Up @@ -581,7 +589,9 @@ exports[`DataSource DynamoDB should generate default role with a Ref for the tab
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"dynamodb",
{
"Ref": "AWS::Region",
Expand All @@ -608,7 +618,9 @@ exports[`DataSource DynamoDB should generate default role with a Ref for the tab
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"dynamodb",
{
"Ref": "AWS::Region",
Expand Down Expand Up @@ -713,7 +725,9 @@ exports[`DataSource DynamoDB should generate default role with custom region 1`]
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"dynamodb",
"us-east-2",
{
Expand All @@ -736,7 +750,9 @@ exports[`DataSource DynamoDB should generate default role with custom region 1`]
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"dynamodb",
"us-east-2",
{
Expand Down Expand Up @@ -1190,7 +1206,9 @@ exports[`DataSource OpenSearch should generate Resource with endpoint 1`] = `
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"es",
"us-east-1",
{
Expand Down Expand Up @@ -1432,7 +1450,9 @@ exports[`DataSource Relational Databases should generate Resource with default r
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"rds",
{
"Ref": "AWS::Region",
Expand Down Expand Up @@ -1497,7 +1517,9 @@ exports[`DataSource Relational Databases should generate Resource with default r
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"rds",
{
"Ref": "AWS::Region",
Expand All @@ -1519,7 +1541,9 @@ exports[`DataSource Relational Databases should generate Resource with default r
":",
[
"arn",
"aws",
{
"Ref": "AWS::Partition",
},
"rds",
{
"Ref": "AWS::Region",
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/dataSources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ const plugin = given.plugin();

describe('DataSource', () => {
describe('DynamoDB', () => {
// Regression guard for #352: generated resource ARNs must derive the
// partition from CloudFormation (`AWS::Partition`) so they are valid in
// the aws-cn (China) and aws-us-gov (GovCloud) partitions, not hardcoded
// to "aws".
it('should derive the resource ARN partition from AWS::Partition', () => {
const api = new Api(given.appSyncConfig(), plugin);
const dataSource = new DataSource(api, {
type: 'AMAZON_DYNAMODB',
name: 'dynamo',
config: {
tableName: 'data',
},
});
const role = JSON.stringify(dataSource.compileDataSourceIamRole());
expect(role).toContain('"Ref":"AWS::Partition"');
expect(role).not.toContain('"arn","aws"');
});

it('should generate Resource with default role', () => {
const api = new Api(given.appSyncConfig(), plugin);
const dataSource = new DataSource(api, {
Expand Down
8 changes: 4 additions & 4 deletions src/resources/DataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class DataSource {
':',
[
'arn',
'aws',
{ Ref: 'AWS::Partition' },
'rds',
config.config.region || { Ref: 'AWS::Region' },
{ Ref: 'AWS::AccountId' },
Expand Down Expand Up @@ -277,7 +277,7 @@ export class DataSource {
':',
[
'arn',
'aws',
{ Ref: 'AWS::Partition' },
'dynamodb',
this.config.config.region || { Ref: 'AWS::Region' },
{ Ref: 'AWS::AccountId' },
Expand Down Expand Up @@ -324,7 +324,7 @@ export class DataSource {
':',
[
'arn',
'aws',
{ Ref: 'AWS::Partition' },
'rds',
this.config.config.region || { Ref: 'AWS::Region' },
{ Ref: 'AWS::AccountId' },
Expand Down Expand Up @@ -380,7 +380,7 @@ export class DataSource {
':',
[
'arn',
'aws',
{ Ref: 'AWS::Partition' },
'es',
result[2],
{ Ref: 'AWS::AccountId' },
Expand Down
Loading