Setting
Official installation instructions can be easily found here https://www.pulumi.com/docs/get-started/install/
There are basically 2 main steps
download and install
1 2 | curl -fsSL https://get.pulumi.com | sh |
set env, here I use ubuntu
1 2 | export PATH="~/.pulumi/bin:$PATH" |
verified
done!
Instructions for creating an S3 bucket and deploying a static web to s3
This article is also sourced from the homepage https://www.pulumi.com/docs/get-started/aws/
- The first step is to configure the aws account
- If you don’t know this, you need to find out on google yourself, create an aws account to get access and fill in the secret key
1 2 3 | export AWS_ACCESS_KEY_ID=<YOUR_ACCESS_KEY_ID> export AWS_SECRET_ACCESS_KEY=<YOUR_SECRET_ACCESS_KEY> |
- new project:
1 2 3 | mkdir quickstart && cd quickstart && pulumi new aws-python pulumi new aws-python |
If you have a question, please fill it out
project name:
project description:
stack name: this I will explain later
Enter your passphrase to protect config/secrets: passphrase to secure your stack
aws:region: The AWS region to deploy into: us-east-1 (enter the aws region you want)
result:
requirements.txt => file containing details of packages with versions in the current python environment
folder evenv => this is the folder containing the files of python’s virtual environment
basically, we don’t need to care about these 2 files, pulumi will automatically manage these 2 files for us.
Pulumi.yaml: contains project information
Pulumi.dev.yaml: contains the newly initialized stack information
main.py program content
1 2 3 4 5 6 7 8 9 10 11 | """An AWS Python Pulumi program""" import pulumi from pulumi_aws import s3 # Tạo bucket s3 bucket = s3.Bucket('my-bucket') # export tên bucket là cái id pulumi.export('bucket_name', bucket.id) |
keep running
1 2 3 | pulumi login --local pulumi up |
choose yes
successful, let’s go to s3 and check
next create the file index.html
1 2 3 4 5 6 | <html> <body> <h1>Hello, Pulumi!</h1> </body> </html> |
then modify main.py
1 2 3 4 5 6 | bucketObject = s3.BucketObject( 'index.html', bucket=bucket.id, source=pulumi.FileAsset('index.html') ) |
keep running
1 2 | pulumi up |
successfully updated the index file to the bucket
So basically we know the steps to successfully create s3 bucket with Pulumi as well as update a file into that bucket.
After reading this, you will probably wonder many things like what is pulli login –local then what is stack and many other things, I will explain gradually in the following articles.