Skip to main content

PERN stack voting app

Voting app that uses containers

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-pern-voting-app
cd pulumi-examples/aws-ts-pern-voting-app

A simple voting app that uses React, Express, PostgreSQL, and NodeJS.

The example shows how easy it is to deploy containers into production and to connect them to one another. Since the example defines a custom container, Pulumi does the following:

  • Builds the Docker image
  • Provisions AWS Container Registry (ECR) instance
  • Pushes the image to the ECR instance
  • Creates a new ECS task definition, pointing to the ECR image definition

Prerequisites#

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

Deploying the example#

  1. Create a new stack:

    Terminal window
    pulumi stack init aws-ts-pern-voting-app
  2. Set the AWS region and the usernames and passwords for a set of accounts the project uses. The user names must be valid PostgreSQL identifiers, and the passwords must satisfy the RDS master password rules (8-128 printable ASCII characters, excluding /, ", @, and spaces).

    Terminal window
    pulumi config set aws:region us-west-2
    pulumi config set sql-admin-name <NAME>
    pulumi config set sql-admin-password <PASSWORD> --secret
    pulumi config set sql-user-name <NAME>
    pulumi config set sql-user-password <PASSWORD> --secret
  3. Install dependencies:

    Terminal window
    npm install
  4. Deploy the stack:

    Terminal window
    pulumi up
    Updating (aws-ts-pern-voting-app):
    Type Name Status Info
    + pulumi:pulumi:Stack voting-app-aws-ts-pern-voting-app created
    + ├─ awsx:x:ecs:FargateTaskDefinition server-side-service created
    ...
    + └─ pulumi-nodejs:dynamic:Resource postgresql-votes-schema created
    Outputs:
    URL: "client-side-listener-086d27d-bb5f264d141c31b7.elb.us-west-2.amazonaws.com"
    Resources:
    + 63 created
    Duration: 4m2s
  5. View the DNS address of the instance via pulumi stack output:

    Terminal window
    pulumi stack output
    Current stack outputs (1):
    OUTPUT VALUE
    URL client-side-listener-086d27d-bb5f264d141c31b7.elb.us-west-2.amazonaws.com
  6. Verify that the ECS instance exists by connecting to it in a browser window.

Cleaning up#

To clean up resources, run pulumi destroy and answer the confirmation question at the prompt, then remove the stack:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.