Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite destination path in api gateway integration request

Say I have a resource like: /foo/{bar} in API Gateway. I want to transform the request path to /bing/baz/{bar} via an integration request template.

It is straight forward to set 'bar' into the request body via:

{ "bar": "$inputs.params('bar')" }

How do I rewrite the destination path at request time?

The solution is hinted at in 'Example Request Response' here:

https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html

but the docs don't outline exactly how 'With input template:' functions.

Resource: /things/{id}

With input template:
{
    "id" : "$input.params('id')",
    "count" : "$input.path(‘$.things').size()",
    "things" : $input.json(‘$.things')
}
like image 918
Ben McNiel Avatar asked Oct 30 '22 13:10

Ben McNiel


1 Answers

You might be looking for mapping template variable '$context.resourcePath' which will give you the resource path on which the request was made.

EDIT:

You can use path parameters in the URI field in the HTTP integration, which allows you to dynamically map parameters or fields in the body to the destination path. The syntax is the same as for resources, so curly brackets around the parameter like "http://myapi.com/foo/bar/{baz}".

Then you'll be able to specify a mapping expression for 'baz'.

like image 71
jackko Avatar answered Nov 15 '22 06:11

jackko