Skip to content

Commit

Permalink
changed flask run command
Browse files Browse the repository at this point in the history
  • Loading branch information
proquickly committed Nov 19, 2024
1 parent faf81be commit 32ed8c5
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ provider "aws" {
resource "aws_instance" "py_server" {
ami = "ami-06946f6c9b153d494"
instance_type = "t2.micro"
associate_public_ip_address = true # Add this line to get a public IP

user_data = <<-EOF
#!/bin/bash
Expand All @@ -21,8 +22,26 @@ resource "aws_instance" "py_server" {
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
EOL
cd /home/ubuntu/app
nohup python3 app.py &
chmod +x /home/ubuntu/app/app.py
# Create a systemd service file for the Flask app
cat <<EOL > /etc/systemd/system/flask-app.service
[Unit]
Description=Flask App
After=network.target
[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/app
ExecStart=/usr/bin/python3 app.py
Restart=always
[Install]
WantedBy=multi-user.target
EOL
# Enable and start the service
systemctl daemon-reload
systemctl enable flask-app
systemctl start flask-app
EOF

tags = {
Expand All @@ -43,6 +62,13 @@ resource "aws_security_group" "allow_http" {
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"] # Consider restricting to your IP
}

egress {
from_port = 0
to_port = 0
Expand Down

0 comments on commit 32ed8c5

Please sign in to comment.