Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add path parameter to AWS::Serverless::Function

I have a cloudformation template that generates an API. I want one of the endpoints to have a path parameter. However, I don't understand how I can achieve this with AWS::Serverless::Function. Here is my current function:

GetItems:
  Type: AWS::Serverless::Function
  Properties:
    Handler: api/items/get.handler
    Timeout: 29
    CodeUri: .
    Events:
      Get:
        Type: Api
        Properties:
          Method: get
          Path: /items
          RestApiId: !Ref MyAPI

This creates an endpoint like aws-domain-example.com/v1/items. This works just fine.

However, I want aws-domain-example.com/v1/items/{item_id}

How can I add a path parameter?

like image 394
Gary Holiday Avatar asked Mar 31 '26 21:03

Gary Holiday


1 Answers

I believe template should be as below. so you can access it as event.pathParameters.itemCode

      Events:
        Get:
          Type: Api
          Properties:
            Path: /item/{itemCode}
            Method: get
like image 132
Amit Naik Avatar answered Apr 02 '26 14:04

Amit Naik



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!