Direkt zum Inhalt

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 Antwort
2
Akzeptierte Antwort

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
beantwortet vor 3 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.