This repository contains a project using Pulumi to build and deploy cloud applications and infrastructure (Infra-as-Code).
This project deploys a simple AWS EC2 VM running a Python web server.
To deploy your infrastructure, follow the below steps.
Install Pulumi
After installing Pulumi, since we're using TypeScript, switch to Node.js 12.x LTS and verify pulumi CLI.
nvm use lts/*
pulumi version
Configure AWS Credentials
vim ~/.aws/config
# Set AWS region for this profile, which is ap-northeast-2
export AWS_PROFILE=pel
After cloning this repo, from this working directory, run these commands:
- Set the required configuration variables for this program:
$ pulumi config set aws:region ap-northeast-2
- Stand up the VM, which will also boot up your Python web server on port 80:
$ pulumi up
- After a couple minutes, your VM will be ready, and two stack outputs are printed:
$ pulumi stack output
Current stack outputs (2):
OUTPUT VALUE
publicIp NN.NN.NNN.NN
- Thanks to the security group making port 80 accessible to the 0.0.0.0/0 CIDR block, we can curl it:
$ curl $(pulumi stack output publicIp)
Hello, World!
-
From there, feel free to experiment. Simply making edits and running pulumi up will incrementally update your VM.
-
If you need to connect to the VM remotely using SSH, add SSH key into instance.
Go to AWS Console and "Connect" to the instance. Pick "EC2 Instance Connect (browser-based SSH connection)". Once you're in, do:
# Follow guide: https://stackoverflow.com/questions/3260739/add-keypair-to-existing-ec2-instance
ubuntu@ip-1-1:~$ sudo adduser pel
New password: *****************
$ ssh-keygen -t rsa -b 4096 -C "pel@protodev"
- Afterwards, destroy your stack and remove it:
$ pulumi destroy --yes
$ pulumi stack rm --yes