Skip to content

DynamoDB Table construct started creating invalid resource-based policy with service principals after v2.222.0 #37273

@fneqcf

Description

@fneqcf

Describe the bug

After upgrading aws-cdk-lib from v2.207.0 to v2.222.0+, a DynamoDB Table construct started creating resource-based policies that include service principals, this caused the deployment to fail

Versions tested

  • v2.220.0: No issues
  • v2.222.0: Build fails with dependency cycle error: "Template is undeployable, these resources have a dependency cycle"
  • v2.234.1: Dependency cycle resolved, but deployment fails with: Resource handler returned message: "One or more parameter values were invalid: Invalid policy document: Policy contains invalid service principal (Service: DynamoDb, Status Code: 400)"

Possibly related PRs

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

v2.220.0

Expected Behavior

DynamoDB Table construct should not generate resource-based policies with invalid service principals after upgrading CDK versions

Current Behavior

The synthesized template includes an invalid service principal in the DDB resource-based policy, it caused cfn deployment to fail.

Reproduction Steps

  1. Create a DynamoDB Table with grantReadWriteData using a ServicePrincipal:
const table = new Table(this, 'MyTable', {
   tableName: 'my-table',
   partitionKey: {
       name: 'pk',
       type: AttributeType.STRING,
   },
   sortKey: {
       name: 'sk',
       type: AttributeType.STRING,
   },
   encryption: TableEncryption.CUSTOMER_MANAGED,
   billingMode: BillingMode.PAY_PER_REQUEST,
   removalPolicy: RemovalPolicy.RETAIN,
   pointInTimeRecovery: true,
});

table.grantReadWriteData(new ServicePrincipal('myservice.amazonaws.com'));

  1. deploy with aws-cdk-lib v2.222.0 or later.

Possible Solution

No response

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.222.0

AWS CDK CLI version

2.1030.0

Node.js Version

v20.18.3

OS

macOS 15.7.4

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/mediumMedium work item – several days of effortp0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions