I want to create a database with cdk that is publicly accessible (dev db). I know how to do it through the Web UI. I need to set the Public accessibility to true and allow my IP as Inbound on the Security Group.
const vpc = new ec2.Vpc(this, 'Vpc')
const postgres = new rds.DatabaseInstance(this, 'Postgres', {
engine: rds.DatabaseInstanceEngine.POSTGRES,
instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
masterUsername: 'postgres',
vpc,
})
this is my current status, it works fine, but no public access
const vpc = new ec2.Vpc(this, 'Vpc')
const postgres = new rds.DatabaseInstance(this, 'Postgres', {
engine: rds.DatabaseInstanceEngine.POSTGRES,
instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.MICRO),
masterUsername: 'postgres',
vpc,
vpcPlacement: { subnetType: ec2.SubnetType.PUBLIC }
})
postgres.connections.allowFromAnyIpv4(ec2.Port.tcp(5432))
vpcPlacement: { subnetType: ec2.SubnetType.PUBLIC } sets public access to true
postgres.connections.allowFromAnyIpv4(ec2.Port.tcp(5432)) allows inbound traffic from port 5432
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With