4
votes

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')
}
1

1 Answers

2
votes

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'.