我正在尝试使用 Python 通过 AWS CDK 将入口规则添加到安全组。根据此处的文档- 类 aws_cdk.aws_ec2 上有一个方法 add_ingress_rule()。
但是 - 当我尝试部署堆栈时,出现以下错误:
AttributeError: 'method' 对象没有属性 ' jsii__type ' 子进程退出,错误 1
下面的安全组代码片段-
sg_elb = ec2.SecurityGroup(
self,
id = "sg_elb",
vpc = vpc,
security_group_name = "sg_elb"
)
sg_elb.add_ingress_rule(
peer = ec2.Peer.any_ipv4,
connection = ec2.Port.tcp(443) # This line seems to be a problem.
)
Run Code Online (Sandbox Code Playgroud)
此处的官方文档中甚至还提供了相同的示例(在 TypeScript 中),因此我不确定自己做错了什么。
任何人都可以建议吗?
提前致谢 !
Ult*_*oxx 20
我使用 TS 获得了以下内容,希望对您有所帮助。
const mySG = new ec2.SecurityGroup(this, `${stack}-security-group`, {
vpc: vpc,
allowAllOutbound: true,
description: 'CDK Security Group'
});
mySG.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(22), 'SSH frm anywhere');
mySG.addIngressRule(ec2.Peer.ipv4('10.200.0.0/24'), ec2.Port.tcp(5439), 'Redshift Ingress1');
mySG.addIngressRule(ec2.Peer.ipv4('10.0.0.0/24'), ec2.Port.tcp(5439), 'Redshift Ingress2');
Run Code Online (Sandbox Code Playgroud)
顺便说一句,不建议使用明确的安全组名称:https : //docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.SecurityGroup.html
| 归档时间: |
|
| 查看次数: |
13601 次 |
| 最近记录: |