0

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Jimmy Chen
  • 207
  • 5
  • 12

2 Answers2

0

You set it using DatabaseClusterAttributes. Specifically using:

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

Marcin
  • 215,873
  • 14
  • 235
  • 294
  • I actually tried this, but got some odd errors where it said my security group needed to be an Array, but the docs say Isecuritygroup go figure... – Jimmy Chen Feb 17 '21 at 16:18
  • @JimmyChen You would have to show actual code that you used. – Marcin Feb 17 '21 at 22:07
0

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]
                            )
Deepak
  • 85
  • 2
  • 11