Tom Barber
Tom Barber

Reputation: 319

CDK Lambda and S3 artifact circular dependency

If you want to run a CDK app that has an S3 bucket and Lambda function that gets its code from the bucket, you need to maintain the bucket outside of CDK because otherwise it tries to deploy the function before the artifact can be put in the bucket.

Is there something obvious I missing?

Upvotes: 0

Views: 2615

Answers (2)

Stefan Freitag
Stefan Freitag

Reputation: 3608

Not sure if I got the question 100% right, but I think you can make use of the addDependency method. In the docs of CDK 1.55.0 I see

**
* Add an ordering dependency on another Construct.
* All constructs in the dependency's scope will be deployed before any
* construct in this construct's scope.

and if your lambda is named fn it should work like this

fn.node.addDependency(bucket)

Upvotes: 0

Tom Barber
Tom Barber

Reputation: 319

I see how it works, you can create 2 stacks and reference one S3 bucket from the other.

Sadly you can only use the IBucket object at the moment, but it'll do for me.

https://docs.aws.amazon.com/cdk/api/latest/docs/aws-s3-readme.html#sharing-buckets-between-stacks

Upvotes: 1

Related Questions