Skip to content

Commit 610f175

Browse files
authored
Add our AWS EC2 instance example in Go (pulumi#512)
This translates our existing AWS EC2 instance examples that we already have in JavaScript and Python to Go.
1 parent b44ff00 commit 610f175

File tree

5 files changed

+790
-0
lines changed

5 files changed

+790
-0
lines changed

aws-go-webserver/Pulumi.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
name: go-webserver
2+
runtime: go
3+
description: Basic example of an AWS web server accessible over HTTP
4+
template:
5+
config:
6+
aws:region:
7+
description: The AWS region to deploy into
8+
default: us-east-1

aws-go-webserver/README.md

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
[![Deploy](https://get.pulumi.com/new/button.svg)](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+
```

aws-go-webserver/go.mod

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/pulumi/examples/aws-go-webserver
2+
3+
go 1.13
4+
5+
require (
6+
github.com/pulumi/pulumi v1.8.1
7+
github.com/pulumi/pulumi-aws v1.17.0
8+
)

0 commit comments

Comments
 (0)