(aws-dynamodb): Feature gap regarding global DynamoDB Tables with per-region streams
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 74
Description
## :question: Global DynamoDB Tables with Multi Region Streams
### The Question
I am using the AWS CDK (Python) to create a DynamoDB global table.
```
globaltable = ddb.Table(
self, 'GlobalTable',
partition_key={'name': 'name', 'type': ddb.AttributeType.STRING},
replication_regions=['ap-southeast-2'],
stream=ddb.StreamViewType.NEW_AND_OLD_IMAGES,
billing_mode=ddb.BillingMode.PAY_PER_REQUEST,
)
```
This is a global table that is launched in a stack in eu-west-1. As you can see, the table is replicated across to ap-southeast-2.
I want to create another stack in ap-southeast-2 that references the DynamoDB replica table local to that region. In this stack, I need to use the DynamoDB streams for the table replica to trigger a Lambda function that also exists in that region.
To create the Lambda event source in the secondary region, I need to get the table from its attributes in the second stack
```
globaltable = ddb.Table.from_table_attributes(
self,
'GlobalTable',
table_name=global_table_primary.table_name,
table_stream_arn = '???'
)
```
From the [DynamoDB CDK API docs](https://docs.aws.amazon.com/cdk/api/latest/docs/aws-dynamodb-readme.html#importing-existing-tables
):
> If you intend to use the tableStreamArn (including indirectly, for example by creating an @aws-cdk/aws-lambda-event-source.DynamoEventSource on the imported table), you must use the Table.fromTableAttributes method and the tableStreamArn property must be populated.
So it appears that you must provide the ARN during the fromTableAttributes call to import the foreign resource. Failing to do so gives the following error:
> jsii.errors.JSIIError: DynamoDB Streams must be enabled on the table GlobalServerlessSecondaryStack/GlobalTable
Of course, I don't know this since it is not a predictable ARN.
I can easily get the ARN of the stream in the primary region using `table.tableStreamArn`, but there doesn't seem to be an option to get the stream ARN for the replica.
### Environment
- **CDK CLI Version:** 1.119.0 (build 2921d64)
- **Module Version:**
- **Node.js Version:** v10.24.1
- **OS:** all
- **Language:** Python
### Other information
Contributor guide
Research direction
Start with the aws-dynamodb Table.from_table_attributes entry point and its tableStreamArn handling, then trace how DynamoEventSource uses the imported table. Confirm how a replica's regional stream ARN can be obtained or represented for the secondary stack; done means the Lambda event source can use that replica stream without the current streams-enabled error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python, typescript
- Domain
- cloud, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100