|
| 1 | +[](https://app.pulumi.com/new) |
| 2 | + |
| 3 | +# Web Server Using Amazon EC2 (in Go) |
| 4 | + |
| 5 | +This example deploys a simple AWS EC2 virtual machine running a Python web server. It uses Go as its infrastructure as |
| 6 | +code language. |
| 7 | + |
| 8 | +## Deploying the App |
| 9 | + |
| 10 | +To deploy your infrastructure, follow the below steps. |
| 11 | + |
| 12 | +### Prerequisites |
| 13 | + |
| 14 | +1. [Install Go](https://golang.org/doc/install) |
| 15 | +2. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/) |
| 16 | +3. [Configure AWS Credentials](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/) |
| 17 | + |
| 18 | +### Steps |
| 19 | + |
| 20 | +After cloning this repo, from this working directory, run these commands: |
| 21 | + |
| 22 | +1. Go is a compiled language, so you must first compile it: |
| 23 | + |
| 24 | + ```bash |
| 25 | + $ go build -o go-webserver |
| 26 | + ``` |
| 27 | + |
| 28 | +2. Next, create a new Pulumi stack, which is an isolated deployment target for this example: |
| 29 | + |
| 30 | + ```bash |
| 31 | + $ pulumi stack init |
| 32 | + ``` |
| 33 | + |
| 34 | +3. Set the required configuration variables for this program: |
| 35 | + |
| 36 | + ```bash |
| 37 | + $ pulumi config set aws:region us-east-1 |
| 38 | + ``` |
| 39 | + |
| 40 | +4. Stand up the VM, which will also boot up your Python web server on port 80: |
| 41 | + |
| 42 | + ```bash |
| 43 | + $ pulumi up |
| 44 | + ``` |
| 45 | + |
| 46 | +5. After a couple minutes, your VM will be ready, and two stack outputs are printed: |
| 47 | + |
| 48 | + ```bash |
| 49 | + $ pulumi stack output |
| 50 | + Current stack outputs (2): |
| 51 | + OUTPUT VALUE |
| 52 | + publicIp 53.40.227.82 |
| 53 | + ``` |
| 54 | + |
| 55 | +6. Thanks to the security group making port 80 accessible to the 0.0.0.0/0 CIDR block, we can curl it: |
| 56 | + |
| 57 | + ```bash |
| 58 | + $ curl $(pulumi stack output publicIp) |
| 59 | + Hello, World! |
| 60 | + ``` |
| 61 | + |
| 62 | +7. From there, feel free to experiment. Simply making edits and running `pulumi up` will incrementally update your VM. |
| 63 | + |
| 64 | +8. Afterwards, destroy your stack and remove it: |
| 65 | + |
| 66 | + ```bash |
| 67 | + $ pulumi destroy --yes |
| 68 | + $ pulumi stack rm --yes |
| 69 | + ``` |
0 commit comments