liveBook · Manning

Chapter 12: Packaging and deploying Streamlit apps

What you will learn in chapter 12 of Build Python Web Apps with Streamlit

This chapter introduces moving beyond Streamlit Community Cloud by packaging a Streamlit app with Docker, deploying it to AWS Elastic Beanstalk, and giving it a custom HTTPS domain.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduces moving beyond Streamlit Community Cloud by packaging a Streamlit app with Docker, deploying it to AWS Elastic Beanstalk, and giving it a custom HTTPS domain.

Key terms: Docker, AWS, AWS Elastic Beanstalk, custom domain, HTTPS, Streamlit Community Cloud, deployment, traffic, memory, environment

12.1 Deployment considerations

This section frames the move from Streamlit Community Cloud for small projects to a more professional deployment approach for larger or higher-traffic apps.

Key terms: Streamlit Community Cloud, deployment, deployment alternatives

12.1.1 Why Streamlit Community Cloud may not work for some users

This section explains why Streamlit Community Cloud suits learning and lightweight apps but may be unsuitable when an app needs branding, capacity, availability, or server control.

Key terms: Streamlit Community Cloud, custom domain, resource limits, throttled, idle, high availability, free, Snowflake, deployment costs

12.1.2 Deployment alternatives

This section compares fully managed platforms, infrastructure-as-a-service, and platform-as-a-service options for deploying Streamlit apps, emphasizing their trade-offs and WebSocket support.

Key terms: fully managed platforms, infrastructure-as-a-service (IaaS), platform-as-a-service (PaaS), Render, Heroku, Streamlit in Snowflake, GitHub repository, scaling, WebSockets, Google App Engine (Flexible)

12.1.3 Our approach

This section justifies a learning-focused deployment path: containerize a Streamlit app with Docker, deploy it through AWS Elastic Beanstalk, and make it production-ready with a custom domain and HTTPS.

Key terms: Docker, AWS Elastic Beanstalk, custom domain, HTTPS, Render, Heroku, AWS, Elastic Beanstalk, reproducible image, dependencies

12.2 Packaging the app using Docker

This section introduces packaging a Streamlit app with Docker so it runs consistently locally and in cloud environments.

Key terms: Docker, portable, self-contained unit, cloud, local machine, container, Python, required libraries, app code, Dockerfile

12.2.1 Intro to Docker

This section introduces Docker as a way to package a Streamlit app and its environment consistently, and explains how to install Docker Desktop.

Key terms: Docker, consistent environment, dependencies, Python version, operating system, Dockerfile, Docker image, container, layers, Dockerfile instructions

12.2.2 The app in a container

This section explains the layered Docker environment in which a Streamlit app runs and how its container connects to the host through ports and mounted volumes.

Key terms: Docker container, Docker Engine, Docker Desktop, Linux kernel, Linux virtual machine, container, minimal Linux distribution, Python, Streamlit, dependencies

12.2.3 Creating a Dockerfile

This section builds a Dockerfile for a Streamlit app and explains how its instructions package the app, dependencies, network settings, and startup command into an image.

Key terms: Dockerfile, Docker image, Docker container, instruction, layer, layer caching, python:3.12-slim, base image, Docker Hub, WORKDIR

12.2.4 Excluding files from an image

This section prevents sensitive and unnecessary local files from being copied into a Docker image by configuring a .dockerignore file.

Key terms: secrets.toml, Docker image, image layers, COPY . ., .dockerignore, .gitignore, pattern matching, .streamlit/, Docker build process

12.2.5 Building an image and running a container

This section builds and runs the Fact Frenzy Docker image, connects its Streamlit port to the host, and supplies excluded secrets at runtime with a volume mount.

Key terms: Dockerfile, Docker image, Docker container, CMD, docker build, docker run, host machine, container machine, -p, port mapping

12.2.6 Adding a Docker Compose configuration

This section replaces repeated Docker build-and-run commands with a Docker Compose configuration that starts the Streamlit app with its required ports and secrets mount.

Key terms: Docker Compose, configuration manager, docker-compose.yml, YAML, service, fact-frenzy-app, build: ., ports, docker compose up, http://localhost:8502

12.3 Deploying to AWS Elastic Beanstalk

This section introduces deploying a Dockerized Streamlit app to AWS Elastic Beanstalk and previews the concepts and steps that make the deployment understandable.

