[lambda-event-sources] Cross stack reference with dynamodb stream
See original GitHub issueWhen I create a dynamodb table in one stack and share that reference to a second stack (same cdk app) and add in the second stack a DynamoEventSource it gives me an error
Stack "s2a-wd-datapoint-importer" cannot consume a cross reference from stack "s2a-wd-plotting". Cross stack references are only supported for stacks deployed to the same environment or between nested stacks and their parent stack
/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/refs.ts:55
throw new Error(
^
Error: Stack "s2a-wd-datapoint-importer" cannot consume a cross reference from stack "s2a-wd-plotting". Cross stack references are only supported for stacks deployed to the same environment or between nested stacks and their parent stack
at resolveValue (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/refs.ts:55:11)
at Object.resolveReferences (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/refs.ts:31:24)
at Object.prepareApp (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/prepare-app.ts:36:5)
at Object.synthesize (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/synthesis.ts:21:3)
at App.synth (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/stage.ts:175:23)
at process.<anonymous> (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/app.ts:112:45)
at Object.onceWrapper (events.js:422:26)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at process.emit (/home/emil/code/watchdog-plotting/node_modules/source-map-support/source-map-support.js:495:21)
Reproduction Steps
Stack1:
this.table= new dynamodb.Table(scope, 'table', {
partitionKey: {
name: 'id',
type: AttributeType.STRING,
},
billingMode: BillingMode.PAY_PER_REQUEST,
tableName: `tabletest`,
stream: dynamodb.StreamViewType.NEW_IMAGE,
});
Stack2:
lambda.addEventSource(
new DynamoEventSource(table, {
startingPosition: StartingPosition.LATEST,
batchSize: 5,
maxBatchingWindow: Duration.seconds(10),
retryAttempts: 1,
})
);
What did you expect to happen?
Sharing dynamodb table with streams should work within one cdk app
What actually happened?
I see the following error. When I remove the EventSource from the lambda everything works fine.
Stack "s2a-wd-datapoint-importer" cannot consume a cross reference from stack "s2a-wd-plotting". Cross stack references are only supported for stacks deployed to the same environment or between nested stacks and their parent stack
/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/refs.ts:55
throw new Error(
^
Error: Stack "s2a-wd-datapoint-importer" cannot consume a cross reference from stack "s2a-wd-plotting". Cross stack references are only supported for stacks deployed to the same environment or between nested stacks and their parent stack
at resolveValue (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/refs.ts:55:11)
at Object.resolveReferences (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/refs.ts:31:24)
at Object.prepareApp (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/prepare-app.ts:36:5)
at Object.synthesize (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/private/synthesis.ts:21:3)
at App.synth (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/stage.ts:175:23)
at process.<anonymous> (/home/emil/code/watchdog-plotting/node_modules/@aws-cdk/core/lib/app.ts:112:45)
at Object.onceWrapper (events.js:422:26)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at process.emit (/home/emil/code/watchdog-plotting/node_modules/source-map-support/source-map-support.js:495:21)
Environment
- CLI Version : 1.62.0 (build 8c2d7fc)
- Framework Version: 1.62.0
- Node.js Version: v12.18.3
- OS : Ubuntu Server 20.4
- Language (Version): TypeScript (3.9.7)
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
aws-cdk/aws-lambda-event-sources module
DynamoDB Streams. You can write Lambda functions to process change events from a DynamoDB Table. An event is emitted to a DynamoDB stream...
Read more >awslabs/aws-cdk - Gitter
I just want to add a dynamodb stream event source to a new lambda which is ... Cross stack references are only supported...
Read more >Migrate DynamoDB tables with zero downtime and no data loss
Add the new stack to bin/app.ts . It can be tricky to cross-reference values from different accounts. Since this is temporary anyway, we ......
Read more >@aws-cdk/aws-lambda-event-sources - Package Manager
You can use event source mappings to process items from a stream or queue in services that don't invoke Lambda functions directly.
Read more >Capture and forward correlation IDs through different Lambda ...
“Let me cross reference the logs from hundreds of services and find ... Unfortunately, with Kinesis and DynamoDB Streams, there's no way to ......
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 Free
Top 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
well not literally the same. As you mentioned the error message was correct but I did not see the problem in the first place.
My setup is like this. I added the env since I could not create a hosted zone
Cannot retrieve value from context provider hosted-zone since account/region are not specified at the stack level. Either configure "env" with explicit account and region when you define your stack, or use the environment variables "CDK_DEFAULT_ACCOUNT" and "CDK_DEFAULT_REGION" to inherit environment information from the CLI (not recommended for production stacks)
But then the environment seems not to be the same for both stacks which makes sense to me. So I added the
env
to stack2 and then it works.Thanks for your help! I think it is solved with that
let me check that. If have literally the same setup