AWS Python Starter
A minimal AWS Python Pulumi program
Before you begin#
For this walkthrough, you'll need:
- The Pulumi CLI
- An AWS account with programmatic access
- The AWS CLI (optional, but recommended and used in this guide)
- Permission to manage resources in Amazon S3
Create a new project#
This starter creates an Amazon S3 bucket and exports the bucket’s name.
mkdir my-project; cd my-projectpulumi new aws-pythonmkdir my-project; cd my-projectpulumi new aws-pythonThe pulumi new command walks you through creating and configuring the new project and stack. A stack is an instance of a project, and you can have many of them (dev, staging, prod), each with its own configuration settings. Depending on the language, you may also be asked for your preferred package manager or toolchain.
This template also asks for the aws:region you’d like to deploy into:
| Key | Description | Default |
|---|---|---|
| aws:region | The AWS region to deploy into | us-east-1 |
pulumi config set
:
pulumi config set aws:region <value>pulumi config set aws:region "<value>"Review the code#
When setup completes, you’ll see a few files:
Pulumi.yamlcontains the project name and the language it’s written in.Pulumi.dev.yamlcontains thedevstack’s settings, including the values you just entered.__main__.pycontains the program code that declares your cloud resources.
Take a moment to open them up and have a look. Here’s what’s in __main__.py:
"""An AWS Python Pulumi program"""
import pulumifrom pulumi_aws import s3
# Create an AWS resource (S3 Bucket)bucket = s3.Bucket('my-bucket')
# Export the name of the bucketpulumi.export('bucket_name', bucket.id)Deploy the project#
Deploy with pulumi up. It starts with a preview of what it’s about to create and asks before it changes anything. Choose yes to deploy.
Pulumi adds a random suffix to most resource names, so my-bucket becomes something like my-bucket-4f8a2c1. This is autonaming. It lets you deploy the same program to more than one stack, and lets Pulumi create a replacement before it deletes the old resource, without names colliding.
pulumi uppulumi upWhen it finishes, Pulumi prints the stack’s outputs, values it only knows once the resources exist. This program exports the bucket’s name. Read it any time with pulumi stack output <name>, or pass it to another command. This one finds the bucket in your account and prints its name and creation date:
aws s3 ls | grep $(pulumi stack output bucket_name)aws s3 ls | Select-String $(pulumi stack output bucket_name)Need help?
If pulumi up reports No valid credential sources found or ExpiredToken, sign in again:
aws loginaws loginStill stuck? Let us know.
Customize the project#
Put a file in the bucket. In __main__.py, add this below the bucket:
s3.BucketObject( "hello", bucket=bucket.id, key="hello.txt", content="Hello, Pulumi!",)Deploy again. The preview shows one object to create:
pulumi uppulumi upThen read the file back from S3. It prints Hello, Pulumi!:
aws s3 cp "s3://$(pulumi stack output bucket_name)/hello.txt" -aws s3 cp "s3://$(pulumi stack output bucket_name)/hello.txt" -To see what else you can add, browse the AWS provider in the Pulumi Registry.
Cleaning up#
You can destroy the stack and all of its infrastructure with pulumi destroy, then remove the stack with pulumi stack rm:
pulumi destroypulumi stack rmpulumi destroypulumi stack rmRelated

Advanced AWS Networking: Part 1
