- Go Monk
- Posts
- Pulumi and AWS - Intro
Pulumi and AWS - Intro
Deploying a static website into S3 bucket
Pulumi is an Infrastructure as Code (IaC) tool, similar to Terraform. The key difference is that Pulumi lets you define infrastructure using a general-purpose programming language instead of a domain-specific language like HCL.
In this post, I’ll deploy a simple web page to an AWS S3 bucket using Pulumi with Go. The steps are based on the Pulumi Get Started guide — refer to it for more detailed explanations.
1) Creating the S3 Bucket
Create a new Pulumi project:
$ mkdir 1
$ cd 1
$ pulumi new aws-go
This sets up a few starter files:
$ tree
.
├── go.mod
├── go.sum
├── main.go # the real deal
├── Pulumi.dev.yaml # stack configuration (e.g., environment-specific settings)
├── Pulumi.yaml # project metadata (e.g., name and runtime)
└── README.md # I deleted this file
Deploy and verify the bucket:
$ pulumi up # you’ll get a chance to review and confirm
$ aws s3 ls s3://$(pulumi stack output bucketName)
2) Adding the Web Page
To keep things clean, I duplicate the project so I can diff
the changes:
$ cd ..
$ cp -r 1 2
$ cd 2
To convert your bucket into a static website, add three new AWS S3 resources to main.go
:
BucketWebsiteConfigurationV2
: configures the bucket as a websiteBucketOwnershipControls
: manages ownership settingsBucketPublicAccessBlock
: allows public access (disabled by default for safety)
Then, create an index.html
file — this will be your web page.
In main.go
, add a BucketObject
right after the bucket creation. This uploads the index.html
file using a Pulumi concept called an asset. It also uses DependsOn
to wait for two of the previously created resources.
Finally, export the url
instead of the bucketName
.
Deploy the changes and test the web page:
$ pulumi up
$ curl $(pulumi stack output url)
Cleanup
$ pulumi destroy
$ pulumi stack rm dev