我有一個子網串列,我想將這些子網迭代到我的公共和私有路由表中。這是我的公共 RT 函式的示例:
// 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]
我相信迭代會干擾id我的函式中的 。將不勝感激任何幫助解決這個問題。
uj5u.com熱心網友回復:
你的懷疑是正確的。您只需要為每個路由表關聯構造一個唯一的 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
});
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/360527.html
