0

I need to pass a path param in the API.

By using the mapping template, I am able to pass query params and use them in the function.

Mapping template:

{ "Id": "$input.params('Id')" //this works fine after passing params as <url>?param=vale } 

With reference to this I created the mapping template as following-

{ "Id": "$input.params().querystring.get('Id')" // requirement is to be able to use <url>/value } 

I tried using 'Method request template' under genrate template, but it didn't work either.

When I invoke the URL urlname.execute-api.us-east-2.amazonaws.com/stag/functionname, it gives the value as undefined.

This is how I'm using the param:

class Lambda { static run(event, context, callback) { callback(null, 'Id '+ event.Id); } } module.exports = Lambda; 

Also, please tell me how to use those params in code. Be kind :)

4
  • Are you using Lambda Proxy? Commented Dec 4, 2019 at 15:25
  • @AssaelAzran I see answers related to that. Is it absolutely mandatory? Commented Dec 4, 2019 at 17:37
  • No. i just asked it to get more information. so i guess your api is a non proxy one. am i right? Commented Dec 4, 2019 at 17:42
  • Yes. I would prefer keeping it that way. Commented Dec 4, 2019 at 17:46

1 Answer 1

2

In order to be able to use <url>/value and get value from event follow this (Tested):

Configure your API gateway resource

enter image description here

enter image description here

Under /api2/{id} - GET - Integration Request configure your Mapping Templates

enter image description here

Execute request https://123456.execute-api.my-region.amazonaws.com/stage/api2/123

Lambda

console.log(event.id) callback(null, { id:event.id }); 

CloudWatch

enter image description here

Hope this helps

Sign up to request clarification or add additional context in comments.

3 Comments

how do we configure {id} under api?
just create a resource under api and in the path section insert {id}
added a snapshot to my answer. if you are using a non proxy api don't forget to configure status code in your method response.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.