A First Look at Pulumi
Published:
Pulumi provides open source infrastructure as code SDKs for creating, deploying, and managing infrastructure on multiple clouds in multiple languages.
Outline
All of this project’s code can be found in the First Look monorepo on my GitHub.
Introduction
Pulumi provides open source infrastructure as code SDKs that enable you to create, deploy, and manage infrastructure on numerous popular clouds in multiple programming languages.
Setup
In this tutorial, we’ll show you how to write a Pulumi program that creates a serverless app serving static content with dynamic routes in AWS Lambda.
Install Pulumi CLI
Instructions for downloading the CLI will vary depending on your operating system. This tutorial will use Homebrew on MacOS.
Subsequent updates can be installed with brew upgrade
.
Configure AWS Credentials
Make sure you have the AWS CLI installed and an AWS account. For general use, aws configure
is recommended as the fastest way to set up your AWS CLI installation.
When you enter this command, the AWS CLI prompts you for four pieces of information:
- Access key ID
- Secret access key
- AWS Region
- Output format
Go to My Security Credentials to find your Access Key ID, Secret Access Key, and default region. You can leave the output format blank.
Login to Pulumi
You will be asked to hit <ENTER>
to log in with your browser.
Create a New Pulumi Project
We’ll use the pulumi new command and generate a new project with the hello-aws-javascript
template. It will be named ajcwebdev-pulumi
with the --name
flag.
You will be asked to provide a description, stack name, and AWS region. I selected the default option for each.
Pulumi Yaml Files
A Pulumi project is any folder which contains a Pulumi.yaml
file specifying metadata about your project. The project file must begin with a capitalized P and can use either .yml
or .yaml
extensions.
The key-value pairs for any given stack are stored in your project’s stack settings file, which is automatically named Pulumi.<stack-name>.yaml
.
Index File
Import the pulumi/aws package. Create a public HTTP endpoint using AWS API Gateway that serves static files from the www
folder using AWS S3 with a REST API served on GET /name
with AWS Lambda. Finally, export the public URL for the HTTP service with exports.url = endpoint.url
.
HTML Index File
The project comes with a hello world example in the index.html
file.
Deploy to Pulumi Cloud
Create or update the resources in a stack with pulumi up
.
Select yes.
Open the output’s URL, (2inuue6w0a.execute-api.us-west-1.amazonaws.com/stage/
in my case) to see your site.
Update HTML File
Change stuff.
Run pulumi up
again to deploy your changes.
Check back to your URL.