AWS Cloudformation
Installing PostgreSQL using Infrastructure As Code
Time requirement: 30 mins
Prerequisites
- Available AWS Account
- fork or copy of Cloudformation template
simpleVPC creates pub/priv VPC + subnet
rds-postgresql.yaml creates RDS database - AWS CLI installed locally
verify default configuration region and key:
$ aws configure
Deploy Postgres-17 install and expose ports
This demo will install a postgresql database in my local region:
$ export AWS_REGION="us-west-1"
Log into AWS Console to follow along, if-needed:
AWS RDS Console URL
AWS Cloudformation Console URL
AWS Secrets Manager for credentials
Use Cloudformation template to create VPC, Subnet and PostgreSQL database:
$ aws cloudformation create-stack --stack-name cfn-rds-demo --template-body file://rds-postgresql.yaml
- follow along in AWS Console for Cloudformation Template.
You’ll see a new template called “cfn-rds-demo”
Errors may be related to new releases (pg16, pg17, etc)
update the yaml file as-needed - when the template shows “CREATE_COMPLETE” check RDS console
new database called cfdemo created - retrieve username/password from Secrets Manager
Connection and further maintenance
RDS Console provided endpoint: cfdemo.cvf3het7fmyg.us-west-1.rds.amazonaws.com
psql -h cfdemo.cvf3het7fmyg.us-west-1.rds.amazonaws.com -U postgres -d demoDB
*Retrived secret value password: “<SD3d(4F>(p[”
Additional Customization
Under Parameter groups, the default:postgres17 file can be updated to meet DevOps needs
It’s always recommended to have a parameter group per database for compatibility/customization.
Cleanup resources
Delete stack via AWS Console or:
aws cloudformation delete-stack --stack-name cfn-rds-demo
Again, verify snapshots/backups deleted to avoid incurring charges