Created
November 21, 2025 06:10
-
-
Save ninejuan/a6041aa59bd2828277f53a7f69d5cb51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #cloud-config | |
| # ===== Basic system prep ===== | |
| # Enable systemd services to start after cloud-init | |
| # Update packages | |
| dnf -y update | |
| # Install Python 3 (AL2023 기본 포함이지만 확실히 설치) | |
| dnf -y install python3 | |
| # Create a simple webroot | |
| mkdir -p /var/www/simple | |
| cat > /var/www/simple/index.html << 'EOF' | |
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <title>Simple Python Server</title> | |
| </head> | |
| <body> | |
| <h1>Hello from Amazon Linux 2023!</h1> | |
| <p>This page is served by Python's built-in HTTP server.</p> | |
| </body> | |
| </html> | |
| EOF | |
| # Create systemd service for the Python HTTP server | |
| cat > /etc/systemd/system/simple-python-server.service << 'EOF' | |
| [Unit] | |
| Description=Simple Python HTTP Server | |
| After=network.target | |
| [Service] | |
| Type=simple | |
| User=nobody | |
| Group=nobody | |
| WorkingDirectory=/var/www/simple | |
| # Serve the current directory on port 8000 | |
| ExecStart=/usr/bin/python3 -m http.server 8000 | |
| Restart=always | |
| RestartSec=2 | |
| StandardOutput=append:/var/log/simple-python-server.log | |
| StandardError=append:/var/log/simple-python-server.log | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOF | |
| # Reload systemd and enable + start the service | |
| systemctl daemon-reload | |
| systemctl enable simple-python-server.service | |
| systemctl start simple-python-server.service | |
| # Optional: open firewall (AL2023 typically has no firewall by default; security group must allow 8000) | |
| # If using firewalld, uncomment: | |
| # dnf -y install firewalld | |
| # systemctl enable --now firewalld | |
| # firewall-cmd --permanent --add-port=8000/tcp | |
| # firewall-cmd --reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment