Web server using Amazon EC2 (in Go)
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:
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examplesgit -C pulumi-examples sparse-checkout set aws-go-webservercd pulumi-examples/aws-go-webserverThis example deploys a simple AWS EC2 virtual machine running a Python web server. It uses Go as its infrastructure as code language.
Prerequisites#
Deploying the example#
-
Create a new stack, which is an isolated deployment target for this example:
Terminal window pulumi stack init dev -
Set the AWS region to deploy into:
Terminal window pulumi config set aws:region us-east-1 -
Install dependencies:
Terminal window go mod download -
Stand up the VM, which will also boot up your Python web server on port 80:
Terminal window pulumi up -
After a couple minutes, your VM will be ready, and the stack outputs are printed:
Terminal window pulumi stack outputCurrent stack outputs (2):OUTPUT VALUEpublicIp 53.40.227.82 -
Thanks to the security group making port 80 accessible to the 0.0.0.0/0 CIDR block, we can curl it:
Terminal window curl $(pulumi stack output publicIp)Hello, World! -
From there, feel free to experiment. Simply making edits and running
pulumi upwill incrementally update your VM.
Cleaning up#
Once you’re finished experimenting, you can destroy your stack and remove it to avoid incurring any additional cost:
pulumi destroypulumi stack rm