Skip to main content

AWS StackReference architecture

This example lives in the pulumi/examples repository. Check out just this directory to use it:

Get started with this example
git clone --filter=blob:none --sparse https://github.com/pulumi/examples pulumi-examples
git -C pulumi-examples sparse-checkout set aws-ts-stackreference-architecture
cd pulumi-examples/aws-ts-stackreference-architecture

This will deploy a Data VPC and an application VPC that is peered. It will deploy an RDS Instance into the Data VPC and it will run a sample application in ECS that is fronted with an ALB.

This directory contains three Pulumi projects that must be deployed in the following order so that the correct data is shared between the layers:

  • networking/ — the data and application VPCs, peered together.
  • database/ — an RDS instance deployed into the data VPC.
  • application/ — a sample application running in ECS behind an ALB.

Prerequisites#

  1. Install Pulumi
  2. Configure AWS credentials
  3. Install Node.js

Deploying the example#

Networking#

  1. Change to the networking project:

    Terminal window
    cd networking
  2. Install dependencies:

    Terminal window
    npm install
  3. Create a new Pulumi stack named dev:

    Terminal window
    pulumi stack init dev
  4. Set the configuration variables for the project:

    Terminal window
    pulumi config set aws:region us-west-2

    If you wish to control the number of availability zones that the VPC will be created within, you can do this by setting:

    Terminal window
    pulumi config set azCount 3
  5. Deploy the networking stack:

    Terminal window
    pulumi up

Database#

  1. Change to the database project:

    Terminal window
    cd database
  2. Install dependencies:

    Terminal window
    npm install
  3. Create a new Pulumi stack named dev:

    Terminal window
    pulumi stack init dev
  4. Set the configuration variables for the project:

    Terminal window
    pulumi config set aws:region us-west-2
    pulumi config set dbUsername MyRootUser
    pulumi config set dbPassword --secret MyPassword1234!

    You need to set a stack reference to the networking stack so that the RDS Instance can be deployed into the correct VPC that was created in the networking stack. The stack needs to be in the form <organization_or_user>/<projectName>/<stackName> e.g. myUsername/multicloud/dev:

    Terminal window
    pulumi config set networkingStack stack72/networking-layer/dev

    If you wish to specify an initial database name in the RDS Instance, then you can do so by setting the following:

    Terminal window
    pulumi config set dbName myDatbaseName
  5. Deploy the database stack:

    Terminal window
    pulumi up

Application#

  1. Change to the application project:

    Terminal window
    cd application
  2. Install dependencies:

    Terminal window
    npm install
  3. Create a new Pulumi stack named dev:

    Terminal window
    pulumi stack init dev
  4. Set the configuration variables for the project:

    Terminal window
    pulumi config set aws:region us-west-2

    You need to set a stack reference to the networking stack so that the application can be deployed into the correct VPC that was created in the networking stack. The stack needs to be in the form <organization_or_user>/<projectName>/<stackName>:

    Terminal window
    pulumi config set networkingStack stack72/networking-layer/dev

    You need to set a stack reference to the database stack so that the Application Instance can get the correct credentials and database information for application startup. The stack needs to be in the form <organization_or_user>/<projectName>/<stackName>:

    Terminal window
    pulumi config set application-layer:databaseStack stack72/database-layer/dev
  5. Deploy the application stack:

    Terminal window
    pulumi up

You can then take the output albAddress and hit it with curl or in the browser to see the application running.

Cleaning up#

In each of the networking, database, and application directories, tear down the resources that are part of the stack and then remove the stack:

Terminal window
pulumi destroy
pulumi stack rm

Note: pulumi stack rm deletes all deployment history from the Pulumi Cloud and cannot be undone.

Related

The infrastructure as code platform for any cloud.