Skip to content

Conversation

vincentsarago
Copy link
Owner

@vincentsarago vincentsarago commented Jul 31, 2019

closes #16

To Do

  • live test
  • update docs

@vincentsarago
Copy link
Owner Author

vincentsarago commented Jul 31, 2019

deployed this code

"""app.py"""

from lambda_proxy.proxy import API

api = API(name="api", debug=True)


# This route won't work when using path mapping
@api.route("/", methods=["GET"], cors=True)
# This route will work only if the path mapping is set to /api
@api.route("/api", methods=["GET"], cors=True)
def index():
    html = """<!DOCTYPE html>
    <html>
        <header><title>This is title</title></header>
        <body>
            Hello world
        </body>
    </html>"""
    return ("OK", "text/html", html)


@api.route("/yo", methods=["GET"], cors=True)
def yo():
    return ("OK", "text/plain", "YOOOOO")


@api.route("/hey", methods=["GET"], cors=True)
def hey():
    return ("OK", "text/plain", "HEYYYYY")

serverless.yml

service: demo

provider:
  name: aws
  runtime: python3.6
  stage: ${opt:stage, 'production'}

  region: eu-central-1

package:
  artifact: package.zip

functions:
  api:
    handler: app.api
    memorySize: 128
    timeout: 3
    events:
      - http:
          path: /{something+}
          method: any
          cors: true
      # This is to support `/` root route, 
      # but won't work when using custom domain
      - http:
          path: /
          method: get
          cors: true

and it's not working because pathParameters is set to {"proxy": "yo"} and thus path is yo while the lambda_proxy is looking for /yo

@vincentsarago

This comment has been minimized.

@vincentsarago

This comment has been minimized.

@vincentsarago vincentsarago marked this pull request as ready for review July 31, 2019 23:37
@vincentsarago
Copy link
Owner Author

@DanSchoppe this is ready, if you can test from this branch it would be great

@vincentsarago vincentsarago self-assigned this Jul 31, 2019
Copy link

@DanSchoppe DanSchoppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DanSchoppe this is ready, if you can test from this branch it would be great

Wow! Thank you for putting all this effort in!

I deployed a new tiler with custom base mapping and confirmed it fixed my original issue 🎉 💯. I also tested the endpoint without a base path mapping and confirmed it works perfectly as well 😄

@vincentsarago vincentsarago merged commit 80f60f4 into master Aug 1, 2019
@vincentsarago vincentsarago deleted the pathproxy branch August 19, 2019 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Path resolution for API Gateway custom domain base path mapping
2 participants