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 32ed8c5 commit a239330
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 @@ -22,26 +21,8 @@ resource "aws_instance" "py_server" {
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
EOL
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
cd /home/ubuntu/app
nohup python3 app.py &
EOF

tags = {
Expand All @@ -62,13 +43,6 @@ 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 a239330

Please sign in to comment.