question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Greedy Proxy Path Does Not Work Locally

See original GitHub issue

Description

Can not use greedy proxy path variable in local SAM server

Steps to reproduce

Using something like this template.yaml.

  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      DefinitionBody:
        swagger: 2.0
        info: { title: !Ref 'AWS::StackName' }
        basePath: '/'
        schemes: [ 'https' ]
        paths:
          /:
            get:
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}:live/invocations
                httpMethod: POST
                type: aws_proxy
          /{proxy+}:
            x-amazon-apigateway-any-method:
              parameters:
                - name: proxy
                  in: path
                  required: true
                  type: string
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}:live/invocations
                httpMethod: POST
                type: aws_proxy

  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: .
      Handler: app.handler
      Runtime: ruby2.5
      MemorySize: 512
      Timeout: 10
      Events:
        Root:
          Type: Api
          Properties:
            Path: /
            Method: GET
            RestApiId: !Ref MyApi
        All:
          Type: Api
          Properties:
            Path: /{proxy+}
            Method: ANY
            RestApiId: !Ref MyApi

And then using sam local start-api

Observed result

Any root / request works, but requesting a path like /foo/bar results in.

2019-03-03 10:59:10 127.0.0.1 - - [03/Mar/2019 10:59:10] "GET /foo/bar HTTP/1.1" 403 -

Expected result

Building and deploying to AWS works. Can it work locally?

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

  1. OS: Mac/Darwin
  2. sam --version: SAM CLI, version 0.11.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
prcongithubcommented, Oct 8, 2020

How can someone test this locally without support for /{proxy+}?

0reactions
metaskillscommented, Mar 5, 2019

Oh, I do think it might be. Will watch that one to see. Thanks! Closing this one now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Greedy Proxy Path Does Not Work Locally #1037 - GitHub
FWIW, I've been working around this by using /app/{proxy+} . Seem SAM needs some sort of anchor in the path to help it...
Read more >
go - Use /path/{proxy+} with AWS SAM to have a greedy API in ...
The reason this doesn't work is that gin receives the path from API Gateway RawPath which in your instance would include "/test".
Read more >
Set up a proxy integration with a proxy resource - Amazon API ...
To set up a proxy integration in an API Gateway API with a proxy resource, you perform the following tasks: ... Greedy path...
Read more >
404 Unable to identify proxy for host: <virtual host name> and url
Cause: Path not associated with any API proxy. If the API proxy is not configured to accept the requests for the specific path...
Read more >
API Gateway Express.js Greedy Paths to a full stack with Vue.js
To get up and running locally, after downloading the source, run npm install in the root directory, then change directories to the guestbook- ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found