【发布时间】:2021-09-21 20:07:02
【问题描述】:
我有一个多堆栈应用程序,我想在一个堆栈中部署 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
});
有了这个添加入口规则,一切都很好,因为 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,
});
如何删除入口规则并允许从该 ecsSG 到 RDS 的入站连接,因为它稍后会部署?如果我尝试从部署堆栈调用以下命令,则会收到循环依赖错误:
props.rdsSG.connections.allowFrom(ecsSG, ec2.Port.allTcp(), 'Aurora RDS');
感谢您的帮助!
【问题讨论】:
标签: amazon-rds aws-cdk aws-security-group