In the DynamoDB table stack, export the StreamArn
attribute of the table. Use that as the value of the EventSourceArn
to define an EventSourceMapping resource in your Lambda stack.
Resources:
Table:
Type: AWS::DynamoDB::Table
Properties:
StreamSpecification: NEW_AND_OLD_IMAGES
Outputs:
TableStreamArn:
Value: !GetAtt Table.StreamArn
Export:
Name: StreamArn
Resources:
Function:
Type: AWS::Lambda::Function
EventMapping:
Type: AWS::Lambda::EventSourceMapping
Properties:
EventSourceArn: !ImportValue StreamArn
FunctionName: !GetAtt Function.Arn
You could also do it the other way around - import the Lambda function ARN to the DynamoDB stack and define the event mapping there, but that feels less logical to me.