I am trying to pass an Arn for a resource created in a parent stack to be used in a nested stack. The aws-cdk documentation states that:
When a resource from a parent stack is referenced by a nested stack, a CloudFormation parameter will automatically be added to the nested stack and assigned from the parent
However, trying to reference a resource created in a parent stack results in Circular dependency between resources: error.
What would be the best way to pass a reference for a resource from a parent stack to a nested one?
object TestTemplateApp extends App {
class MainStack(parent: Construct)
extends Stack(parent, "Main") {
//some other resources
val firstNestedStack = new FirstNestedStack(this)
}
class FirstNestedStack(parent: Construct)
extends NestedStack(parent, "Batch") {
//some other resources
val s3Bucket = Bucket.Builder
.create(this, "id")
.bucketName(("example"))
.build()
val BucketArn = s3Bucket.getBucketArn
val secondNested = new SecondNestedStack(this, BucketArn)
}
class SecondNestedStack(parent: Construct, bucketArn: String) extends NestedStack(parent, "second") {
//some other resources
val secondS3Bucket = Bucket.Builder
.create(this, s" S3WorkspaceBucket")
.bucketName(s"$bucketArn example") // assume we want to use the ARN of the s3 bucket from the parent in the bucket in the nested stack
.build()
}
val cdkApp = CDKApp.Builder.create().outdir("/tmp/test_template").build()
val mainStack = new MainStack(cdkApp)
cdkApp.synth()
}