0

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.

1 Answer 1

1

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.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.