aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Path variables are not compatible with API Gateway

Open daymansiege opened this issue 6 years ago • 2 comments

Description

It is possible to extract variables from path when using sam local start-api but not all supported cases are valid for deployment to AWS API Gateway.

Steps to reproduce

Create lambda and SAM template to be triggered by path with variables:

TheFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Handler: app.lambdaHandler
      Runtime: nodejs8.10
      Events:
        Aliases:
          Type: Api
          Properties:
            Path: /{product}/prefix_{type}_suffix/{id}.json
            Method: get

Start local API and invoke URL http://127.0.0.1:3000/good-stuff/prefix_type_A_suffix/123.json You can see that path parameters were successfully parsed:

console.log(event.pathParameters);
{ product: 'good-stuff', type: 'type_A', id: '123' }

But when trying to deploy such template to API Gateway you will get error Resource's path part only allow a-zA-Z0-9._- and curly braces at the beginning and the end.

Observed result

All works fine!

Expected result

I'd expect SAM CLI to tell me that such format is not supported.

As a workaround, you have to define path like /{product}/{param_with_type}/{id_with_extension} and parse variables out of path parameters, or just setup proxy integration and parse path parts on you own (or by some framework which will do all the routing for you), which is fine as such path variables are not supported in AWS API Gateway now, as far as I know.

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: Windows
  2. sam --version: SAM CLI, version 0.11.0

daymansiege avatar Feb 15 '19 12:02 daymansiege

It is a a year later but I get the same error about the path when deploying a SAM template that includes "Path: "/users/{+proxy}"". Is this not possible?

napter avatar Feb 20 '20 06:02 napter

@napter did you try: "Path: /users/{proxy+}"? That should work better.

chriskresge avatar Oct 27 '20 20:10 chriskresge