What is the best approach for having multiple instances in AWS running a custom Next.js app?

Viewed 36

I am running a Next.js app using the custom server options and the AWS CodePipeline for CI/CD.

My pipeline uses code build to build the app and AWS CodeDeploy to deploy to all instances within an autoscaling group. Configured with CodeDeployDefault.OneAtATime

I would like the cache and incrementally generated static pages to be shared between the ec2 instances.

Is there a way to do this and if so how would deployment of a new version to multiple instances work without affecting the shared files?

Stack:

  • EC2 Instances running AMAZON LINUX 2
  • Autoscaling group connected to an ELB
1 Answers

Please, consider using AWS EFS (Elastic File System) connected to all of your instances. It is a convenient solution for scenarios where application hosted on multiple machines needs access to the shared files. It works with machines operating under amazon linux. It means you next.js app on every instance will have access (read and write) to the same folder/files other instances have access to.

Google "mount EFS to instances" in order to find understandable and helpful guide.

Related