1

I am trying to use aurora serverless data API feature to reduce the db connection time in my serverless application. But building client is taking time.

I would like to call rds HTTP service via lambda to get/post data.

I came across some was posts but I am still getting error, missing authentication token

https://docs.aws.amazon.com/rdsdataservice/latest/APIReference/API_ExecuteStatement.html

My sample request is below for MySQL. I have run this via AWS cloud shell.

curl --location --request POST 'https://rds-data.us-west-2.amazonaws.com/Execute' \
--header 'Content-Type: application/json' \
--data-raw '{
"continueAfterTimeout": false,
"database": "demo_data",
"includeResultMetadata": true,
"parameters": [],
"resourceArn": "arn:aws:rds:us-west-2:*******:cluster:rds-serverless",
"schema": "demo_data",
"secretArn": "arn:aws:secretsmanager:us-west-2:******:secret:serverless/user_u-cMt2Q4",
"sql": "select now()"
}'

  • This might help you, it helped me. https://docs.aws.amazon.com/code-samples/latest/catalog/python-signv4-v4-signing-get-post.py.html – IrishGeek82 Nov 06 '21 at 02:16

1 Answers1

1

If I can recommend a different approach--AWS has already done a lot of work for you, so you shouldn't need to construct your own access mechanism for the data api.

For instance, from the command line you can access the data api using the aws cli application (available on mac, windows, linux, etc) like this:

aws rds-data execute-statement --resource-arn "arn:aws:rds:us-east-1:123456789012:cluster:mydbcluster" \
--database "mydb" --secret-arn "arn:aws:secretsmanager:us-east-1:123456789012:secret:mysecret" \
--sql "select * from mytable"

For access to the data api from within a lambda, you would usually want to pull in the sdk for whatever language your lambda is setup to run and then to use their libraries to access the data api and other services.

If you are dead-set on using the command line from within lambda you could even create a lambda layer that includes the aws cli mentioned above and then use a system command to call the api that way, though I wouldn't recommend it.

Hopefully one of these easier solution will work better for you than curl!

adavea
  • 1,535
  • 1
  • 19
  • 25