Skip to content

(aws-dynamodb): replica-provider has a hardcoded aws partition in the IAM policy #25407

@jacklin213

Description

@jacklin213

Describe the bug

In f35b70b, a new policy statement was introduced to add permissions 'dynamodb:DeleteTable', 'dynamodb:DeleteTableReplica' to allow for custom resource to delete the replication Table. However the resource arn was hardcoded to the aws partition meaning that this code will not work in other partitions such as aws-cn. (See Line 100 below)

// Required for replica table deletion
let resources: string[] = [];
props.regions.forEach((region) => {
resources.push(`arn:aws:dynamodb:${region}:${this.account}:table/${props.tableName}`);
});
this.onEventHandler.addToRolePolicy(
new iam.PolicyStatement({
actions: ['dynamodb:DeleteTable', 'dynamodb:DeleteTableReplica'],
resources: resources,
}),
);

The error we see when the CDK stack is deployed to CN:

Partition "aws" is not valid for resource "arn:aws:dynamodb:cn-northwest-1:1234567890:table/MyTable". (Service: AmazonIdentityManagement; Status Code: 400; Error Code: MalformedPolicyDocument; Request ID: -snip-; Proxy: null)

Expected Behavior

The policy should be create inferring the partition when specifying the tableArn for the resource of the new policy statement.

Current Behavior

The policy creation fails in CN partition as the partition is hardcoded to standard partition.

Reproduction Steps

  1. Create a CDK repo that only has 1 Table resource.
  2. As part of the Table resource provide replicationRegions and have either cn-north-1 or cn-northwest-1.
  3. Synth the repo and attempt to deploy the stack to China

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.73.0

Framework Version

No response

Node.js Version

18.0.0

OS

Linux

Language

Typescript

Language Version

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-dynamodbRelated to Amazon DynamoDBbugThis issue is a bug.effort/smallSmall work item – less than a day of effortgood first issueRelated to contributions. See CONTRIBUTING.mdneeds-reviewp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions