Skip to main content

Web server using Amazon EC2

Basic example of an AWS web server accessible over HTTP

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-webserver
cd pulumi-examples/aws-ts-webserver

This example deploys a simple AWS EC2 virtual machine running a Python web server.

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Node.js

Deploying the example#

  1. Create a new stack, which is an isolated deployment target for this example:

    Terminal window
    pulumi stack init
  2. Set the AWS region to deploy into:

    Terminal window
    pulumi config set aws:region us-east-1
  3. Install dependencies:

    Terminal window
    npm install
  4. Stand up the VM, which will also boot up your Python web server on port 80:

    Terminal window
    pulumi up
  5. After a couple minutes, your VM will be ready, and two stack outputs are printed:

    Terminal window
    pulumi stack output
    Current stack outputs (2):
    OUTPUT VALUE
    publicHostName ec2-53-40-227-82.compute-1.amazonaws.com
    publicIp 53.40.227.82
  6. Thanks to the security group making port 80 accessible to the 0.0.0.0/0 CIDR block (all addresses), we can curl it:

    Terminal window
    curl $(pulumi stack output publicIp)
    Hello, World!
  7. From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your VM.

Cleaning up#

Once you’re finished experimenting, destroy your stack and remove it:

Terminal window
pulumi destroy --yes
pulumi stack rm --yes

Related

The infrastructure as code platform for any cloud.