0.0.17 • Published 7 months ago

cdk-nextjs-standalone-ecs v0.0.17

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
7 months ago

Next.js Standalone ECS Site

WARNING

Leaving this here in case someone can use it as a jumping off point, but the copying method used breaks at scale. Ends up being a race between the first container and when the others start up, and they can break one another. Recommend a different strategy.

NPM Package

View on Construct Hub

Have a very simple use case for Next.js? Perhaps akin to what you would use a SPA (single page app) for? Check out cdk-nextjs-export-s3-dynamic-routing.

Deploy a Next.js site to AWS ECS supporting all version 13 features, including properly functioning, efficient Incremental Static Regeneration and Image Optimization.

This construct employs AWS EFS to share the .next directory between containers, as is recommended by Vercel.

Getting Started

A full example including custom domain, SSL, and Cloudfront is in the /example folder. This construct can also be used with only a VPC and ALB as well, with no caching or custom domain.

You can see the requirements for this construct there, but they are also spelled out in detail below.

The full API of this construct is available in the API.md file.

Requirements

next.config.?s

  • output must be set to standalone. This is what Vercel recommends for Docker based deployments.
  • experimental.isrMemoryCacheSize must be set to zero. Without this, you can get odd responses when using ISR and having multiple containers.

Scripts

Some minimal scripts that handle moving files around when a new build is created are required. They are available in the docker folder.

Dockerfile

The following should be inserted during the final steps, just after the standalone folder is copied.

# Additions from NextjsStandaloneEcsSite
# We use curl to run the health check on the container
RUN apk add --update curl
# Copy our scripts to the root of the container
COPY --from=builder --chown=nextjs:nodejs app/docker ./
# Move the build out of the way of our .next folder shared across containers
RUN mv ./.next ./.next.currentBuild
RUN mkdir -p ./.next
RUN chown nextjs:nodejs ./.next
# End additions from NextjsStandaloneEcsSite

In addition, the final line in the Dockerfile should be changed to:

ENTRYPOINT ["sh","./startup.sh"]

Instead of any CMD or existing ENTRYPOINT. You can add to startup.sh if you need to run additional commands before the container starts.

0.0.17

7 months ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago