mobilequickie / rds-aurora-mysql-serverless

Getting started with Amazon Aurora Serverless Databae with Data API for building cloud enabled serverless backends for mobile and web applications.
Apache License 2.0
13 stars 4 forks source link

Getting Started with Amazon RDS Aurora Serverless Data API

Getting started with Amazon RDS Aurora (MySQL) Serverless with Data API for building cloud enabled serverless backends for mobile and web applications.

If you want to learn a bit more about Aurora Serverless Data API, checkout my getting started blog here.

In this repo, I have uploaded a one-click CloudFormation template that will deploy all the resources necessary to build a Serverless Aurora MySQL database and provided manual steps to enable the Data API and connect to this serverless database via an AWS Lambda function using the RDSDataService API.

In this solution below, we'll create resources using a CloudFormation template that does the following:

Note: The CloudFormation template does not currently enable the "Data API" for the created Aurora Serverless Cluster as this feature is currently in BETA. The only (feasable) way to enable Data API is through the RDS management console. See step 2 to enable the Data API manually after the Cloudformation Stack completes.

Step 1: Create an Aurora Serverless Database via CloudFormation

This CloudFormation template automates the creation of an RDS Aurora MySQL Serverless Cluster, an AWS Secrets for storing the cluster master account credentials, an AWS Lambda function used to make CRUD operations directly against your serverless database, and all the permission needed.

Once the stack completes, see the Output tab for the Aurora Cluster Arn and Secrets Arn which will be used to for connecting to the database via the AWS CLI, SDK, or Lambda. Please note that these arn's will also automatically made available as environment variables for the deployed Lambda function.

⚡️ Getting Started

  1. Click on the Launch Stack button to start provisioning your new Aurora MySQL Serverless Database (defaults to us-east-1 region).

    Launch Stack

    This will launch the AWS CloudFormation Console, passing in the template, create a new stack, and automate the creation of an Aurora Serverless Cluster, database, Lambda function, and IAM role.

  2. Click Next on the Select Template page

  3. Provide a Database name (e.g. MarketPlace) and a master username/password for connecting to your serverless instance. Stack Output

  4. Click Next

  5. On the Options page, leave all the defaults and click Next

  6. On the Review page, check the box to acknowledge that CloudFormation will create IAM resources and click Create.

  7. Wait for the my-serverless-cluster stack to reach a status of CREATE_COMPLETE

  8. With the my-serverless-cluster-stack selected, click on the Outputs tab and you should see three rows. Stack Output

  9. Copy the Value for each of the three resources as we’ll be pasting those values into AWS CLI command for executing CRUD operations agains the serverless database.

Step 2: Enable Data API for your Aurora Serverless Cluster

Here we are going to enable the Data API for the newly created Aurora serverless cluster manually via the RDS Management Console. Hopefully this is temporary and we'll be able to enable via the CF template using EnableHTTPEndpointAPI.

  1. Launch the RDS Management Console
  2. Select your cluster (even though it says database)
  3. Select the Modify button on the upper right
  4. Select Data API under the Network & Security section
  5. Click orange Continue button
  6. Select Apply immediately under Scheduling of modifications
  7. Select Modify cluster button

Congrats! The Aurora Serverless Cluster is now Data API enabled.

📝 Notes about Data API and support

I'll try to keep this update as things change above.