我试图使用SecurityGroup.fromSecurityGroupId方法在CDK中导入一个现有的安全组,但是它失败了,出现了以下错误:
安全组Id: sg-12345未找到!(服务: AmazonEC2;状态代码: 400;错误代码: InvalidGroup.NotFound;请求ID: 8e2cd924-075d-4c64-b5ba-2e1d9c72fe95;代理: null)
下面是我的CDK代码:
const sg = SecurityGroup.fromSecurityGroupId(this, 'sgFromLookUp', 'sg-084c533df9d662439');
我再次检查了安全组id是否正确,我还尝试了其他2种安全组查找方法:
SecurityGroup.fromLookupById() and SecurityGroup.fromLookupByName()
他们都犯了同样的错误,知道为什么吗?
发布于 2022-08-06 00:00:39
结果显示,安全组是在引用它的InterfaceVpcEndpoint之后查找的,因为我没有向InterfaceVpcEndpoint中添加安全组的依赖项。在引用安全组之前,我设法查找了它,它现在起作用了。
起作用的代码:
// Create security group
const sgConstruct = new SgConstruct(this, 'SecurityGroup', { vpc: props.vpc });
// Create endpoints
new VpcEndpointsConstruct(this, 'VpcEndpoints', { sg: sgConstruct.sg, subnets: props.subnets, vpc: props.vpc });
发布于 2022-10-07 15:30:15
https://kuchbhilearning.blogspot.com/2022/10/get-security-group-from-id-aws-cdk.html
这能帮你开始工作。CDK确实提供了一些方法,我们可以根据这些方法从id中获取安全组。
https://stackoverflow.com/questions/73255901
复制相似问题