Skip to content

Commit

Permalink
Add our AWS EC2 instance example in Go (pulumi#512)
Browse files Browse the repository at this point in the history
This translates our existing AWS EC2 instance examples that we already
have in JavaScript and Python to Go.
  • Loading branch information
joeduffy authored Jan 9, 2020
1 parent b44ff00 commit 610f175
Show file tree
Hide file tree
Showing 5 changed files with 790 additions and 0 deletions.
8 changes: 8 additions & 0 deletions aws-go-webserver/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: go-webserver
runtime: go
description: Basic example of an AWS web server accessible over HTTP
template:
config:
aws:region:
description: The AWS region to deploy into
default: us-east-1
69 changes: 69 additions & 0 deletions aws-go-webserver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
[![Deploy](https://get.pulumi.com/new/button.svg)](https://app.pulumi.com/new)

# Web Server Using Amazon EC2 (in Go)

This example deploys a simple AWS EC2 virtual machine running a Python web server. It uses Go as its infrastructure as
code language.

## Deploying the App

To deploy your infrastructure, follow the below steps.

### Prerequisites

1. [Install Go](https://golang.org/doc/install)
2. [Install Pulumi](https://www.pulumi.com/docs/get-started/install/)
3. [Configure AWS Credentials](https://www.pulumi.com/docs/intro/cloud-providers/aws/setup/)

### Steps

After cloning this repo, from this working directory, run these commands:

1. Go is a compiled language, so you must first compile it:

```bash
$ go build -o go-webserver
```

2. Next, create a new Pulumi stack, which is an isolated deployment target for this example:

```bash
$ pulumi stack init
```

3. Set the required configuration variables for this program:

```bash
$ pulumi config set aws:region us-east-1
```

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

```bash
$ pulumi up
```

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

```bash
$ pulumi stack output
Current stack outputs (2):
OUTPUT VALUE
publicIp 53.40.227.82
```

6. Thanks to the security group making port 80 accessible to the 0.0.0.0/0 CIDR block, we can curl it:

```bash
$ 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.

8. Afterwards, destroy your stack and remove it:

```bash
$ pulumi destroy --yes
$ pulumi stack rm --yes
```
8 changes: 8 additions & 0 deletions aws-go-webserver/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/pulumi/examples/aws-go-webserver

go 1.13

require (
github.com/pulumi/pulumi v1.8.1
github.com/pulumi/pulumi-aws v1.17.0
)
Loading

0 comments on commit 610f175

Please sign in to comment.