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

Unknown request when lambda invoke #1033

Closed
daoudsh opened this issue Jan 4, 2019 · 6 comments
Closed

Unknown request when lambda invoke #1033

daoudsh opened this issue Jan 4, 2019 · 6 comments

Comments

@daoudsh
Copy link

daoudsh commented Jan 4, 2019

Hello,

when deploying the lambda using chalice and using the API Gateway, I got no error and it works find. But when I invoke the same lambda from another lambda I got error "Unknown request".

After debugging, I found that the 'requestContext' is None in case of lambda invoke from another lambda.

@kyleknap
Copy link
Contributor

kyleknap commented Jan 8, 2019

@daoudsh how are you invoking the chalice deployed lambda function from the other lambda function? A code snippet for both lambda functions would be useful.

@daoudsh
Copy link
Author

daoudsh commented Jan 9, 2019

@kyleknap thanks for your response.
I created a small example that show the error with some custom log in line 645 in file chalice/app.py

    def __call__(self, event, context):
    # This is what's invoked via lambda.
    # Sometimes the event can be something that's not
    # what we specified in our request_template mapping.
    # When that happens, we want to give a better error message here.
    print('event: ' + json.dumps(event))
    resource_path = event.get('requestContext', {}).get('resourcePath')
    if resource_path is None:
        return error_response(error_code='InternalServerError',
                              message='Unknown request.',
                              http_status_code=500)

You can see the full example in chalice_example

You can also find the fix for this issue in chalice_fork

thanks

@kyleknap
Copy link
Contributor

kyleknap commented Jan 9, 2019

@daoudsh Thanks for the info! Is there a particular reason you are using API Gateway + Lambda function integration (e.g. app.route() decorator) instead of just a pure lambda function (e.g. the app.lambda_function() decorator)? I'm only asking this because I noticed in the cha-invoke code you are trying to invoke the lambda function directly without making the request go through API Gateway.

@daoudsh
Copy link
Author

daoudsh commented Jan 9, 2019

@kyleknap this is no particular reason for that but it is easier to read and handle multi API in the same lambda. And also I am also java developer who like to use Spring Framework.

cha-invoke is invoking directly cha-lambda because sometimes I need to keep one lambda secured in AWS and not exposing it to public.

@kyleknap
Copy link
Contributor

@daoudsh based off this comment:

cha-invoke is invoking directly cha-lambda because sometimes I need to keep one lambda secured in AWS and not exposing it to public.

I think it may make sense to convert your cha-lambda to use the app.lambda_function() decorator. When using the app.route() decorator you will always get an API Gateway API that is public. By using app.lambda_function(), it will only be able to be invoked by your account, assuming you do not add any extra permissions. You also will not have to worry about formatting the same payload that gets sent by API Gateway to invoke the lambda function and allow you to format your own schema. Hope this help!

@daoudsh
Copy link
Author

daoudsh commented Jan 14, 2019

@kyleknap
I replaced app.route() with app.lambda_function() and I didn't get the error.
The main reason why I used Chalice and its routing feature is that it makes the code readable and easy to maintenance.
thanks for your support.
Anyway I will keep using my fix (and I hope in future that this issue will be solved)

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

No branches or pull requests

3 participants