Skip to content

What is the proper decoration for a {proxy+} #700

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

Closed
gwlester opened this issue Sep 25, 2021 · 7 comments
Closed

What is the proper decoration for a {proxy+} #700

gwlester opened this issue Sep 25, 2021 · 7 comments
Labels
documentation Improvements or additions to documentation p1
Milestone

Comments

@gwlester
Copy link
Contributor

What were you trying to accomplish?
We want to have a function handle proxying to an ELB.

  MicroServices:
    Type: AWS::Serverless::Function
    Properties:
      Handler: 'microServices.api_call_dispatcher'
      FunctionName: !Sub "micro-services"
      CodeUri: ../../src/microServices/
      Description: Implements calls to all of the micro servcies
      Runtime: python3.8
      Timeout: 60
      Layers:
        - !GetAtt rAwsLambdaPowertoolsPythonLayer.Outputs.LayerVersionArn
      Events:
        OnPremiseApiEvent:
          Type: Api
          Properties:
            Path: /proxy/{proxy+}
            Method: Any
            RestApiId:
              Ref: rApiGateway
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver

app = ApiGatewayResolver()

@app.get("/proxy/<proxy>")
def proxy(proxy):
    try:
        return on_premise_api_handler(app, proxy)  #

def lambda_handler(event, context):
    return app.resolve(event, context)

Expected Behavior

Documentation containing the correct decoration for a proxy handler.

Current Behavior

No documentation containing the correct decoration for a proxy handler.

Possible Solution

Steps to Reproduce (for bugs)

Environment

  • Powertools version used: 1.20.2
  • Packaging format (Layers, PyPi): Layer
  • AWS Lambda function runtime: 3.8
  • Debugging logs

How to enable debug mode**

# paste logs here
@gwlester gwlester added bug Something isn't working triage Pending triage from maintainers labels Sep 25, 2021
@heitorlessa
Copy link
Contributor

Hey @gwlester, could you try the following and let us know if it works for you?

@app.get("/proxy/.+")

We made a conscious decision not to support "proxy+" to prevent customers into having a single Lambda function for everything.

That said, we understand there are edge cases and we support regex in the route definition, so "/proxy/.+" should match the greedy pattern you defined up there.

@gwlester
Copy link
Contributor Author

@heitorlessa, thanks for the fast reply!

We will try first thing Monday morning.

Any chance of documenting this in the docs?

@heitorlessa heitorlessa added documentation Improvements or additions to documentation and removed bug Something isn't working triage Pending triage from maintainers labels Sep 25, 2021
@heitorlessa
Copy link
Contributor

Absolutely - I'd love to hear from you first before we add in. In fact, I'll be jet lagged by Monday, so I highly appreciate a PR if you could help.

PS: You can run docs locally by using make docs-local-docker.

@gwlester
Copy link
Contributor Author

I will take a crack at it.

It would have been assume if

@app.get("/proxy/<.+">)
def proxy_service(**kwargs):

would have worked to get everything pass /proxy/ passed into proxy_service.

@heitorlessa
Copy link
Contributor

heitorlessa commented Sep 25, 2021 via email

@heitorlessa
Copy link
Contributor

hey @gwlester just tested and @app.get("/.+") works as a greedy pattern. You do lose the named parameters as you can't use <.+> though.

I'm gonna send a PR updating the docs

@heitorlessa heitorlessa added this to the 1.21.0 milestone Sep 28, 2021
@heitorlessa heitorlessa added the pending-release Fix or implementation already in dev waiting to be released label Sep 28, 2021
@heitorlessa
Copy link
Contributor

This is now available in the stage docs: https://awslabs.github.io/aws-lambda-powertools-python/develop/core/event_handler/api_gateway/#catch-all-routes

I'm gonna resolve this for now as the feature is already available but was undocumented in the latest doc.

@heitorlessa heitorlessa removed the pending-release Fix or implementation already in dev waiting to be released label Sep 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation p1
Projects
None yet
Development

No branches or pull requests

2 participants