Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path variables are not compatible with API Gateway #1010

Open
daymansiege opened this issue Feb 15, 2019 · 2 comments
Open

Path variables are not compatible with API Gateway #1010

daymansiege opened this issue Feb 15, 2019 · 2 comments

Comments

@daymansiege
Copy link

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
@jfuss jfuss added area/local/start-api sam local start-api command type/ux labels Apr 23, 2019
@napter
Copy link

napter commented Feb 20, 2020

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?

@chriskresge
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants