amazon-web-services - AWS CDK 从嵌套堆栈访问父堆栈中的资源
问题描述
我正在尝试将 Arn 传递给在父堆栈中创建的资源,以便在嵌套堆栈中使用。aws-cdk 文档指出:
当嵌套堆栈引用父堆栈中的资源时,CloudFormation 参数将自动添加到嵌套堆栈并从父堆栈分配
但是,尝试引用在父堆栈中创建的资源会导致Circular dependency between resources:
错误。
将资源的引用从父堆栈传递到嵌套堆栈的最佳方法是什么?
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()
}
解决方案
推荐阅读
- python-sphinx - 如何在 Sphinx + Latex Pdf 文件中包含图像文件
- .net - 允许属性进行身份验证
- c# - 未处理的异常 C#
- excel - 将一行转置为两列
- c++ - Arduino Wire requestFrom 冻结
- angular - 如何检查 ngIf 指令中 let i = index 的值
- react-native - 尝试在博览会上发布/获取 API 时出现问题
- ios - 在 Swift 中使用 segue 传递 Firestore 的 documentID
- maps - 如何在 bing 地图上显示 GeoJson 对象?
- php - 使用 PHP 和 .htaccess 创建类似 WordPress 的永久链接重写/重定向,这可能吗?