1.2 Configuring AWS

Now that we have a basic project, let’s add the Pulumi AWS provider and configure our credentials.

Step 1 — Install the AWS Provider

Run the following command:

npm i @pulumi/aws

This will install the Pulumi AWS node SDK and add it to your package.json file. This is the library that will allow us to manage AWS assets with Pulumi. Pulumi also supports a wide range of other providers. For a complete list of all supported providers, see the Pulumi Registry.

Step 2 — Import the AWS Provider

Now that the AWS package is installed, we need to import it as part of our project.

Add the following to the top of your index.ts:

import * as aws from "@pulumi/aws";

After this change, your index.ts should look like this:

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

Step 3 — Configure an AWS Region

Configure the AWS region you would like to deploy to, replacing us-east-1 with your AWS region of choice:

pulumi config set aws:region us-east-1

Setting the AWS region is not strictly necessary, but we do it here to demonstrate how to set stack configuration values. If you do not set the region, Pulumi will use the default region for your AWS profile.

Note that the previous command will create the file Pulumi.dev.yaml which contains the configuration for our dev stack. (Stacks are logical groupings of Pulumi resources.) We will be working with a single Pulumi stack in this tutorial, but we could define additional stacks to deploy our infrastructure to different regions/accounts with different parameters. To learn more about Pulumi stacks, see Stacks in the Pulumi docs.

(Optional) Step 4 — Configure an AWS Profile

If you are using an AWS profile other than the default, you can tell Pulumi which to use in one of two ways:

  • Using an environment variable: export AWS_PROFILE=<profile name>
  • Using configuration: pulumi config set aws:profile <profile name>