in AWS API Gateway how can I pass data from Integration Request to Integration Response when I'm using mock integration

0

Hello. I don't want to use Lambda function. I want to directly pass data from Integration Request to Integration Response. my Integration Request's mapping template looks like this :

{
  "statusCode": 200
}

I want to extract statusCode from this and use it in Integration Response. I'm trying it in following way :

{
"provided_statusCode": "$input.path('$.statusCode')"
}

I also tried input.json('$.statusCode') but it doesn't work. can anyone help? I got response :

{
  "provided_statusCode": ""
}
1 Answer
1
Accepted Answer

In API Gateway you have to create Integration Response and Method Response for each status code (200, 302, 400, 500) you want to present.

You can get all data from Integration Request into Integration Response except Status Code since API Gatewway manages it for you.

Here's an example of getting the body from Integration Request into Integration Response when using Mock:

Integration Request
#set($context.requestOverride.path.body = $input.body)
{
  "statusCode": 200,
}
Integration Response
#set($body = $context.requestOverride.path.body)
{
  "statusCode": 200,
  "body": $body,
}
AWS
vtjean
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions