Table of content:
- Create dockerized NextJS app - previous part
- Manual upload
- Beanstalk CLI
- Add custom domain - next part
- Set up redirects - part 4
Hello everyone.
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!
Deployment to Beanstalk
There are two ways to deploy our app to Beanstalk:
- Manual upload to Beanstalk
- Beanstalk CLI
Manual upload to Beanstalk
In your project folder delete node_modules
directory (and .next
if present), archive leftovers into zip archive. Switch to AWS Console.
New Beanstalk application
If you don't have a Beanstalk application, we need to create one:
- Open AWS Console Beanstalk welcome page
- Click
Create application
button - Fill in application name and select platform
Docker
In Application code
section select Upload your code
, in Source code origin
select Local file
and choose created zip archive.
Finally, click Create application
. It will take a few minutes to deploy our app.
Existing Beanstalk application
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
Applications
tab in the sidebar - Click
Create new application
- Fill in application name and click
Create
Now it's time to create a new environment for our Next app:
- Open created application (if you was following previous step, you already there)
- Tap
Create a new environment
- On
Select environment tier
step leave defaults (Web server environment
) and clickSelect
- Select
Docker
platform and upload your zip archive
Finally, click Create environment
.
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
Elastic Beanstalk CLI
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.
Initialize application
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.
Deploy
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.
Update
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.
Top comments (0)