diff --git a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts index 4b90113ef60d1..dc94f5df8d0e0 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts @@ -564,6 +564,7 @@ export class TableV2 extends TableBaseV2 { this.hasSortKey = props.sortKey !== undefined; this.region = this.stack.region; this.tags = new TagManager(TagType.STANDARD, CfnGlobalTable.CFN_RESOURCE_TYPE_NAME); + this.resourcePolicy = props.resourcePolicy; this.encryption = props.encryption; this.encryptionKey = this.encryption?.tableKey; @@ -737,8 +738,8 @@ export class TableV2 extends TableBaseV2 { * @see https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/cx-api/FEATURE_FLAGS.md */ const resourcePolicy = FeatureFlags.of(this).isEnabled(cxapi.DYNAMODB_TABLEV2_RESOURCE_POLICY_PER_REPLICA) - ? (props.region === this.region ? this.tableOptions.resourcePolicy : props.resourcePolicy) || undefined - : props.resourcePolicy ?? this.tableOptions.resourcePolicy; + ? (props.region === this.region ? this.tableOptions.resourcePolicy : this.resourcePolicy) || undefined + : this.resourcePolicy ?? this.tableOptions.resourcePolicy; const propTags: Record = (props.tags ?? []).reduce((p, item) => ({ ...p, [item.key]: item.value }), {}, diff --git a/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts b/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts index 3ee695c146316..ad04f81c16ede 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/lib/table.ts @@ -1207,6 +1207,8 @@ export class Table extends TableBase { } this.validateProvisioning(props); + this.resourcePolicy = props.resourcePolicy; + const kinesisStreamSpecification = props.kinesisStream ? { streamArn: props.kinesisStream.streamArn, @@ -1241,9 +1243,7 @@ export class Table extends TableBase { kinesisStreamSpecification: kinesisStreamSpecification, deletionProtectionEnabled: props.deletionProtection, importSourceSpecification: this.renderImportSourceSpecification(props.importSource), - resourcePolicy: props.resourcePolicy - ? { policyDocument: props.resourcePolicy } - : undefined, + resourcePolicy: Lazy.any( { produce: () => this.resourcePolicy ? { policyDocument: this.resourcePolicy } : undefined }), warmThroughput: props.warmThroughput?? undefined, }); this.table.applyRemovalPolicy(props.removalPolicy); @@ -1662,8 +1662,20 @@ export class Table extends TableBase { const isCompleteHandlerPolicy = new SourceTableAttachedPolicy(this, provider.isCompleteHandler.role!); // Permissions in the source region - this.grant(onEventHandlerPolicy, 'dynamodb:*'); - this.grant(isCompleteHandlerPolicy, 'dynamodb:DescribeTable'); + onEventHandlerPolicy.grantPrincipal.addToPrincipalPolicy(new iam.PolicyStatement({ + actions: ['dynamodb:*'], + resources: [ + this.tableArn, + this.tableArn + '/index/*', + ], + })); + isCompleteHandlerPolicy.grantPrincipal.addToPrincipalPolicy(new iam.PolicyStatement({ + actions: ['dynamodb:DescribeTable'], + resources: [ + this.tableArn, + this.tableArn + '/index/*', + ], + })); let previousRegion: CustomResource | undefined; let previousRegionCondition: CfnCondition | undefined;