Git Product home page Git Product logo

nextjs-serverless-aws-cdk's Introduction

Welcome to the Cdk NextJs App Aws project

This is a cdk code to deploy a NextJS App on AWS.

NextJS-Serverless-AWSCDK

This project contains a configurable script that allows you to upload your open-next build to your AWS account using custom configurations.

The configurations are managed by the cdk.config.json file located inside the ./lib folder of this project. You will find an example file named cdk.config.example.json that demonstrates the file structure. To use it, rename it to cdk.config.json and make any necessary changes according to your needs.

The main node in the configuration file is the environment name, which is currently set to dev, stg, and prd but can be customized to your liking.

If you use different environment names, you will also need to modify the scripts located in the package.json file. The ENVIRONMENT variable is passed to the script from there.

To get started, you will need the following:

  • Your NextJS Project
  • One or multiple AWS accounts. You will need to bootstrap each account first.
  • Build your NextJS Project using the open-next project. This will create a folder called ./open-next under your root project folder.

Building your NextJS Project with open-next

Navigate to your NextJS project root folder and run the following command:

# Go to your NextJS project root folder and build with open-next

cd myNextJSProject

npx open-next@latest build

This will generate a new folder called .open-next containing the build files to be used in the next step. This uses the open-next project to create the build.

Finally deploy the build to your aws account

To deploy the build to your AWS account, follow these steps:

  1. Clone this repository and rename the cdk.config.example.json file to cdk.config.json.
  2. Edit the configuration file to match your AWS accounts and preferred environment.
  3. Ensure that you update the file paths for each node in the config for assets, and the three lambdas pointing to the .open-next folder created containing the build.
  4. Run the following command to deploy to the dev environment:
# This is an example to deploy to "dev" environment.

npm run cdk-deploy-dev --profile={yourAwsProfile to deploy}

This will create the lambdas, cloudfront configuration, s3 bucket behaviors, and route53 configuration.

Considerations

Please keep in mind the following considerations:

  • This cdk script will create the Route53 entry pointing to the recently created cloudfront distribution. If you have external DNS management, you will need to update this manually. If you don't have a zone already created and don't want this to execute, you will need to edit the nextJS-serverless-stack.ts file
  • You will need a SSL certificate Arn created on your aws account. Grab the Arn and edit the cdk.config.json file for each environment.
  • Add next.config.js image domains manually to lambda-functions.ts NEXT_IMAGE_ALLOWED_DOMAINS: "" under the environment node for the lambda. I will need to review this to automate the deploy. These are the domains allowed to be used by the Image Optimization function.

nextjs-serverless-aws-cdk's People

Contributors

martg0 avatar martingo78 avatar thersbach avatar

Stargazers

Vince Fulco--Bighire.tools avatar

Watchers

 avatar  avatar

Forkers

thersbach

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.