Enable DATA Api for Amazon Aurora

Viewed 2367

We have a running AWS Aurora Cluster (Not the serverless version). I was already successfully connected to the DB externally via Querious (GUI for SQL) When using the Golang RDS SDK I get the following error message:

HttpEndpoint is not enabled for cluster sample-db-cluster. Please refer to https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html#data-api.troubleshooting

This links tells me to activate the Data API.

Problem: This link and anything else I have found so far always relates to serverless Aurora and I could not find any way to enable this for my Aurora instance.

I also tried to enable the DATA Api via the CLI:

aws rds modify-db-cluster --db-cluster-identifier my-cluster-id --enable-http-endpoint --region us-east-1

This did not work!

Below is my go code to connect to Aurora:

package main

import (
"fmt"
    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/credentials"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/rdsdataservice"
    "log"
    "os"
)

func main() {

    sess:= getSession()
    SQLStatement := `SELECT * FROM testTable`
    fmt.Println("SQLStatement",SQLStatement)
    rdsdataservice_client := rdsdataservice.New(sess)
    req, resp := rdsdataservice_client.ExecuteStatementRequest(&rdsdataservice.ExecuteStatementInput{
        Database:    aws.String("my-database-name"),
        ResourceArn: aws.String("arn:aws:rds:us-east-1:XXXXXXXXXXX:cluster:XXXXXXXX"),
        SecretArn:   aws.String("arn:aws:secretsmanager:us-east-1:XXXXXXXXXXX:secret:XXXXXXXX"),
        Sql:         aws.String(SQLStatement),
    })

    err1 := req.Send()
    if err1 == nil {
        fmt.Println("Response:", resp)
    } else {
        fmt.Println("error:", err1) // Produces the mentioned error
    }
}


func getSession() *session.Session {

    var sess *session.Session
    var err error
    if os.Getenv("aws_access_key_id") != "" && os.Getenv("aws_secret_access_key") != "" && os.Getenv("aws_region") != "" { // explicit credentials
        creds := credentials.NewStaticCredentials(os.Getenv("aws_access_key_id"), os.Getenv("aws_secret_access_key"), "")
        sess, err = session.NewSession(&aws.Config{
            Region:      aws.String("us-east-1"),
            Credentials: creds,
        })
        if err != nil {
            log.Println("Error cred")
        }
    } else {
        sess = session.Must(session.NewSession()) // credentials are passed implicit by role lambda-news-parser-executor (defined in IAM)
    }
    return sess
}
2 Answers

I could not find any way to enable this for my Aurora instance

This is because it is not supported. Data API is only for Serverless Aurora.

Ok! I found that issue the github.com/aws/aws-sdk-go/service/rdsdataservice is only usable for serverless Aurora not the "normal" instances.

Link here

Package rdsdataservice provides the client and types for making API requests to AWS RDS DataService. Amazon RDS provides an HTTP endpoint to run SQL statements on an Amazon Aurora Serverless DB cluster. To run these statements, you work with the Data Service API.

Related