Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Deploying Dash on Lambda with serverless

Morning all,

I’m wondering if anyone has experience of deploying small dash apps on Lambda? I’m in the middle of trying to get this to work (with some limited success) using the Serverless framework. From scouring the internet it doesn’t seem like there’s a whole heap of content written on the subject other than some brief discussion on the Zappa GitHub page.

Interested in people’s opinions (“use ECS or Fargate” is probably the right answer) and if I can crack it and have some half decent code I’ll share my findings.

1 Like

Hey, Lambda is not really the right solution. It is meant for very small discrete pieces of functionality that run on minimal infrastructure and doesn’t support GUIs. Spin up, run, spin down, as quickly as possible. ECS and Fargate are still not great because you have to set up things around them to do URL routing. EBS is the only good AWS solution IMO due to needing a URL.

…unless Lambda does support GUIs? I’m interested.

Well I’ve had a sort of successful attempt with some caveats. I have the following;

A Lambda that runs a Dash app to pull some data on the performance of Lambda functions on the account (Invocations, Errors etc) for the previous 24hrs. The Lambda is deployed with Serverless using the Serverless WSGI plugin. The entry point of the Lambda via the WSGI handler is app.server (the flask server) so I’m following the same approach you’d use to deploy a Flask app on Lambda.

This lambda is accessed/triggered by an API Gateway. Other than the initial data pull taking ~20s (I have ways to speed that up) it all seems to work reasonably well. I’ve tried where possible to do as much of the data work outside of the “app” so it runs once per Lambda instantiation not invocation. The only problem I currently have now is it only works with the raw API Gateway URL and not when I sanitise it with a nice Route53 URL. I believe this is due to a conflict between the actual URL have a Dev/Test/Prod suffix (which API Gateway mandates in some way) as I’m seeing 403 errors on some pieces of the app like the Dash renderers.

For now, the ugly URL will do, and I’m trying to make a nice clean example I can pop on GitHub. So watch this space and as soon as I get time I can share some code.

I’ll keep on eye on this thread. I hate the cost of deploying on EBS - I can do it for work projects but it’s not worth it for my personal projects

Hey any update on this? I’d be very interested in reading this if you put it on github.

great idea! I’d very interested in the development and hearing more!

Whenever you have something to share - it would be great to get a first look!

Thank you

Thinking about doing the same thing. Are you running into size limits? Can you send me a pm on linkedin https://www.linkedin.com/in/fbosler/

Cheers

Sorry for the slack responses! Yes I got it working though I couldn’t get it working with Route53. Work are more than happy for me to Open Source the lot. So I’ll get the repo tidied up and get it up on GitHub.

I’ve successfully deployed a dash app using zappa (which generates the lambda handler for the app).
Struggling with cognito user pools authorizer however. no luck there.

Got it working too, but find that it’s super slow and breaks when many people are using it at the same time. Have you noticed something similar?

Cheers

I find the Lambda startup time is high (30s or so) before my graph shows data because I’m doing a lot of data pulling that I could probably either store in the app or have coming from Dynamo instead. Once I have a lambda instance then it works fine for others as all of the data standup is done outside of the lambda handler so is only done once per instantiation (or when we hit the refresh period). Not sure if that helps at all?

I’d love to be digging more into this but there’s limited time at work and outside work I’m also doing an OU course. Hence my knowledge isn’t expanding as quickly as I’d like

Hey @pravincv - did you end up getting cognito working?