- Create dockerized NextJS app - previous part
- Manual upload
- Beanstalk CLI
- Add custom domain - next part
- Set up redirects - part 4
In previous part we created dockerized NextJS app. Now it's time to deploy.
Everything in here is within AWS Free tier.
Also please pay attention that all links to AWS I provide use my region of choice, if you're using different AWS region make sure to change it before making any changes!
There are two ways to deploy our app to Beanstalk:
- Manual upload to Beanstalk
- Beanstalk CLI
In your project folder delete
node_modules directory (and
.next if present), archive leftovers into zip archive. Switch to AWS Console.
If you don't have a Beanstalk application, we need to create one:
- Open AWS Console Beanstalk welcome page
- Fill in application name and select platform
Create application. It will take a few minutes to deploy our app.
If you already have a Beanstalk application, we need to create a new application for our NextJS app (skip to create new environment if you want to use existing Beanstalk application):
- In EB Console jump to
Applicationstab in the sidebar
Create new application
- Fill in application name and click
- Open created application (if you was following previous step, you already there)
Create a new environment
Select environment tierstep leave defaults (
Web server environment) and click
Dockerplatform and upload your zip archive
After it's done you'll be provided with a URL for your application.
To update application, open environment in EB console and click
Upload and deploy
First you need to install EB CLI.
Follow instructions there to install it using script.
If for some reason it's not working (i.e. you're using Arch linux), follow the procedures there.
After it's installed and checked to work, we need to initialize our app:
eb init -r eu-west-1 -p docker my-dockerized-next-app
-r eu-west-1 flag tells what region to use
-p docker flag tells that we're using docker
my-dockerized-next-app sets application name
If you don't specify region flag, use
eb status or check
config.yml file to find what region is used.
You can use application name that already exists in AWS EB Console - every environment you create with EB CLI will be created within existing EB application.
Before proceeding, make sure all your files are commited - EB CLI will produce incorrect result if they are not.
Now we can deploy our app to AWS:
eb create --elb-type application my-nextjs-env
--elb-type application tells to use Application Load Balancer - without this flag Classic Load Balancer (which is outdated) will be used
my-nextjs-env sets environment name
If environment with provided name already exists within selected application, it will be updated.
To update application, commit your changes and execute
eb deploy command.
In the next part we are going to connect our domain to EB application. Hope to see you there =)
Thanks for reading.