Git Product home page Git Product logo

martijnboers / terraform-aws-nextjs-serverless Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nexode-consulting/terraform-aws-nextjs-serverless

0.0 0.0 0.0 45.93 MB

Zero-Config Terraform Module to deploy Next.js Apps on AWS using Serverless solutions

Home Page: https://registry.terraform.io/modules/Nexode-Consulting/nextjs-serverless

License: Apache License 2.0

Shell 7.33% JavaScript 1.68% Go 14.03% TypeScript 26.93% HCL 50.03%

terraform-aws-nextjs-serverless's Introduction

Terraform Next.js module for AWS

Zero-Config Terraform Module to deploy Next.js Apps on AWS using Serverless solutions

Usage

Dependencies

  • Node: 16+
  • Terraform: 1.6.3+
  • bash
  • zip

Prepare

Add the following dependencies & script to your package.json file

package.json

{
  "scripts": {
    "build-serverless-next": "build-serverless-next",
    ...
  },
  "dependencies": {
    "build-serverless-next": "latest",
    "next": "^13",
    ...
  },
  ...
}

Add the output: "standalone" option to the next.config.js file

next.config.js

const nextConfig = {
  ...
  "output": "standalone",
  ...
}

module.exports = nextConfig

Create Terraform deployment

Check it on Terraform Registry for more details.

Ensure that the deployment name is unique since its used for creating s3 buckets.

main.tf

provider "aws" {
  region = "eu-central-1" #customize your region
}

provider "aws" {
  alias  = "global_region"
  region = "us-east-1" #must be us-east-1
}

module "next_serverless" {
  source  = "Nexode-Consulting/nextjs-serverless/aws"

  deployment_name = "nextjs-serverless" #needs to be unique since it will create s3 buckets
  region          = "eu-central-1" #customize your region
  base_dir        = "./" #The base directory of the next.js app
}

output "next_serverless" {
  value = module.next_serverless
}

Deployment

Build the Next.js Code and deploy

npm i build-serverless-next
npm run build-serverless-next

terraform init
terraform apply

Architecture

Module

Module

Distribution

Distribution

Cache

Cache

Examples

  • Next.js v13 Complete example with SSR, API, static pages, image optimization & custom domain

Known Issues

  • The build-serverless-next package's version must match the next_serverless module's version
  • The app/ folder must be in the root directory (ex. not in the src/ directory)
  • When destroying the next_serverless module, Lambda@Edge function need at least 15mins to be destroy, since they're replicated functions
  • Using the <img> tag or background-image css property will face issues rendering images, please use the build-in <Image /> component.

Contributing

Feel free to improve this module.
Our contributing guidelines will help you get started.

About

This module is maintained by Nexode Consulting.
We help companies develop and operate enterprise-grade software with startup momentum.

License

Apache-2.0 - see LICENSE for details.

terraform-aws-nextjs-serverless's People

Contributors

emyriounis avatar christophebeling avatar muratcanozdemir avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.