Closed dkaksl closed 3 years ago
Using Table.fromTableName
is the same as using Table.fromTableAttributes
, specifying only the table name... In order to support existing streams when importing a table, you have to use the Table.fromTableAttributes
API ans specify the table stream ARN.
Are the two stacks part of the same CDK App? If so - you could perhaps pass the table instance across instead of actually manually importing it... This way you would have the stream configuration coming with the table instance naturally...
If you cannot do this, I would suggest storing the table's stream ARN in an SSM Parameter, and retrieving it from there in the second stack.
Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.
@RomainMuller my workaround was to set the stream arn as an output
new cdk.CfnOutput(this, 'table-stream-arn-output', {
exportName: 'tableStreamArn',
value: tableStreamArn,
})
and grabbing it with Fn.importValue
const tableStreamArn = Fn.importValue('tableStreamArn')
and using L1 construct to create the event source
new lambda.CfnEventSourceMapping(
this,
'dynamo-event-source',
{
eventSourceArn: tableStreamArn,
functionName: myFunction.functionArn,
startingPosition: 'TRIM_HORIZON',
},
)
But I guess if I have the stream ARN, I can use Table.fromTableAttributes
like you suggest and avoid using the L1 constructs.
@RomainMuller update: Yes, it worked fine when using Table.fromTableAttribues
. Got rid of the L1 construct.
But I'm not convinced. Seems like a flaw that I would have to know an ARN that comes from the dynamodb resource I am referencing (and importing). I'd maybe not go as far as calling that a bug, but it's counter-intuitive and IMHO it would be better if the resource just had that information (which, if I look in the management console, it does).
Creating a DynamoDB table in one stack, then using it as a lambda's DynamoEventSource in another stack gives the error "DynamoDB Streams must be enabled on the table", even though DynamoDB streams are enabled on the table in the original stack.
Reproduction Steps
In one stack:
In another stack:
What did you expect to happen?
To be able to diff and deploy the stack with the DynamoEventSource.
What actually happened?
Environment
This is :bug: Bug Report