[英]How can I reference a resource from other region in AWS CDK?
I have some cases need to reference resources from other region or account when using CDK.我在使用CDK时有一些情况需要引用其他地区或账号的资源。 Some cases like:有些情况像:
ec2.SecurityGroup.fromSecurityGroupId(
ec2.Subnet.fromSubnetId(
...
I above static API, none of them provide a region
/ account
property.我上面static API,都没有提供region
/ account
属性。 How can I reference the construct from other regions via CDK?如何通过 CDK 引用其他地区的构造?
By utilizing the fromArn
functions where they are available.通过使用可用的fromArn
函数。
For example, you can reference a cross-region Log Group using LogGroup.fromLogGroupArn()
.例如,您可以使用LogGroup.fromLogGroupArn()
引用跨区域的日志组。 If a method like this is not available for the resouce you want to reference, then it's not possible to reference it in CDK.如果您要引用的资源无法使用这样的方法,则无法在 CDK 中引用它。
You could still achieve this by writing a Custom Resource, which is backed by a Lambda function executing arbitrary code and returning arbitrary values - you can use AWS SDK to do the lookup in the required region and return the result or perform operations on the resource.您仍然可以通过编写一个自定义资源来实现这一点,它由 Lambda function 执行任意代码并返回任意值支持 - 您可以使用 AWS SDK 在所需区域进行查找并返回结果或对资源执行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.