Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

AWS TypeScript Starter

A minimal AWS TypeScript Pulumi program

Before you begin#

For this walkthrough, you'll need:

Create a new project#

This starter creates an Amazon S3 bucket and exports the bucket’s name.

Terminal window
mkdir my-project; cd my-project
pulumi new aws-typescript

The 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:

KeyDescriptionDefault
aws:regionThe AWS region to deploy intous-east-1
You can change values like these later with pulumi config set :
Terminal window
pulumi config set aws:region <value>

Review the code#

When setup completes, you’ll see a few files:

  • Pulumi.yaml contains the project name and the language it’s written in.
  • Pulumi.dev.yaml contains the dev stack’s settings, including the values you just entered.
  • index.ts contains the program code that declares your cloud resources.

Take a moment to open them up and have a look. Here’s what’s in index.ts:

index.ts
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create an AWS resource (S3 Bucket)
const bucket = new aws.s3.Bucket("my-bucket");
// Export the name of the bucket
export const bucketName = 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.

Terminal window
pulumi up

When 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:

Terminal window
aws s3 ls | grep $(pulumi stack output bucketName)
Need help?

If pulumi up reports No valid credential sources found or ExpiredToken, sign in again:

Terminal window
aws login

Still stuck? Let us know.

Customize the project#

Put a file in the bucket. In index.ts, add this below the bucket:

new aws.s3.BucketObject("hello", {
bucket: bucket.id,
key: "hello.txt",
content: "Hello, Pulumi!",
});

Deploy again. The preview shows one object to create:

Terminal window
pulumi up

Then read the file back from S3. It prints Hello, Pulumi!:

Terminal window
aws s3 cp "s3://$(pulumi stack output bucketName)/hello.txt" -

To see what else you can add, browse the AWS provider in the Pulumi Registry.

Cleaning up#

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure platform for humans and agents.