screamingtiger
screamingtiger

Reputation: 23

Cross Stack References Issues and Best Practices?

in referencing this documentation: https://github.com/aws/aws-cdk/blob/master/packages/@aws-cdk/core/README.md#removing-automatic-cross-stack-references I have 2 stacks in the same application.

ProducerStack: deploys a lambda ConsumerStack: takes the lambda reference passed into the props.

If I update the lambda in the producer the deploy fails due to the reference blocking it. If I am understanding correctly, I have to remove refs to the lambda in the consumer, deploy which will update the producer. Then add refs back and deploy the consumer.

So questions are: Are 2 deployments really needed in this case? If so, is using cross stack references a bad idea?

More Info: I have a single app that is one bounded context but I want to separate out the concerns. Writing to s3 buckets, sending data to a vendor, and setting up on SQS. SO I have these functionalities in separate stacks to practice good separation of concerns. But this requires cross stack refs and I am now considering just making 1 huge stack. I know I can break it up into modules and include them and thinking thats the way to go.

Upvotes: 1

Views: 3368

Answers (1)

fedonev
fedonev

Reputation: 25739

Is using cross stack references a bad idea?

Quite the opposite. Cross-stack references are a recommended CDK pattern. They are a good fit for your scenario.

Are 2 deployments really needed in this case?

This procedure is needed only if the CDK (or, more precisely, CloudFormation) needs to destroy (or replace = destroy + create) a resource used in another stack. Fortunately, nearly all Lambda updates do not require replacement. As such, deployment deadlocks (which are for our own protection) are rare. Name changes require a resource replacement - perhaps you changed the Lambda's logical id?

Upvotes: 1

Related Questions