简体   繁体   English

如何在 AWS CDK 中引用其他区域的资源?

[英]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.

相关问题 AWS CDK - 从其他堆栈访问资源 - AWS CDK- Access resource from other stack 如何克隆 CDK 资源? - How can I clone a CDK resource? 我怎样才能从其他地区获得ssm参数? - How can i get ssm parameter from other region? 我可以将 AWS elastic IP 从一个区域迁移到另一个区域吗? - Can I migrate AWS elastic IP from a region to another region? 我无法从 Linux 中删除 AWS-CDK - I Can't remove AWS-CDK from Linux AWS CDK:如何从单个堆栈部署多个堆栈 - AWS CDK: How can I deploy multiple stack from a single stack 如何在 CfnInclude 期间将(可选)参数直接从 CloudFormation 模板传递到 CDK 资源而不对参数列表进行硬编码? - How can I pass (optional) parameters directly from CloudFormation template to CDK resource during CfnInclude without hardcoding the parameter list? 如何在定义另一个资源时引用一个 Kube.netes 资源的值 - How can I reference value from one Kubernetes resource when defining another resource AWS CDK - 从资源的逻辑 ID 中排除阶段名称 - AWS CDK - Exclude stage name from logical ID of resource AWS CDK -- 我如何通过 AWS CDK 从我新创建的托管区域中检索我的 NS 记录 - AWS CDK -- How do I retrieve my NS Records from my newly created Hosted Zone by AWS CDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM