9
votes

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?

3
It's in the "roadmap" github.com/aws-cloudformation/… - Yves M.

3 Answers

2
votes

Enabling the Data API is currently only possible in the web console. This feature is still in beta so things like CloudFormation support and availability outside of us-east-1 are still pending, and using the Data API in production should be done with caution as it may still change.

13
votes

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:
        ...
3
votes

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