Deploy your Streamlit app at scale to AWS Fargate using AWS CDK

Hi everyone,

I’ve just created this Git repo https://github.com/nicolasmetallo/legendary-streamlit-demo where I’m trying to show step by step how you can take your demo.ipynb, create an Streamlit app, package into a container image, and then deploy everything to AWS Fargate (serverless managed containers). That means that once you are done with the tutorial, you will have an app with: it’s own VPC, ECS Cluster, Application Load Balancer with a public-facing DNS, Auto-scaling, can talk to other AWS services, and that you can quickly edit and re-deploy.

Let me know your thoughts and any idea/comment on how to improve it.

Thanks!

13 Likes

Wow, that’s a really thorough demo @nicolasmetallo, thanks for sharing that! I hope to have a little time later to day to actually walk through this in detail :slight_smile:

Very nice! I hadn’t used Fargate before, only EC2 and EKS. After a quick read I now want to find some time to give it a try!

2 Likes

Cool. Does this support GPU inference?

Hi, you can specify the type of instance you want to run your ECS cluster on when you are writing your AWS CDK script, so I don’t see why it wouldn’t support GPU inference :slight_smile:.

1 Like

I’ve also riffed on @nicolasmetallo’s project and streamlined it a bit. You can try it out with a single command:

git clone https://github.com/tzaffi/streamlit-cdk-fargate.git && cd streamlit-cdk-fargate && make deploy-streamlit

Check it out here

3 Likes

That’s amazing @tzaffi! I’ll have a go at it during the week. Nice work :slight_smile:. Quick update on teh previous question by @avn3r, Fargate doesn’t support GPU instances as of now, but you can choose to deploy onto a cluster of EC2 instances instead.

1 Like

Sorry for bumping an old thread, but I was wondering if you guys had seen any issues where lots of users connect to the app at the same time. Does streamlit handle that well currently in your experience?

1 Like

Did you figure this out, John? I’d also like to know…

I was looking for a simpler tutorial. Something like a single click deploy.

@nicolasmetallo, I’ve been looking into AWS serverless deployments of Streamlit.

Ideally, I’d be able to use AWS Lambda for this use case, but I’m not sure whether this is supported. I believe that Lambda execution timeout terminates after 15 minutes. (This was 2018 so things might have changed.)

The typical SPA, say a React app, would be delivered to the user from an S3 bucket; so that’s a one-time data transfer. Now, when the user navigates the SPA, occasionally data from your backend server will be needed. These Fetch API calls might be routed to API Gateway and subsequently sent to AWS Lambda functions for execution. No big deal! The SPA maintains the state and that work has been offloaded to client side.

But as I understand Streamlit, there isn’t an equivalent of sending the SPA from an S3 bucket to a user as a one-time data transfer. Due to the usage of Python code, the Streamlit app will always be run on backend servers. In terms of computations, you (and your AWS account) are on the hook for every interaction the user makes with your server.

Sure, you could decouple your architecture and move code out of your Streamlit app and into Lambda functions, which are called by the Streamlit SPA. But at the end of the day, the 15 min timeout just isn’t going to work for Streamlit.

This would be the fundamental reason why you chose Fargate, right?