diff --git a/packages/aws-cdk-lib/aws-backup/lib/resource.ts b/packages/aws-cdk-lib/aws-backup/lib/resource.ts index fcf6a8645ae7d..6fdc3c414fb36 100644 --- a/packages/aws-cdk-lib/aws-backup/lib/resource.ts +++ b/packages/aws-cdk-lib/aws-backup/lib/resource.ts @@ -65,8 +65,8 @@ export class BackupResource { /** * A DynamoDB table */ - public static fromDynamoDbTable(table: dynamodb.ITable) { - return BackupResource.fromArn(table.tableArn); + public static fromDynamoDbTable(table: dynamodb.ITableRef) { + return BackupResource.fromArn(table.tableRef.tableArn); } /** diff --git a/packages/aws-cdk-lib/aws-dynamodb/lib/shared.ts b/packages/aws-cdk-lib/aws-dynamodb/lib/shared.ts index d257e77620a43..4db88b984a77a 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/lib/shared.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/lib/shared.ts @@ -4,6 +4,7 @@ import * as cloudwatch from '../../aws-cloudwatch'; import * as iam from '../../aws-iam'; import * as kms from '../../aws-kms'; import { IResource, ValidationError } from '../../core'; +import { ITableRef } from '../../interfaces/generated/aws-dynamodb-interfaces.generated'; /** * Supported DynamoDB table operations. @@ -339,7 +340,7 @@ export interface LocalSecondaryIndexProps extends SecondaryIndexProps { /** * An interface that represents a DynamoDB Table - either created with the CDK, or an existing one. */ -export interface ITable extends IResource { +export interface ITable extends IResource, ITableRef { /** * Arn of the dynamodb table. * diff --git a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts index 6b1306a3d1ae9..73dc676e5ee23 100644 --- a/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts +++ b/packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts @@ -5,6 +5,7 @@ import { IMetric, MathExpression, Metric, MetricOptions, MetricProps } from '../ import { AddToResourcePolicyResult, Grant, IGrantable, IResourceWithPolicy, PolicyDocument, PolicyStatement } from '../../aws-iam'; import { IKey } from '../../aws-kms'; import { Resource, ValidationError } from '../../core'; +import { TableReference } from '../../interfaces/generated/aws-dynamodb-interfaces.generated'; /** * Represents an instance of a DynamoDB table. @@ -64,6 +65,16 @@ export abstract class TableBaseV2 extends Resource implements ITableV2, IResourc protected abstract get hasIndex(): boolean; + /** + * A reference to this table. + */ + public get tableRef(): TableReference { + return { + tableName: this.tableName, + tableArn: this.tableArn, + }; + } + /** * Adds an IAM policy statement associated with this table to an IAM principal's policy. * diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/delete-item.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/delete-item.ts index b7c8d5451689e..f8725bc42d7fb 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/delete-item.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/delete-item.ts @@ -10,7 +10,7 @@ interface DynamoDeleteItemOptions { /** * The name of the table containing the requested item. */ - readonly table: ddb.ITable; + readonly table: ddb.ITableRef; /** * Primary key of the item to retrieve. @@ -124,7 +124,7 @@ export class DynamoDeleteItem extends sfn.TaskStateBase { Stack.of(this).formatArn({ service: 'dynamodb', resource: 'table', - resourceName: props.table.tableName, + resourceName: props.table.tableRef.tableName, }), ], actions: [`dynamodb:${DynamoMethod.DELETE}Item`], @@ -141,7 +141,7 @@ export class DynamoDeleteItem extends sfn.TaskStateBase { Resource: getDynamoResourceArn(DynamoMethod.DELETE), ...this._renderParametersOrArguments({ Key: transformAttributeValueMap(this.props.key), - TableName: this.props.table.tableName, + TableName: this.props.table.tableRef.tableName, ConditionExpression: this.props.conditionExpression, ExpressionAttributeNames: this.props.expressionAttributeNames, ExpressionAttributeValues: transformAttributeValueMap(this.props.expressionAttributeValues), diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/get-item.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/get-item.ts index fcea61eeac402..19bd593cd69be 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/get-item.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/get-item.ts @@ -10,7 +10,7 @@ interface DynamoGetItemOptions { /** * The name of the table containing the requested item. */ - readonly table: ddb.ITable; + readonly table: ddb.ITableRef; /** * Primary key of the item to retrieve. @@ -106,7 +106,7 @@ export class DynamoGetItem extends sfn.TaskStateBase { Stack.of(this).formatArn({ service: 'dynamodb', resource: 'table', - resourceName: props.table.tableName, + resourceName: props.table.tableRef.tableName, }), ], actions: [`dynamodb:${DynamoMethod.GET}Item`], @@ -123,7 +123,7 @@ export class DynamoGetItem extends sfn.TaskStateBase { Resource: getDynamoResourceArn(DynamoMethod.GET), ...this._renderParametersOrArguments({ Key: transformAttributeValueMap(this.props.key), - TableName: this.props.table.tableName, + TableName: this.props.table.tableRef.tableName, ConsistentRead: this.props.consistentRead ?? false, ExpressionAttributeNames: this.props.expressionAttributeNames, ProjectionExpression: this.configureProjectionExpression(this.props.projectionExpression), diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/put-item.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/put-item.ts index 36c288667c96d..4709b26b5cad3 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/put-item.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/put-item.ts @@ -19,7 +19,7 @@ interface DynamoPutItemOptions { /** * The name of the table where the item should be written . */ - readonly table: ddb.ITable; + readonly table: ddb.ITableRef; /** * A condition that must be satisfied in order for a conditional PutItem operation to succeed. @@ -122,7 +122,7 @@ export class DynamoPutItem extends sfn.TaskStateBase { Stack.of(this).formatArn({ service: 'dynamodb', resource: 'table', - resourceName: props.table.tableName, + resourceName: props.table.tableRef.tableName, }), ], actions: [`dynamodb:${DynamoMethod.PUT}Item`], @@ -139,7 +139,7 @@ export class DynamoPutItem extends sfn.TaskStateBase { Resource: getDynamoResourceArn(DynamoMethod.PUT), ...this._renderParametersOrArguments({ Item: transformAttributeValueMap(this.props.item), - TableName: this.props.table.tableName, + TableName: this.props.table.tableRef.tableName, ConditionExpression: this.props.conditionExpression, ExpressionAttributeNames: this.props.expressionAttributeNames, ExpressionAttributeValues: transformAttributeValueMap(this.props.expressionAttributeValues), diff --git a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/update-item.ts b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/update-item.ts index 15990f95e7bae..43014f7ef5886 100644 --- a/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/update-item.ts +++ b/packages/aws-cdk-lib/aws-stepfunctions-tasks/lib/dynamodb/update-item.ts @@ -10,7 +10,7 @@ interface DynamoUpdateItemOptions { /** * The name of the table containing the requested item. */ - readonly table: ddb.ITable; + readonly table: ddb.ITableRef; /** * Primary key of the item to retrieve. @@ -134,7 +134,7 @@ export class DynamoUpdateItem extends sfn.TaskStateBase { Stack.of(this).formatArn({ service: 'dynamodb', resource: 'table', - resourceName: props.table.tableName, + resourceName: props.table.tableRef.tableName, }), ], actions: [`dynamodb:${DynamoMethod.UPDATE}Item`], @@ -151,7 +151,7 @@ export class DynamoUpdateItem extends sfn.TaskStateBase { Resource: getDynamoResourceArn(DynamoMethod.UPDATE), ...this._renderParametersOrArguments({ Key: transformAttributeValueMap(this.props.key), - TableName: this.props.table.tableName, + TableName: this.props.table.tableRef.tableName, ConditionExpression: this.props.conditionExpression, ExpressionAttributeNames: this.props.expressionAttributeNames, ExpressionAttributeValues: transformAttributeValueMap(this.props.expressionAttributeValues),