Coh*_*ent 8 amazon-rds aws-security-group aws-cdk
我有一个多堆栈应用程序,我想在一个堆栈中部署 RDS,然后在后面的堆栈中部署一个连接到 RDS 的 Fargate 集群。
以下是 rds 的定义方式:
this.rdsSG = new ec2.SecurityGroup(this, `ecsSG`, {
vpc: props.vpc,
allowAllOutbound: true,
});
this.rdsSG.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(5432), 'Ingress 5432');
this.aurora = new rds.ServerlessCluster(this, `rds`, {
engine: rds.DatabaseClusterEngine.AURORA_POSTGRESQL,
parameterGroup: rds.ParameterGroup.fromParameterGroupName(this, 'ParameterGroup', 'default.aurora-postgresql10'),
vpc: props.vpc,
securityGroups: [this.rdsSG],
// more properties below
});
Run Code Online (Sandbox Code Playgroud)
有了这个添加入口规则,一切都很好,因为 RDS 和 Fargate 都在同一个 VPC 中,所以我可以很好地进行通信。我担心即使它在自己的 VPC 中,也要开放世界。
const ecsSG = new ec2.SecurityGroup(this, `ecsSG`, {
vpc: props.vpc,
allowAllOutbound: true,
});
const service = new ecs.FargateService(this, `service`, {
cluster,
desiredCount: 1,
taskDefinition,
securityGroups: [ecsSG],
assignPublicIp: true,
});
Run Code Online (Sandbox Code Playgroud)
由于稍后部署了 ecsSG,如何删除入口规则并允许从该 ecsSG 到 RDS 的入站连接?如果我尝试从部署堆栈调用以下命令,则会收到循环依赖错误:
props.rdsSG.connections.allowFrom(ecsSG, ec2.Port.allTcp(), 'Aurora RDS');
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助!
Coh*_*ent 17
事实证明这比我想象的要容易 - 您只需翻转连接即可,这样您就可以使用 来建立与allowTords 实例的连接,而不是尝试修改 rds 以接受 ecs 的安全组。
ecsSG.connections.allowTo(props.rds, ec2.Port.tcp(5432), 'RDS Instance');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5747 次 |
| 最近记录: |