Skip to main content

Search the Dev Center

Search tutorials, templates, examples, and more.

Next.js on AWS

A Next.js site deployed on AWS using OpenNext

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-nextjs
cd pulumi-examples/aws-ts-nextjs

This example deploys a Next.js site on AWS using OpenNext.

Prerequisites#

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

Deploying the example#

  1. Create a new stack, which is an isolated deployment target for this example:

    Terminal window
    pulumi stack init
  2. Set the AWS region to deploy into:

    Terminal window
    pulumi config set aws:region us-west-2
  3. Install dependencies:

    Terminal window
    npm install
  4. Deploy the stack:

    Terminal window
    pulumi up

    Most of the infrastructure will deploy within about 30s, but the CloudFront CDN can take 4-5 minutes. After this is complete, a CloudFront URL where your application is served will be shown.

    Outputs:
    url: "https://d119mwdwutz4hu.cloudfront.net"
    Resources:
    + 45 created
    Duration: 4m14s
  5. Open that URL in your browser to see your Next.js demo app.

    Screenshot of demo app

  6. Make changes to the Next.js app in the demoapp folder, or bring your own Next.js app and point the Pulumi component at it instead.

Cleaning up#

Once you’ve finished experimenting, tear down your stack’s resources by destroying and removing it:

Terminal window
pulumi destroy
pulumi stack rm

Related

The infrastructure as code platform for any cloud.