Aurora Serverless PostgreSQL Architecture

Overview

This architecture documentation describes the CloudFormation stack that deploys an Aurora Serverless PostgreSQL cluster on AWS. Aurora Serverless is an on-demand, auto-scaling configuration for Amazon Aurora that automatically starts up, shuts down, and scales capacity up or down based on your application's needs.

Key Benefits

  • Cost Optimization: Only pay for the database resources you consume, with automatic pause after inactivity
  • Auto-Scaling: Seamlessly scales compute capacity from 2 to 4 ACU (Aurora Capacity Units)
  • High Availability: Built on Aurora's proven architecture with automatic failover
  • Data API: HTTP endpoint for running SQL statements without managing connections
  • Fully Managed: No server provisioning or management required

Architecture Diagram

CloudFormation

CloudFormation Stack

Infrastructure as Code Deployment

Environment Configuration

Environment:dev
Database Name:temporal
Master User:Mahira

Scaling Configuration

Min Capacity:2 ACU
Max Capacity:4 ACU
Auto Pause:300s
AWS Secrets Manager

AWS Secrets Manager

Securely stores and retrieves database credentials (username and password) for the RDS cluster. Referenced dynamically during stack deployment.

Key Parameters:

Secret NameMahira
Fieldsusername, password
Aurora Serverless PostgreSQL Cluster

Aurora Serverless PostgreSQL Cluster

Fully managed, auto-scaling PostgreSQL-compatible database that automatically adjusts capacity based on application needs. Supports Data API for HTTP-based queries.

Key Parameters:

Engineaurora-postgresql
Engine Version13.9
Modeserverless
Data APIEnabled
EncryptionEnabled (at rest)
Backup Retention30 days

Auto-Scaling

Automatically scales capacity from 2 to 4 ACU based on workload demands

Auto-Pause

Pauses after 5 minutes of inactivity to reduce costs

Security

Encrypted at rest with automatic 30-day backup retention

Stack Outputs

Connection Information

  • Endpoint: DBCluster.Endpoint.Address
  • Port: 5432
  • Database: temporal

Resource Names

  • Cluster ID: dev-AuroraCluster
  • Stack Name: Exported for reference

Components

1. AWS CloudFormation

The infrastructure is defined as code using CloudFormation templates, enabling:

  • Version-controlled infrastructure
  • Repeatable deployments across environments
  • Automated resource provisioning and updates
  • Consistent configuration management

2. AWS Secrets Manager

Securely manages database credentials with:

  • Encrypted storage of sensitive information
  • Dynamic reference resolution during stack deployment
  • Automatic rotation capabilities (optional)
  • Access control via IAM policies

The template references secrets using the syntax:

!Sub '{{resolve:secretsmanager:$\{DBMaster\}:SecretString:username\}}'

3. Aurora Serverless PostgreSQL Cluster

The core database component with the following characteristics:

Engine Configuration

  • Engine: aurora-postgresql
  • Engine Mode: serverless
  • Engine Version: PostgreSQL 13.9
  • Compatible with: PostgreSQL wire protocol

Scaling Configuration

  • Minimum Capacity: 2 ACU (Aurora Capacity Units)
  • Maximum Capacity: 4 ACU
  • Auto-Pause: Enabled (pauses after 300 seconds of inactivity)
  • Resume: Automatically resumes when accessed

Security Features

  • Storage Encryption: Enabled (at rest)
  • In-Transit Encryption: Enabled by default
  • Backup Retention: 30 days
  • Network Isolation: Deployed in VPC (when NetworkStackName is configured)

Data API

  • HTTP Endpoint: Enabled
  • Use Cases: Serverless applications, Lambda functions, containerized apps
  • Benefits: No persistent database connections required

Configuration

Parameters

The CloudFormation template accepts the following parameters:

ParameterTypeDefaultDescription
EnvironmentNameStringdevEnvironment identifier (dev/staging/uat/production)
NetworkStackNameString30Reference to VPC/network stack
DBMasterStringMahiraSecrets Manager secret name for credentials
DatabaseNameStringtemporalInitial database name to create
DBBackupRetentionPeriodNumber30Days to retain automated backups (1-35)
EnableDataApiStringtrueEnable HTTP Data API endpoint
AutoPauseStringtrueEnable automatic pause during inactivity
MaxCapacityNumber4Maximum ACU for scaling (2-384)
MinCapacityNumber2Minimum ACU for scaling (2-384)
SecondsUntilAutoPauseNumber300Idle time before auto-pause (1-86400)
EngineVersionString13.9PostgreSQL engine version

Outputs

The stack exports the following outputs for use by other stacks:

  • StackName: The CloudFormation stack name
  • ClusterName: The Aurora cluster identifier (dev-AuroraCluster)
  • DNSName: The cluster endpoint address for connections
  • DBName: The database name (temporal)
  • DBPort: The PostgreSQL port (5432)

Deployment

Prerequisites

  1. AWS Account with appropriate permissions
  2. Secrets Manager Secret created with database credentials:
    {
      "username": "your_master_username",
      "password": "your_secure_password"
    }
    
  3. VPC Configuration (if using NetworkStackName parameter)

Deployment Steps

Using AWS CLI

aws cloudformation create-stack \
  --stack-name aurora-serverless-dev \
  --template-body file://aurora-serverless-postgres.yaml \
  --parameters \
    ParameterKey=EnvironmentName,ParameterValue=dev \
    ParameterKey=DBMaster,ParameterValue=Mahira \
    ParameterKey=DatabaseName,ParameterValue=temporal \
  --capabilities CAPABILITY_IAM

Using AWS Console

  1. Navigate to CloudFormation in AWS Console
  2. Click Create StackWith new resources
  3. Upload the aurora-serverless-postgres.yaml template
  4. Configure parameters as needed
  5. Review and create the stack

Post-Deployment

After successful deployment:

  1. Retrieve Connection Details:

    aws cloudformation describe-stacks \
      --stack-name aurora-serverless-dev \
      --query 'Stacks[0].Outputs'
    
  2. Test Connection (when cluster is active):

    psql -h <DNSName> -p 5432 -U <username> -d temporal
    
  3. Using Data API (from Lambda or application):

    const AWS = require('aws-sdk');
    const rdsDataService = new AWS.RDSDataService();
    
    const params = {
      resourceArn: 'arn:aws:rds:region:account:cluster:dev-auroracluster',
      secretArn: 'arn:aws:secretsmanager:region:account:secret:Mahira',
      database: 'temporal',
      sql: 'SELECT version();'
    };
    
    const result = await rdsDataService.executeStatement(params).promise();
    

Cost Optimization Tips

  1. Set appropriate auto-pause duration based on usage patterns
  2. Use Data API to avoid connection management overhead
  3. Monitor scaling metrics to optimize min/max capacity
  4. Enable Aurora Serverless v2 for finer-grained scaling (requires template update)
  5. Review backup retention period based on compliance requirements

Monitoring

Key metrics to monitor:

  • ServerlessDatabaseCapacity: Current ACU allocation
  • DatabaseConnections: Active connection count
  • CPUUtilization: Processor usage percentage
  • FreeableMemory: Available RAM
  • NetworkThroughput: Data transfer rates

Access metrics via CloudWatch dashboard or AWS Console RDS section.


Was this page helpful?