api gateway trying to use method.request.body in URL Path Parameters

0

Created a api gateway to s3 directory service, and everything is working I am trying to use method.request.body..$.cust in the URL Path Parameters to extract the request body info as a s3 destination. The request body is as below, {"cust" : "cust123"} Also tried method.request.body..$['cust'] and method.request.body..$.cust

Tried various different ways including but it doesn't seem to recognize the method.request.body, i tried to use the following links, https://docs.aws.amazon.com/apigateway/latest/developerguide/request-response-data-mappings.html https://docs.hevodata.com/sources/engg-analytics/streaming/rest-api/writing-jsonpath-expressions/ http://jsonpath.com/

2개 답변
1

This is doable using an API Gateway Request Mapping Template. First, I've made some assumptions:

  • You have a POST or PUT API method with a Request Body json payload something like this: {"cust" : "cust123"}
  • In your Integration Request you are making a direct integration call to S3 to GET an object with a Path override that has a path parameter ending with or containing "/{cust}"

If so, add the following Request Mapping Template:

#set($body-json = $util.parseJson($input.json('$')))
#set($context.requestOverride.path.cust = $body-json.cust)
profile picture
답변함 9달 전
  • Thanks for the reply.

    The integration request is a direct integration (PUT) into S3. with a path override set to {bucket}/{key}

    In URL Path parameters, bucket = 's3_loc' key = method.request.body..$.cust

    So based on this, I may have to do,

    #set($body-json = $util.parseJson($input.json('$'))) #set($context.requestOverride.path.key = $body-json.cust)

0

I tried this and got

Method request body before transformations: [Binary Data] Execution failed due to configuration error: Cannot map binary data to parameters

And I have these set in the settings like below, Enter image description here

Enter image description here

Enter image description here

tans
답변함 9달 전
  • The key in your path comes from cust in the json request body. You won't need the URL Path Parameters setting for key since you aren't mapping it any longer, you are setting it in the Mapping template.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