Skip to content

Instantly share code, notes, and snippets.

@maddiesch
Last active February 25, 2019 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maddiesch/864b994f4ef89c292e64ffb12e536116 to your computer and use it in GitHub Desktop.
Save maddiesch/864b994f4ef89c292e64ffb12e536116 to your computer and use it in GitHub Desktop.
Create an aurora serverless cluster.

Aurora Serverless

This template can be run in CloudFormation to create an Aurora Serverless cluster that can be accessed using the Data API.

Run the AuroraServerless.yml template.

Currently the Data API is only available in us-east-1.

Enable Data API

After the template is run, we need to enable the Data API.

  1. Head to the RDS Console and select your created cluster.

Select Cluster

  1. In the cluster summary page, select "Modify"

Modify Cluster

  1. In the modify page, scroll down to the "Network & Security" section.

Enable Data API

  1. Make sure that Data API is checked.

  2. Click Continue

  3. On the confirm screen make sure that the "Enable data API" is enabled.

If you don't want to wait you can choose to apply the changes immediately.

Apply Changes

Perform a query

aws rds-data execute-sql --db-cluster-or-instance-arn <value from DatabaseClusterArn> --aws-secret-store-arn <value from DatabaseConnectionSecretArn> --sql-statements "select * from information_schema.tables limit 1;"

---
Parameters:
DatabaseUsernameTemplateParameter:
Type: String
Description: The username for the database user
MaxLength: 16
Default: root
DatabasePasswordTemplateParameter:
Type: String
Description: The password for the database user
NoEcho: true
MaxLength: 64
MinLength: 8
DatabaseScalingAutoPauseTemplateParameter:
Type: String
Description: Should the database cluster auto-pause on inactivity
Default: true
AllowedValues:
- true
- false
DatabaseScalingMaxCapacityTemplateParameter:
Type: Number
Description: The maximum capacity for the auto-scaling.
Default: 8
AllowedValues:
- 2
- 4
- 8
- 16
- 32
- 64
- 128
- 256
DatabaseScalingMinCapacityTemplateParameter:
Type: Number
Description: The minimum capacity for the auto-scaling (Must be smaller than the maximum).
Default: 2
AllowedValues:
- 2
- 4
- 8
- 16
- 32
- 64
- 128
- 256
DatabaseScalingTTLTemplateParameter:
Type: Number
Description: The number of seconds before the cluster is paused.
Default: 300
MinValue: 60
MaxValue: 86400
Resources:
##
# The Serverless Database
DatabaseCluster:
Type: AWS::RDS::DBCluster
Properties:
MasterUsername: !Ref DatabaseUsernameTemplateParameter
MasterUserPassword: !Ref DatabasePasswordTemplateParameter
Engine: aurora
EngineMode: serverless
ScalingConfiguration:
AutoPause: !Ref DatabaseScalingAutoPauseTemplateParameter
MaxCapacity: !Ref DatabaseScalingMaxCapacityTemplateParameter
MinCapacity: !Ref DatabaseScalingMinCapacityTemplateParameter
SecondsUntilAutoPause: !Ref DatabaseScalingTTLTemplateParameter
DatabaseConnectionSecret:
Type: AWS::SecretsManager::Secret
Properties:
SecretString: !Sub
- |
{
"dbInstanceIdentifier": "${ClusterName}",
"engine": "aurora",
"host": "${ClusterHost}",
"port": ${ClusterPort},
"username": "${DatabaseUsername}",
"password": "${DatabasePassword}"
}
- ClusterName: !Ref DatabaseCluster
ClusterHost: !GetAtt DatabaseCluster.Endpoint.Address
ClusterPort: !GetAtt DatabaseCluster.Endpoint.Port
DatabaseUsername: !Ref DatabaseUsernameTemplateParameter
DatabasePassword: !Ref DatabasePasswordTemplateParameter
Outputs:
DatabaseConnectionSecretArn:
Value: !Ref DatabaseConnectionSecret
DatabaseClusterArn:
Value: !Sub arn:aws:rds:${AWS::Region}:${AWS::AccountId}:cluster:${DatabaseCluster}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment