![](/img/trans.png)
[英]How to import existing private subnets in a VPC in AWS CDK using TypeScript?
[英]How to iterate over multiple subnets in Route Table Associations with AWS CDK?
我有一個子網列表,我想迭代到我的公共和私有路由表中。 這是我的公共 RT 的 function 示例:
// This will grab the public RT and associate all public subnets to the RT.
props.pubSubnetId.forEach((public_subnets) => {
const publicRTAssoc = new ec2.CfnSubnetRouteTableAssociation(this, "publicRTAssoc", {
routeTableId: props.pubRouteTableId,
subnetId: public_subnets
});
});
我發現我的代碼沒有任何問題,但是當我運行cdk synth
時,出現以下錯誤:
Error: There is already a Construct with name 'publicRTAssoc' in CloudformationArchStack [CloudformationArchStack]
我相信迭代會干擾我的 function 中的id
。 將不勝感激任何幫助解決這個問題。
你的懷疑是正確的。 您只需要為每個路由表關聯構造一個唯一的 id:
// This will grab the public RT and associate all public subnets to the RT.
props.pubSubnetId.forEach((public_subnets) => {
const publicRTAssoc = new ec2.CfnSubnetRouteTableAssociation(this, `publicRTAssoc_${public_subnets}`, {
routeTableId: props.pubRouteTableId,
subnetId: public_subnets
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.