Key terms: Dockerized app, AWS, AWS Elastic Beanstalk, Streamlit Community Cloud, Elastic Beanstalk, mental model, convenience, control

12.3.1 An overview of AWS

This section introduces AWS as an on-demand cloud platform, identifies the AWS services used for deployment and HTTPS, and motivates Elastic Beanstalk as a simpler alternative to assembling raw services yourself.

Key terms: Amazon Web Services, AWS, cloud computing platform, on demand, automatic scaling, EC2, Elastic Cloud Compute, S3, Simple Storage Service, IAM

12.3.2 Introducing Elastic Beanstalk

This section introduces AWS Elastic Beanstalk as a managed, Docker-friendly platform that deploys and operates a Streamlit app without requiring manual infrastructure setup.

Key terms: Elastic Beanstalk, AWS, underlying infrastructure, EC2 instances, load balancer, networking rules, monitoring, scaling, EC2, Docker

12.3.3 A mental model of the deployed app

This section establishes a mental model of how a Docker-packaged Streamlit app runs on AWS Elastic Beanstalk and how a browser request travels through its infrastructure.

Key terms: load balancer, EC2 instances, Docker container, Docker image, Streamlit app, port 80, port 443, HTTPS, Elastic Beanstalk, S3 storage

12.3.4 Creating and preparing an AWS account

This section prepares an AWS account for Elastic Beanstalk deployment by explaining AWS service permissions, creating command-line credentials, and assigning an EC2 instance role.

Key terms: AWS Management Console, free tier, Elastic Beanstalk, EC2, S3, Billing and Cost Management, permissions, health, IAM, IAM user

12.3.5 Modifying your app setup for Elastic Beanstalk

This section adapts a Dockerized Streamlit app for Elastic Beanstalk by provisioning secrets on the host, mounting them into the container, and keeping deployment secrets out of source control and images.

Key terms: .ebextensions, secrets_file.config, secrets.toml, Elastic Beanstalk, EC2 instance, /var/app/secrets/.streamlit/, content, 644, webapp, pipe (|)

12.3.6 Creating an Elastic Beanstalk app

This section walks through initializing an Elastic Beanstalk application with the EB CLI, creating and deploying an environment, and redeploying later code changes.

Key terms: EB CLI, eb init, AWS region, access key ID, secret access key, Elastic Beanstalk application, eb create, Elastic Beanstalk environment, DNS prefix, application load balancer

12.4 Adding a custom domain and HTTPS

This section introduces why a deployed Elastic Beanstalk app needs a custom domain and HTTPS before explaining how to add both.

Key terms: custom domain, Elastic Beanstalk URL, HTTP, HTTPS, encryption, certificate, load balancer

12.4.1 Adding a domain

This section explains why a custom domain is needed for practical HTTPS and how to register one and point its www address to an Elastic Beanstalk app through DNS.

Key terms: custom domain, HTTPS, SSL certificate, Certificate Authority, CA, Elastic Beanstalk domain, domain registrar, domain registration, DNS, DNS management dashboard

12.4.2 Creating a certificate

This section explains why HTTPS certificates are needed and shows how to request and validate an AWS ACM certificate for a custom domain.

Key terms: HTTP, HTTPS, digital certificate, man-in-the-middle attack, Certificate Authority (CA), AWS Certificate Manager (ACM), public certificate, Fully Qualified Domain Name, DNS validation, RSA 2048

12.4.3 Adding the certificate to your load balancer

This section attaches an ACM certificate to an Elastic Beanstalk load balancer so a custom-domain Streamlit app serves secure HTTPS traffic.

Key terms: load balancer, EC2 instances, HTTPS, encryption, Elastic Beanstalk, AWS Management Console, Configuration, Instance Traffic and Scaling, Listeners, port 443

12.5 Go forth and develop!

This concluding section frames Streamlit as a launchpad for building, sharing, and iterating on real Python web apps, while encouraging continued technical growth.

Key terms: Streamlit, pure-Python web apps, interactive applications, launchpad, internal tool, prototype, data dashboard, CRUD interface, trivia game, AI-powered support bot

12.6 Summary

This summary recaps deployment choices, Docker packaging, Elastic Beanstalk deployment, and custom-domain HTTPS for Streamlit apps.

Concepts explained in this chapter

← Chapter 11: Testing Streamlit apps

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.