question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[lambda-event-sources] Cross stack reference with dynamodb stream

See original GitHub issue

When 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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
obiwabrakenobicommented, Sep 23, 2020

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)

const stack1 = new Stack(app, 'stack1', {
    env: {
        account: process.env.CDK_DEFAULT_ACCOUNT,
        region: process.env.CDK_DEFAULT_REGION,
    },
});

const stack2 = new Stack(
    app,
    'stack2'
);

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

0reactions
obiwabrakenobicommented, Sep 23, 2020

let me check that. If have literally the same setup

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found