-
-
Notifications
You must be signed in to change notification settings - Fork 950
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
Falcon app on AWS lambda ? #1552
Comments
Hi 👋, Thanks for using Falcon. The large amount of time and effort needed to Please consider helping us secure the future of the Falcon framework with a Thank you for your support! |
Hi @Gorbus , Furthermore, do not hesitate to ask questions/share insights on our Gitter channels: https://falconframework.org/#sectionCommunity Kindly, |
@Gorbus It's been awhile since I ran Falcon on Lambda as I'm no longer on a project that requires it these days. However, when I did, I was able to use the import logging
from falcon_lambda import logger, wsgi
from example.app import MyFalconApp
logger.setup_lambda_logger(logging.DEBUG)
log = logging.getLogger(__name__)
api = MyFalconApp()
def lambda_handler(event, context):
log.debug(event)
resp = wsgi.adapter(api, event, context)
log.debug(resp)
return resp API Gateway Definition: swagger: "2.0"
info:
version: "v1"
title: "My App"
description: ""
schemes:
- https
consumes:
- application/json
produces:
- application/json
paths:
/{proxy+}:
x-amazon-apigateway-any-method:
responses: {}
x-amazon-apigateway-integration:
type: "aws_proxy"
credentials: "${lambda_role}"
uri: "${lambda_arn}"
httpMethod: "POST" From there, I believe the biggest annoyance going forward is packaging your function. The product I was on had their own lambda packaging system, so unfortunately I'm not much help there, but hopefully this gets you pointed in the right direction. |
Hey to both of you, Thank you for your quick answer, I can see Falcon is a very nice and active community. Unfortunately my knowledge in python and lambda are very low, I was hoping there would be a library that would do the hard work (including packaging) for me just as claudiajs does it for lambda in nodejs. I guess I'll have to give up on the lambda solution and go for a vps or anything else to run my api with falcon (or any other proposal of easy to deploy solution for mini falcon app ??) |
You can use Zappa to package the function for you |
I noticed that google cloud functions has a falcon example for deployment. Its pretty easy to deploy any pip packages there as well. |
Posting for reference what I previously googled:
|
I have recently heard from our community (@zacharyabresch) that this package also gets the job done: https://github.com/truckpad/aws-lambda-wsgi . |
Ya know, I found this issue early on in my research and forgot all about it. Can confirm, this module is working in my project to send AWS Lambda events (from API Gateway) to Falcon. This comes with one caveat ... my project is only working with incoming requests. Currently, API Gateway responses are timing out but I have not determined the cause of this. As this app involves a lot of file uploading & downloading, it is more likely my source than the above-mentioned WSGI module). I'll respond back with my results once I can verify that requests are making the round trip as expected. |
Hi again @zacharyabresch , The default timeout is only 3 seconds, which may not be enough to handle file uploads:
Furthermore, note that memory is scaled together with CPU:
Using a low value (is 128MB default?) might give you a very poor vCPU share, which in turn may further exacerbate the timings issue. I have never used Lambda for HTTP though, only for scaling out CPU-expensive background jobs to the cloud. |
Good call but, in this case, it's the API Gateway timeout I'm hitting which is locked at 30 seconds max. After further debugging, I was able to prove that my issue is unrelated to the WSGI adapter so this can be considered a viable solution. In that process I swapped out Regardless, these are both viable solutions to running Falcon inside a Lambda. I plan on writing a post about it someday. :) |
Aha, sorry! I'm thinking whether we should actually document Falcon on AWS Lambda as a Deployment article 🤔 |
I started a draft for this post last night. Hoping to work on it over the week and get an example posted soon. |
Got sample code repository up (https://github.com/zacharyabresch/falcon-on-aws-lambda) and have tested it in AWS. Learned something too ... the API Gateway must be using the 1.0 payload version which is only available, AFAICT, with HTTP APIs, not REST. Explains some things I was seeing when hooking my work project up. Post forthcoming. |
I just created a PR for you repo, when I tried to run the example that you provided in Lambda I got the error:: I replaced App with API() and now everything is working properly, I have an API function in front of a Lambda falcon API and everything is working (y) |
@ilietrasca Just to clarify |
@ilietrasca Thanks for the heads up! As @vytas7 mentioned, I'm using the new API but I'll make a note of that in the README on my project. |
For falcon 3 with asgi I think we can check if https://github.com/jordaneremieff/mangum works |
Hi,
I have a little api working locally thanks to falcon and it can connect to my AWS RDS postgresql database. It is mainly a GET API as I already have the data I need in the database but need them to be accessible.
The code is not really relevant for the question except that I need to import two packages :
import falcon
import psycopg2
and I am using gunicorn to run it locally.
So far so good, However I am trying to reproduce this on a AWS lambda function with an API gateway and I just cannot manage to have it run. (idea would be to have a publicly accessible api) I started a python lambda with the hello world template and copied my code. However I am pretty sure that the packages I import are not there (falcon and psycopg2). How can I have them in it ? Also is gunicorn needed to run the function or not ?
Afterwards I also tried to create the api gateway in aws but it didnt want to work when I tried to go to the http address generated : I got wrong authentification token.
I am not a python dev, rather a Js one but for this one I need it to be in python as the rest get function is complex and already exists in python.
If you have any lead or tutorial to explain how to convert my little 100 lines of code with its 2/3 dependencies into a working http api online on Lambda, I'd be more than glad. I also tried using Zappa but somehow went from error to error and as my code is pretty simple and just need a few packages I though I could probably do it manually or with a little help from the falcon community.
Thanks for any lead.
The text was updated successfully, but these errors were encountered: