![](/img/trans.png)
[英]How to Connect AWS ECS (ApplicationLoadBalancedFargateService) Private IP to RDS Security Group Using CDK
[英]Allow ingress from one security group to another using AWS CDK
如何使用 AWS CDK 将两个安全组连接在一起?
这是允许 IPv4 流量通过端口 443 进入的示例
ec2SecurityGroup.addIngressRule(Peer.anyIpv4(), Port.tcp(443), 'Test rule', false)
这来自文档:
public addIngressRule(peer: IPeer, connection: Port, description?: string, remoteRule?: boolean): void
这是我能想到的最好的方法(其中 'elbSecurityGroup' 是另一个安全组):
const p = Peer.anyIpv4()
p.connections.allowFrom(elbSecurityGroup.connections, Port.tcp(443))
ec2SecurityGroup.addIngressRule(p, Port.tcp(443), 'Test rule', false)
但这真的没有任何意义。 必须有更好的方法来初始化 Peer。 打字稿说
类“Peer”的构造函数受保护并且只能在类声明中访问。
如果我尝试:
const p = new Peer()
这可以通过直接访问 SecurityGroups 或其他构造上的“连接”来完成
ec2SecurityGroup.connections.allowFrom(elbSecurityGroup, Port.tcp(443), 'Application Load Balancer')
或者直接从一个 EC2 实例对象到另一个 EC2 实例:
ec2Instance1.connections.allowFrom(ec2Instance2, Port.tcp(4321), 'Inbound')
ec2Instance2.connections.allowTo(ec2Instance1, Port.tcp(4321), 'Outbound')
这将创建/更改由附加到 EC2 实例的 CDK 创建的 SecurityGroup。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.