The Challenge
You need a simple web server running on EC2 for development, testing, or hosting a basic website. This is the most straightforward way to get a web server running on AWS without external dependencies or container tooling.
What You'll Build
- → EC2 instance running Amazon Linux 2023
- → Security group allowing inbound HTTP traffic
- → Python HTTP server serving on port 80
- → Public IP and DNS hostname exported for access
Try This Prompt in Pulumi Neo
Run this prompt in Neo to deploy your infrastructure, or edit it to customize.
Best For
Architecture Overview
This deployment creates a minimal web server on AWS using a single EC2 instance. The architecture has three components: an AMI lookup to find the latest Amazon Linux 2023 image, a security group that controls network access, and the EC2 instance itself with a user data script that starts a web server at boot.
The AMI lookup ensures you always deploy on the latest version of Amazon Linux 2023 without hardcoding an image ID that would become outdated or fail in different regions. The security group acts as a virtual firewall, allowing inbound HTTP traffic on port 80 while blocking everything else. This is the minimum network configuration needed for a public-facing web server.
The user data script runs at instance launch and handles all server setup. It creates an HTML file and starts Python’s built-in HTTP server to serve it on port 80. Python comes pre-installed on Amazon Linux, so there are no additional packages to install. This approach is intentionally simple and works well for demos and testing, though production workloads would typically use nginx or a similar server.
AMI Lookup
Rather than hardcoding an AMI ID (which varies by region and becomes outdated), the deployment uses the EC2 AMI lookup feature to find the latest Amazon Linux 2023 image for x86_64 architecture. This makes the deployment portable across AWS regions and ensures you always start with a patched, current image.
Security Group
The security group defines inbound rules that allow TCP traffic on port 80 from any source. This is the equivalent of a firewall rule that permits HTTP access from the internet. Outbound traffic is allowed by default, which the instance needs to download packages or reach other AWS services. You can tighten these rules for production use.
EC2 Instance and User Data
The t2.micro instance is eligible for the AWS Free Tier, making this deployment nearly free for experimentation. The user data script is a shell script that runs once at first boot, creating the HTML content and starting the Python HTTP server. The instance receives a public IP address and DNS hostname, both of which are exported as stack outputs so you know where to access the server.
Common Customizations
- Switch to nginx: Replace the Python HTTP server with nginx for better performance, static file serving, and reverse proxy capabilities needed in production.
- Add SSH access: Extend the security group to allow TCP port 22 and provide an SSH key pair so you can log into the instance for debugging or manual configuration.
- Use an Elastic IP: Assign an Elastic IP address so the public IP persists across instance stop/start cycles, which is important if other services reference the IP.
- Increase instance size: Move to a larger instance type (t3.small, t3.medium) for workloads that need more CPU or memory than t2.micro provides.
Related Prompts
Deploy a Basic Web Server
You need a simple web server to host a website or test an application. This deployment introduces the core building …
Deploy a Static Website
You need a fast, secure way to serve a static website globally. Whether it is a marketing site, documentation portal, or …
Build a Security and Compliance Stack
You need infrastructure that meets security and compliance requirements from day one. Rather than retrofitting security …
Deploy a Multi-Cloud Application
You need to run an application across multiple cloud providers so that a regional outage or provider-level incident does …