跳至內容

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 個回答
2
已接受的答案

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
已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。