Tutorial Launch Saleable Streamlit dashboards @ AWS — part 3

You are here completely right for deploy a professional streamlit/python solution launched at AWS.

M. the German Engineer
7 min readDec 14, 2021

So this is part 3 of my tutorial for creating a professional solution using streamlit as web service for a customer. In part 1 + part 2 we connect the streamlit for files in AWS S3 and uploaded a container to AWS ECS.

Overview of the tutorial parts:
- introduction of this tutorial (part 0)
- using a file in streamlit saved in AWS and upload a new one (part 1)
- make a docker container and uploading to AWS ECS (part 2)
- launching this container as a fargate service (part 3)
- connecting the service to your Route53 hosted zone (part 4)
- integrating authentication with Cognito (part 5)
- bonus session: using the streamlit upload button for saving files at AWS S3 — after 100 claps
- bonus session: integrate prophet in streamlit and host it — after 200 claps

- integrating authentication with Cognito (part 5) — not published
- bonus session: using the streamlit upload button for saving files at AWS S3 — after 100 claps
- bonus session: integrate prophet in streamlit and host it — after 200 claps

What we want to do here?

We now start the container as a web service at AWS and make it available for public. Later in part 4,5 we want to integrate authentication.

Create a cluster for your container

In part 2 the last step was “pushing the container” to AWS. So we will start here at the last screen of part 2.

Now click on “Cluster” and “Create Cluster”

In the next steps we will create a Cluster and the setup process is very lean. We will choose “Networking only” and “Next step”

In the next screen we give the cluster a name and checking the “VPC”. With this you create a virtual private cloud in this cluster for secure connection in this cluster. After this “Create” and it will take 5 minutes for creating your new cluster.

If it is finished click on “View Cluster” and you will see your empty cluster

Task Definition

The next step we have to create a task. So click on “Task Definition” and “Create new Task Definition”

Here we choose “Fargate” as a cost-optimal solution

Give your task a name and choose the IAM standard role.

After this scroll down to “Container” and click on “Add container”

Here you have to insert some informations of our uploaded container — perhaps open a new tab to have a look at the ECR.

Set the port of 8501 for the streamlit app. Everything else are lot of options we don’t need in the moment. After clicking “Add” you will returned to the task screen and have to add a CPU/memory.

After this click on “Create” and in the next screen “View task definition” and after this on the left hand side “Task definitions” — Vola we defined a cluster and task definition.

Create a service

Now we have to define in your cluster a new service for running the task defintion. So click on Clusters -> samplecluster -> and “Create”

Here to select “Fargate” and as Task Definition your task “sampletask”. Give the service a name and insert how many tasks you need. Then click on “next step”.

In this step we will choose the VPC we created before and the two subnets. Then we have to define a security group so click on “Edit”

Here you give the security group a name and allow the streamlit port 8501. After this click save.

Now scroll down and select “Application Load Balancer”. After this a red box should appear and you click on “EC2 console” for creating it.

Here we have to select “Application Load Balancer” again

Next we give the load balancer a name and select your VPCs and check the subnets

Scrolling down we have to define a new security group for the load balancer by click on it. In this screen we define the new security group, a descripion, choose our VPCs and add an Inbound rule and click on “create security group”.

Then go back to the screen of “creating a load balancer”, click on refresh at the security group and choose the new one.

After the security group we need a target group. So click on “Create a target group”

Here you have to choose “IP” and add the streamlit port 8501 — everything elese is fine so click on “Next”.

In the “Register Target group” everything is ok for the moment and we click on “Create target group”. After this go back to the “Creating load balancer”-screen, click on the refresh button and add you target group

Final click on “Create load balancer” and go back to your “Create service” screen and update here the load balancer and add your container

Here you have to choose HTTP and your target group again and “Next”

In the following Auto-Scaling we click “Next Step” and “Create Service” and “View Service”.

Now you see your service and a task with status “pending” and some minutes later “running”.

Click on your Task and Logs and you see Streamlit is running! Here you see a external URL typing in the browser it works! We see our streamlit app as web service!

WOW — what we have done here?

We started with a container at AWS and create a web service with AWS fargate. So we can share our streamlit app with the world and exchange a input file with AWS S3 without modification of the container!

What’s next?

So sharing a IP-adress isn’t a professional solution and we want to connect it to our domain. And we need professional authentication that the customer data keeps secret. So follow me, share it and enjoy the next part!

Overview of the tutorial parts:
- introduction of this tutorial (part 0)
- using a file in streamlit saved in AWS and upload a new one (part 1)
- make a docker container and uploading to AWS ECS (part 2)
- launching this container as a fargate service (part 3)
- connecting the service to your Route53 hosted zone (part 4)
- integrating authentication with Cognito (part 5)
- bonus session: using the streamlit upload button for saving files at AWS S3 — after 100 claps
- bonus session: integrate prophet in streamlit and host it — after 200 claps

--

--

M. the German Engineer

Mechanical engineer, Future worker, Data scientist, Project manager, Systems engineer