Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"Metadata": { "Test": "test" },
"Resources": {
"TableCD117FA1": {
"Type": "AWS::DynamoDB::Table",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ readScaling.scaleOnSchedule('ScaleDownAtNight', {
/// !hide

app.synth();
// linter update
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExpectedResult, IntegTest, Match } from '@aws-cdk/integ-tests-alpha';
// Trigger integration test update for PR linter
import * as path from 'path';
import type { StackProps } from 'aws-cdk-lib';
import { App, RemovalPolicy, Stack } from 'aws-cdk-lib';
Expand Down
4 changes: 3 additions & 1 deletion packages/aws-cdk-lib/aws-dynamodb/lib/table-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1604,10 +1604,12 @@ export class TableV2MultiAccountReplica extends TableBaseV2 {
let sourceRegion = sourceStack.region;

// For imported tables, extract account/region from ARN instead of stack
if (!Token.isUnresolved(props.replicaSourceTable!.tableArn)) {
try {
const arnParts = this.stack.splitArn(props.replicaSourceTable!.tableArn, ArnFormat.SLASH_RESOURCE_NAME);
if (arnParts.account) sourceAccount = arnParts.account;
if (arnParts.region) sourceRegion = arnParts.region;
} catch {
// Ignore splitArn failures on purely tokenized ARNs
}

// Validate different account (skip if token)
Expand Down
16 changes: 15 additions & 1 deletion packages/aws-cdk-lib/aws-dynamodb/test/table-v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ArnPrincipal, PolicyDocument, PolicyStatement } from '../../aws-iam';
import * as iam from '../../aws-iam';
import { Stream } from '../../aws-kinesis';
import { Key } from '../../aws-kms';
import { App, CfnDeletionPolicy, Fn, Lazy, RemovalPolicy, Stack, Tags } from '../../core';
import { App, CfnDeletionPolicy, Fn, Lazy, RemovalPolicy, Stack, Tags, Token } from '../../core';
import type {
GlobalSecondaryIndexPropsV2,
LocalSecondaryIndexProps,
Expand Down Expand Up @@ -4274,6 +4274,20 @@ test('TableV2MultiAccountReplica does not throw when account/region are tokens',
}).not.toThrow();
});

test('TableV2MultiAccountReplica handles partially tokenized ARNs successfully', () => {
const app = new App();
const replicaStack = new Stack(app, 'ReplicaStack', { env: { account: '111111111111', region: 'us-west-2' } });

const sourceTable = TableV2.fromTableArn(replicaStack, 'SourceTable',
`arn:aws:dynamodb:us-east-1:222222222222:table/${Token.asString('MyTable')}`);

expect(() => {
new TableV2MultiAccountReplica(replicaStack, 'ReplicaTable', {
replicaSourceTable: sourceTable,
});
}).not.toThrow();
});

test('can add GSI with compound partition keys', () => {
const stack = new Stack();
const table = new TableV2(stack, 'Table', {
Expand Down
Loading