Mapping template for API Gateway with Secrets Manager integration

Provides a mapping template for API Gateway and Secrets Manager integration

This snippet can be used to retrieve the secrets from Secrets Manager.
When creating the integration, ensure to have the below configuration to use the mapping template:
1. In Action type select Use action name and provide the Action Name as GetSecretValue.
2. Add the following headers in the integration headers:
X-Amz-Target: 'secretsmanager.GetSecretValue'
Content-Type: 'application/x-amz-json-1.1'
3. Provide IAM role with appropriate permission to perform GetSecretValue action on the secret resource
4. Select the integration HTTP method as 'POST'

Use the following mapping template which will fetch the SecretId from the input request body (secret_name) and pass it in the GetSecretValue API call as required in the API call:

#set($allParams = $input.params())
{
  "SecretId": "$input.path('$.secret_name')"
}
                                


The following payload can be used for testing this set up:

{
    "secret_name":"<secret name that is configured>"
}

                                


Created by:

Pallavi Bhat

Pallavi Bhat

Pallavi is a Cloud Support Enginner focusing on serverless at Amazon Web Services.

Follow on LinkedIn