CDK Table DynamoDB, Stream configuration Python

Question:

In terraform, it works passing the attributes directly in CDK does not work. Does anyone know how to activate the stream in the DynamoDB table?

stream_enabled   = true
stream_view_type = "NEW_AND_OLD_IMAGES"
Asked By: Junior Osho

||

Answers:

I assume you are asking how to do so in CDK, with Terraform as your background:

from aws_cdk import aws_dynamodb as dynamodb

...

my_dynamo_table = dynamodb.Table(
    self, "LogicalIDForThisTable",
    ...
    stream=dynamodb.StreamViewType.NEW_AND_OLD_IMAGES
)

In order to use said stream, you need to create an DynamoEventSource object to pass to whatever resource will be consuming the stream:

https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_lambda_event_sources/DynamoEventSource.html

ie:

from aws_cdk import aws_lambda_event_sources as event_source

...

my_dynamo_event_stream = event_source.DynamoEventSource(
    my_dynamo_table,
    starting_position=aws_lambda.StartingPosition.TRIM_HORIZON,
    batch_size=25,
    retry_attempts=10
)

my_lambda.add_event_source(my_dynamo_event_stream)
Answered By: lynkfox
from aws_cdk import aws_dynamodb as dynamodb

my_dynamo_table = dynamodb.Table(
self, "LogicalIDForThisTable",

stream=dynamodb.StreamViewType.NEW_AND_OLD_IMAGES
)

My problen is :

stream_enabled = true

how to ?
Tanks.

Answered By: Junior Osho
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.