Skip to content
Draft
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
4 changes: 2 additions & 2 deletions packages/aws-cdk-lib/aws-backup/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/aws-cdk-lib/aws-dynamodb/lib/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/aws-cdk-lib/aws-dynamodb/lib/table-v2-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`],
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`],
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`],
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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`],
Expand All @@ -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),
Expand Down
Loading