Deploying streamlit app to AWS beanstalk using docker

HI,

I have a stareamlit app, that I would like to deploy to AWS beanstalk using docker. I am able o run the docker image successfully on 0.0.0.0:500 using the command locally on my machine
docker run -p 80:8501 stapp:latest

But, when I try deploying it to AWS using elastic benstalk using the same dockerfile, the app open but it only shows connecting. Looks like its not able to connect. Can somebody help me in pointing out where i might be going wrong?

Here is my docker file,

FROM python:3.7-stretch

streamlit-specific commands

WORKDIR /src/

COPY . .

exposing default port for streamlit

EXPOSE 8501

copy over and install packages

COPY . .

RUN pip3 install -r requirements.txt

run app

CMD streamlit run app.py server=“0.0.0.0”

1 Like

Hi @Sharabh, thanks for your question! Did you configure Beanstalk for Websockets? This thread may help: https://stackoverflow.com/questions/27436110/websockets-with-aws-and-elastic-beanstalk/39604687

Best,
Matteo

@Sharabh did you get it working?

I’m in the same situation.

I’ve tried the advice in the post @monchier linked to (which helped me getting it working via the public IP address at least), but nothing I do makes it work with beanstalk’s URL.

Some things I’ve tried:

  • configure the EC2 Security group for TCP (this is what got it working with the public IP address)
  • this nginx upgrade for reverse proxy: https://stackoverflow.com/a/43796967/718139
  • change the load balancer protocol from HTTP to TCP (that’s with the “Classic Load Balancer”)
  • I also tried an “Application Load Balancer”

Presumably whatever wrong for me is related to what’s wrong in Working fine via public IP address, but problems with DNS. (Seems like just getting a DNS entry to work should be simpler than getting a load balancer to work, so I tried that but even had trouble there.)

Any help would be appreciated.

Hey @Sharabh,

The first thing that I would do is trying to disable CORS, as the App is working but not connecting to the server could be related to that.

The config option that you have to set up is server.enableCORS

1 Like

No, David, I am still in the same trouble. Although, I got it working on azure web apps service. But again, the app works fine for some time after I restart, but again it starts hanging up and connecting…

I have disabled cors, by adding a separate settings in a toml file

Hi @Sharabh,

Is the app not working at all for you on Beanstalk? Or, is it working via public IP but not via DNS?

It seems @dchudz was able to get his app fully working on Beanstalk by following Matteo’s comment, the steps he posted in his comment above and also by following the instructions in this comment.

When you said the following, were you talking about Azure or Beanstalk?

But again, the app works fine for some time after I restart, but again it starts hanging up and connecting

@Sharabh does it work for you eventually?

Hi all,
I was running into the same issue. I would suggest uploading a dockerrun.aws.json in the source code origin upload when creating the environment in beanstalk. I had to specify both containerport and Hostport as 8501. The dockerrun.aws.json file that worked for me was as follows:

{
  "AWSEBDockerrunVersion": "1",
  "Image": {
    "Name": "your image on the docker hub",
    "Update": "true"
  },
  "Ports": [
    {
      "ContainerPort": 8501,
      "HostPort": 8501
    }
  ],
  "Logging": "/var/log/nginx"
}