Unexpected cyclic reference error with lambda.addEventSource
See original GitHub issueI tried to split into two stacks. One creates S3 Bucket, and the other creates a lambda and add event source to that from s3 of other stack.
When execute cdk deploy
, error messages put on console.
Reproduction Steps
source Code
import cdk = require( '@aws-cdk/core' )
import * as S3 from '@aws-cdk/aws-s3';
import * as Lambda from '@aws-cdk/aws-lambda';
import { S3EventSource } from '@aws-cdk/aws-lambda-event-sources';
const app = new cdk.App();
export class Stack1 extends cdk.Stack {
readonly bucket: S3.Bucket;
constructor( scope: cdk.Construct, name: string, props?: cdk.StackProps ) {
super( scope, name, props );
this.bucket = new S3.Bucket( this, 'tests3' );
}
}
interface Stack2Props extends cdk.StackProps {
bucket: S3.Bucket
}
export class Stack2 extends cdk.Stack {
constructor( scope: cdk.Construct, name: string, props: Stack2Props ) {
super( scope, name, props );
const lambda = new Lambda.Function(
this,
'testLambda',
{
functionName: 'test',
code: Lambda.Code.fromAsset( { ***source path***} ),
handler: 'index.handler',
runtime: Lambda.Runtime.NODEJS_8_10,
}
);
lambda.addEventSource(
new S3EventSource( props.bucket, {
events: [S3.EventType.OBJECT_CREATED],
} )
);
}
}
const stack1 = new Stack1( app, 'stack1' );
const stack2 = new Stack2( app, 'stack2', {
bucket: stack1.bucket
} );
app.synth();
Error Log
$ ENV=dev cdk deploy
'stack2' depends on 'stack1' (stack2 -> stack1/tests3/Resource.Arn). Adding this dependency (stack1 -> stack2/testLambda/Resource.Arn) would create a cyclic reference.
Environment
- CLI Version : 1.14.0
- Framework Version:1.14.0
- OS :Mac
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:10 (4 by maintainers)
Top Results From Across the Web
CDK - S3 notification causing cyclic reference error
The error message indicates, that you use a Lambda. Where is that Lamdba definition? What are you trying to do with SNS?
Read more >@aws-cdk/aws-lambda-event-sources - Package Manager
When a user calls the SNS Publish API on a topic that your Lambda function is subscribed to, Amazon SNS will call Lambda...
Read more >Resolving circular dependency in provisioning of Amazon S3 ...
In this article, I present a mechanism to resolve the circular dependency while preserving the desired outcome of auto-generated S3 bucket names ...
Read more >Resolving circular dependencies in CDK Constructs/CFN ...
Using some construct or resource that creates a circular relation ... CDK will complain that there is a circular reference among them.
Read more >awslabs/aws-cdk - Gitter
Arn). Adding this dependency (LampycalLambdaStack/lampycal_calendars/ApiPermission.ANY.. -> LampycalAPIStack/LamPyCal/Resource.Ref) would create a cyclic ...
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
I want to keep this issue open. Currently I keep both s3 and lambda resources in a single stack to avoid the cyclic reference.
I’d like to separate global from regional resources. Also I’d like to keep my resources in a single app.
So even if I am importing the bucket (not the name or ARN) into the stack, the below seems to do the trick.
Stack 1 - Creates
mybucket
. Stack 2 - Imports it as a shared resourcesprops.mybucket
In Stack 2 instead of using
props.mybucket
directly in theaddEventSource
, I do this-