[aws-dynamodb] tableStreamArn is undefined
See original GitHub issueWe’re creating a DynamoDB table with a stream. We’re trying to create a lambda.EventSourceMapping
, passing in table.tableStreamArn
as the eventSourceArn
prop like so:
new lambda.EventSourceMapping(this, props.serviceName + 'eventSourceMapping', {
eventSourceArn: ddbTable.tableStreamArn,
target: ddbStreamProcessor,
startingPosition: lambda.StartingPosition.TRIM_HORIZON
});
When we try to build (transpiling from TypeScript to JavaScript), we get the following error:
npm run build
> cdk@0.1.0 build /home/ec2-user/scm/app/cdk
> tsc
lib/cdk-stack.ts:63:7 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
63 eventSourceArn: ddbTable.tableStreamArn,
~~~~~~~~~~~~~~
node_modules/@aws-cdk/aws-lambda/lib/event-source-mapping.d.ts:9:14
9 readonly eventSourceArn: string;
~~~~~~~~~~~~~~
The expected type comes from property 'eventSourceArn' which is declared here on type 'EventSourceMappingProps'
Found 1 error.
Environment
- CDK CLI Version:
1.56.0 (build c1c174d)
- Module Version:
1.56.0
- Node.js Version:
v10.16.0
- OS: all
- Language (Version): TypeScript 3.7.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
AWS CDK getting DynamoDB Stream ARN returns null
DynamoEventSource on the imported table), you must use the Table.fromTableAttributes method and the tableStreamArn property must be populated.
Read more >class Table (construct) · AWS CDK
CUSTOMER_MANAGED and this property is undefined, a new KMS key will be created and associated with this table.) External KMS key to use...
Read more >Aws Cdk Getting Dynamodb Stream Arn Returns Null - ADocLib
The tableStreamArn property is optional meaning it can be undefined because no stream will exist if the table was created without a stream....
Read more >@aws-cdk/aws-dynamodb | Yarn - Package Manager
Amazon DynamoDB Construct Library. cfn-resources: Stable. cdk-constructs: Stable. Here is a minimal deployable DynamoDB table definition:
Read more >awsdynamodb - Go Packages
Returns: The construct as a stack element or undefined if it is not a stack element ... such as `arn:aws:dynamodb:us-east-1:123456789012:table/testddbstack- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The
tableStreamArn
property is optional (meaning it can beundefined
) because no stream will exist if the table was created without astream
property. This is perfectly normal and expected.There are two things you can do to fix your code:
stream
property, use a!
to inform the typescript compiler that you know the value will not beundefined
:ITable
from outside of your control and cannot guarantee it was created with astream
property, add guard for the case where no stream was created:Hello!
When I say “directly”, I mean the same way my blog post that you mentioned is passing an S3 Bucket from the
ProducingStack
to theConsumingStack
.