简体   繁体   中英

Creating AWS RDS Postgres with CDK and defining Security Groups

I'm using python CDK to create a Postgres DB and all is fine.

I'm using

newdatabase = rds.DatabaseCluster(

)

Unfortunately, I couldn't find a way to attach an existing security group to this cluster. Anyone know how I could do it with Python?

You set it using DatabaseClusterAttributes . Specifically using:

security_groups - The security groups of the database cluster. Default: - no security groups

Did you try calling the existing security group as shown below and then using the variable in the array. It worked for me.

security_group = _ec2.SecurityGroup.from_security_group_id(self, "imported-sg",security_group_id="sg-xxxxxxxx")
mydb= _rds.DatabaseInstance(self,
                              "mysql-rds",
                              security_groups=[security_group]
                            )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM