eagle0504 commited on
Commit
b3b5f89
·
verified ·
1 Parent(s): c75ddbc

Create docs/deploy-st-on-aws-ec2.md

Browse files
Files changed (1) hide show
  1. docs/deploy-st-on-aws-ec2.md +112 -0
docs/deploy-st-on-aws-ec2.md ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deploying a Streamlit App on AWS EC2
2
+
3
+ This guide will walk you through the steps to deploy your Streamlit application on an AWS EC2 instance.
4
+
5
+ ## Prerequisites
6
+
7
+ 1. A Streamlit app designed and tested locally with the following structure:
8
+ - `requirements.txt`
9
+ - `app.py`
10
+ 2. An AWS account.
11
+
12
+ ## Steps to Deploy
13
+
14
+ ### 1. Launch an EC2 Instance
15
+
16
+ 1. Log in to your AWS account.
17
+ 2. Navigate to the EC2 Dashboard.
18
+ 3. Click on "Launch Instance."
19
+ 4. Name your instance `streamlit-test`.
20
+ 5. Choose an Amazon Machine Image (AMI). You can use the default Amazon Linux 2 AMI.
21
+ 6. Select an instance type (e.g., t2.micro for free tier eligibility).
22
+ 7. Configure the instance details as required.
23
+ 8. Add storage if necessary.
24
+ 9. Add tags if desired.
25
+ 10. Configure the security group:
26
+ - Click on "Add Rule."
27
+ - Set the "Type" to "Custom TCP."
28
+ - Set the "Port Range" to `8501` (Streamlit's default port).
29
+ - Set "Source" to `Anywhere` to allow access from any IP (or restrict to your IP for security).
30
+ - Click "Save rules."
31
+
32
+ ### 2. Create and Download the Key Pair
33
+
34
+ 1. When prompted, create a new key pair.
35
+ 2. Name the key pair `streamlit-test-key`.
36
+ 3. Download the `.pem` file and save it in a directory of your choice.
37
+
38
+ ### 3. Connect to the EC2 Instance
39
+
40
+ 1. In the EC2 Dashboard, go to "Instances."
41
+ 2. Click on the `Instance ID` of your newly created instance.
42
+ 3. Click on "Connect."
43
+ 4. Follow the instructions to connect using SSH. The command should look like this:
44
+
45
+ ```sh
46
+ ssh -i "streamlit-test-key.pem" ec2-user@<your-ec2-public-dns>
47
+ ```
48
+
49
+ Replace `<your-ec2-public-dns>` with your instance's public DNS.
50
+
51
+ ### 4. Copy Local Files to the EC2 Instance
52
+
53
+ 1. Open another terminal window.
54
+ 2. Navigate to the directory containing your `.pem` key file and Streamlit app.
55
+ 3. Use `scp` to copy your local files to the EC2 instance:
56
+
57
+ ```sh
58
+ scp -i "streamlit-test-key.pem" -r ./meta-llama3-full-stack/* ec2-user@<your-ec2-public-dns>:/home/ec2-user/
59
+ ```
60
+
61
+ Replace `<your-ec2-public-dns>` with your instance's public DNS.
62
+
63
+ ### 5. Set Up the EC2 Environment
64
+
65
+ 1. Once connected to the EC2 instance via SSH, create a virtual environment:
66
+
67
+ ```sh
68
+ python3 -m venv venv
69
+ source venv/bin/activate
70
+ ```
71
+
72
+ 2. Navigate to the project directory and install the required packages:
73
+
74
+ ```sh
75
+ cd /home/ec2-user/meta-llama3-full-stack
76
+ pip install -r requirements.txt
77
+ ```
78
+
79
+ ### 6. Run the Streamlit App
80
+
81
+ 1. For a temporary run, simply execute:
82
+
83
+ ```sh
84
+ streamlit run app.py
85
+ ```
86
+
87
+ 2. For a persistent run, use `nohup`:
88
+
89
+ ```sh
90
+ nohup streamlit run app.py &
91
+ ```
92
+
93
+ ### 7. Access the Streamlit App
94
+
95
+ 1. Open your web browser and navigate to:
96
+
97
+ ```sh
98
+ http://<your-ec2-public-dns>:8501
99
+ ```
100
+
101
+ Replace `<your-ec2-public-dns>` with your instance's public DNS.
102
+
103
+ ### Code Reference
104
+
105
+ The code for the Streamlit app can be found here: [Meta Llama 3 Full Stack](https://huggingface.co/spaces/eagle0504/meta-llama3-full-stack)
106
+
107
+ ### Notes
108
+
109
+ - Ensure that your security group rules are correctly configured to allow inbound traffic on port 8501.
110
+ - Keep your `.pem` file secure and do not share it.
111
+
112
+ Following these steps will help you successfully deploy your Streamlit app on an AWS EC2 instance.