AWS CloudFormation Template -Aurora Serverless PostgreSQL Cluster
Introduction :-
Cloud computing has revolutionized the way organizations manage their databases. #AmazonWebServices (AWS) offers a powerful database service known as Amazon Aurora, which combines the performance and availability of high-end commercial databases with the simplicity and cost-effectiveness of open-source databases. Aurora Serverless is a key feature that automatically adjusts capacity to match actual consumption, making it a highly efficient and cost-effective solution for many applications.
This CloudFormation template is designed to streamline the deployment of an #Aurora Serverless PostgreSQL cluster on AWS. With the flexibility to customize various parameters, it provides an easy and consistent way to set up the database #infrastructure for a wide range of applications. In this template, we will walk through the essential components and configurations required to create an Aurora Serverless PostgreSQL cluster.
AWSTemplateFormatVersion: Specifies the version of the CloudFormation template. In this case, it’s set to ‘2010–09–09’, which is a common and stable version.
Description: Provides a brief description of the stack and its purpose.
Parameters: Defines input parameters that can be provided when creating a stack. These parameters allow you to customize the stack based on your requirements. Some of the parameters include
EnvironmentName
,NetworkStackName
,DBMaster
, and more.Resources: Describes the AWS resources to be created as part of the stack. The primary resource defined in this template is an Aurora Serverless PostgreSQL cluster (
DBCluster
). It also defines a security group for the cluster, a DB subnet group, and a security group for a Bastion host (which is currently commented out).Outputs: Specifies the values that should be exported from the stack for later use. For example, it exports the stack name, cluster name, connection endpoint (DNS name), security group IDs, database name, and database port.
It’s important to note that this CloudFormation template is a starting point and can be customized to meet the specific needs of your application and environment. Make sure to fill in the parameter values and customize the resources as required for your use case.
Deployment Steps
Follow these steps to upload and create the CloudFormation stack using the AWS Management Console:
- Sign in to the AWS Management Console: Log in to your AWS account if you haven’t already.
2. Navigate to CloudFormation: Go to the AWS CloudFormation service from the AWS Management Console.
3. Click the “Create stack” button.
4. Upload the CloudFormation template file (YAML).
Yaml:
AWSTemplateFormatVersion: '2010-09-09'
Description: This stack deploys an Aurora Serverless PostgreSQL cluster.
Parameters:
EnvironmentName:
Description: Environment name for the application (dev/staging/uat/production)
Type: String
Default: dev
NetworkStackName:
Type: String
MinLength: 1
MaxLength: 255
AllowedPattern: '^[a-zA-Z][-a-zA-Z0-9]*$'
Default: 30
DBMaster:
Type: String
Default: Mahira
DatabaseName:
Type: String
Default: temporal
DBBackupRetentionPeriod:
Description: 'The number of days to keep snapshots of the cluster.'
Type: Number
MinValue: 1
MaxValue: 35
Default: 30
EnableDataApi:
Description: 'Enable the Data API.'
Type: String
AllowedValues: ['true', 'false']
Default: 'true'
AutoPause:
Description: 'Enable automatic pause for the cluster.'
Type: String
AllowedValues: ['true', 'false']
Default: 'true'
MaxCapacity:
Description: 'The maximum capacity units for the cluster.'
Type: String
AllowedValues: [2, 4, 8, 16, 32, 64, 192, 384]
Default: 4
MinCapacity:
Description: 'The minimum capacity units for the cluster.'
Type: String
AllowedValues: [2, 4, 8, 16, 32, 64, 192, 384]
Default: 2
SecondsUntilAutoPause:
Description: 'The time, in seconds, before the cluster is paused.'
Type: Number
MinValue: 1
MaxValue: 86400
Default: 300
EngineVersion:
Description: 'Aurora Serverless PostgreSQL version.'
Type: String
Default: '13.9'
AllowedValues: ['10.18', '10.21', '11.13', '11.16','13.9']
Resources:
DBCluster:
Type: AWS::RDS::DBCluster
Properties:
DBClusterIdentifier: !Sub ${EnvironmentName}-AuroraCluster
MasterUsername: !Sub '{{resolve:secretsmanager:${DBMaster}:SecretString:username}}'
MasterUserPassword: !Sub '{{resolve:secretsmanager:${DBMaster}:SecretString:password}}'
DatabaseName: !Ref DatabaseName
Engine: aurora-postgresql
EngineMode: serverless
EngineVersion: !Ref EngineVersion
EnableHttpEndpoint: !Ref EnableDataApi
ScalingConfiguration:
AutoPause: !Ref AutoPause
MaxCapacity: !Ref MaxCapacity
MinCapacity: !Ref MinCapacity
SecondsUntilAutoPause: !Ref SecondsUntilAutoPause
BackupRetentionPeriod: !Ref DBBackupRetentionPeriod
StorageEncrypted: true
Outputs:
StackName:
Description: 'Stack name.'
Value: !Sub '${AWS::StackName}'
ClusterName:
Description: 'The name of the cluster.'
Value: !Ref DBCluster
DNSName:
Description: 'The connection endpoint for the DB cluster.'
Value: !GetAtt 'DBCluster.Endpoint.Address'
DBName:
Description: 'The name of the database.'
Value: !Ref DatabaseName
DBPort:
Description: 'The port of the database.'
Value: 5432
5. Specify Stack Details:
Enter a Stack name for your deployment.
Provide parameter values as needed.
Review and acknowledge the capabilities .
You can set additional stack options or tags if necessary.
6. Review and Create:
Review the stack details and configuration.
Click “Create stack” to initiate the deployment.
7. Monitor Stack Creation:
The CloudFormation stack creation process will begin.
Monitor the stack events in the AWS Management Console.
Conclusion:
In conclusion, this CloudFormation template simplifies the process of provisioning an #Aurora Serverless PostgreSQL cluster on AWS, helping you harness the power of this fully managed database service. By defining crucial parameters such as the environment name, database configurations, and scaling options, you can tailor the cluster to meet the specific needs of your application. Once deployed, the template also offers outputs that provide important information, such as the connection endpoint, cluster name, and more, making it easier to manage and interact with the database.
As you embark on your journey to build and scale your applications, this template serves as a fundamental building block, ensuring that your database infrastructure is not only efficient but also cost-effective. By leveraging the capabilities of Amazon Aurora Serverless, you can focus on developing your application while AWS takes care of the heavy lifting when it comes to database management.
Subscribe to my newsletter
Read articles from Mahira Technology Private Limited directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Mahira Technology Private Limited
Mahira Technology Private Limited
A leading tech consulting firm specializing in innovative solutions. Experts in cloud, DevOps, automation, data analytics & more. Trusted technology partner.