To add a requestId to the request body using a mapping template in API Gateway, you can use the following steps:
- In the API Gateway console, go to your API's Resources page and select the desired resource method.
- Click on the Integration Request card to show the integration options.
- Under Mapping Templates, create a new mapping template by selecting "Add mapping template".
- Select "application/json" as the Content-Type and enter the input for the new mapping template.
- To add the requestId to the request body, use the following code in the template:
{
"requestId": "$context.requestId"
}
- Click "Save".
- Finally, deploy the updated API. Once deployed, the requestId will be added to the request body of all incoming requests.