Skip to content

Latest commit

 

History

History

complete

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Terraform Next.js complete example

Warning: This example is not fully updated for the upcoming v1.0.0 release.
We recommend following the Atomic Deployments Example instead until this example gets an update.

This example contains a fully featured Next.js app (Static files, API-Routes, SSR) that can be deployed using the Terraform Next.js for AWS module.

Notice: You can find the full example code on GitHub.

Setup

Download the files from the example app:

yarn create next-app --example https://github.com/milliHQ/terraform-aws-next-js/tree/main/examples/complete my-app

cd my-app

Build

Prepare the Next.js application to be deployed with Terraform:

yarn tf-next

Deploy

Use Terraform to deploy the Next.js app to your AWS account:

# Expose your AWS Access Keys to the current terminal session
# Only needed when running Terraform commands
export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

terraform init    # Only needed on the first time running Terraform

terraform plan    # (Optional) See what resources Terraform will create
terraform apply   # Deploy the Next.js app to your AWS account

After the deployment was successful, you should see the following output:

> Apply complete!
>
> Outputs:
>
> cloudfront_domain_name = "<distribution-id>.cloudfront.net"

You can now access your Next.js app in the browser under the https://<distribution-id>.cloudfront.net domain.