Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Aurora Data Api from CloudFormation

I have a CloudFormation template that creates my RDS cluster using aurora serverless. I want the cluster to be created with the data API enabled.

The option exists on the web console: https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html

But I can't find it on the CloudFormation documentation. How can I turn this option on from the template?

like image 444
Lucas Ferreira Avatar asked Feb 28 '19 17:02

Lucas Ferreira


People also ask

How do I enable API data in AWS?

AWS CLI. When you create or modify an Aurora Serverless v1 DB cluster using AWS CLI commands, the Data API is enabled when you specify --enable-http-endpoint . You can specify the --enable-http-endpoint using the following AWS CLI commands: create-db-cluster.

How do I connect to Amazon Aurora database?

You can connect to an Aurora DB cluster using the same tools that you use to connect to a MySQL or PostgreSQL database. You specify a connection string with any script, utility, or application that connects to a MySQL or PostgreSQL DB instance. You use the same public key for Secure Sockets Layer (SSL) connections.

What is data API in AWS?

For customers using AWS Lambda, the Data API provides a secure way to access your database without the additional overhead for Lambda functions to be launched in an Amazon VPC. Integration with the AWS SDK provides a programmatic interface to execute SQL statements with parameters.


2 Answers

Set the EnableHttpEndpoint property to true, e.g.:

AWSTemplateFormatVersion: '2010-09-09'
Description: Aurora PostgreSQL Serverless Cluster
Resources:
  ServerlessWithDataAPI:
    Type: AWS::RDS::DBCluster
    Properties:
      Engine: aurora-postgresql
      EngineMode: serverless
      EnableHttpEndpoint: true
      ScalingConfiguration:
        ...
like image 182
Alejandro C De Baca Avatar answered Sep 28 '22 04:09

Alejandro C De Baca


You can enable the Data API from CloudFormation by creating a custom resource backed lambda and enable it using any of the available SDK.

I use boto3 (python), so the lambda would have code similar as below:

import boto3

client = boto3.client('rds')

response = client.modify_db_cluster(
    DBClusterIdentifier='string',
    EnableHttpEndpoint=True|False
) 

Obviously, you need to handle different custom resource request types and return from the lambda with success or failure. But to answer your question, this is the best possible way to set up data API via CloudFormation, for now, IMHO.

For more information about the function (Boto3): https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/rds.html#RDS.Client.modify_db_cluster

like image 32
Biplob Biswas Avatar answered Sep 28 '22 05:09

Biplob Biswas