Reputation: 960
I am using an AWS Serverless Function to create API events. Currently I am working on my GET event and it works the way I want it to with the given URL from AWS. I want to be able to put a / and then a number and be able to get this number. For example, it would be myurl/1
. That number would be used to get a specific id versus the original function which gets all ID's. I am using a CloudFormation template so it needs to be something I put into the template. The event section currently looks like:
Events:
GetEvent:
Type: Api
Properties:
Path: /
Method: get
I need to know where to add a section to be able to accept a number at the end of the path so that I can use it in my code.
Upvotes: 0
Views: 119
Reputation: 19758
You can add the event as follows
functions
get:
handler: myurl/get.get
events:
- http:
path: myurl/{id}
method: get
cors: true
Note that above is not a part of CloudFormation resources section in serverless.yml.
Inside your event handler code in Lambda, you should be able to access the id parameter using the event object as follows
event.pathParameters.id
Refer this Serverless example for more details.
Upvotes: 1