Amazon Elastic Beanstalk is a fully managed service offered by Amazon Web Services (AWS) that helps developers quickly deploy and manage web applications.
Generally, Elastic Beanstalk saves developers time and effort, as they do not need to worry about the underlying infrastructure and can focus on building and improving their application.
However, NextLink Labs has found that the promise falls through when upgrading your Elastic Beanstalk environment to a new major version— there are a number of manual steps that need to be taken.
With the Node 18 release date in 2023, now is a great time to prepare by upgrading to Node 16.
Let’s walk through the process of easily upgrading your existing Node 14 app to Node 16 on Elastic Beanstalk in AWS.
We'll cover the necessary steps and best practices, so you can make the most of the new features and performance improvements that come with the latest version.
So let's get started!
Step 1: Upgrade the Local Environment
The first step is to upgrade your application’s local environment to utilize Node 16.
nvm, or Node Version Manager, allows you to quickly install and use different versions of node via the command line. Install nvm following these instructions.
Once installed, use `nvm` to download, compile, and install the latest Node release:
nvm install node
In your application’s directory, install and use Node 16 using nvm:
nvm install 16.19.0
nvm use 16.19.0
Upgrade your package.json file with the updated Node version:
Install your dependencies:
Fix any errors caused by upgrading the Node version. You may need to upgrade package versions using:
npm update <package-name>@<version-number>
Verify that your application still works as expected, and make any necessary code fixes.
Step 2: Create Your New Elastic Beanstalk Environment
Although Elastic Beanstalk allows you to update the platform version for minor updates to the environment, you have to create a new environment to utilize a Node 16 compatible platform branch.
In Elastic Beanstalk, select “Applications” and select the application with your current environment.
Open your current environment in a new tab for reference and choose “Create environment.”
This will bring you to the “Configure environment” page. Complete the following steps:
- For “Environment tier,” select the type of environment your application utilizes. This will likely be a Web server environment.
- Under “Environment information,” choose your new environment name. We recommend specifying the Node version in the environment name to prevent confusion.
- Under “Platform,” select “Node.js.” Choose a Platform branch of Node.js 16 running on 64bit Amazon Linux 2. For “Platform version,” select the recommended version.
- For “Application code,” use the default “Sample application” option.
- Under “Presets,” choose “Custom configuration.”
Now, open the tab for your outdated environment. Select Configuration from the left panel and select “Edit” under “Service access.”
Copy the values from your previous environment into your new environment. Unfortunately, Elastic Beanstalk does not let you save and import your configuration settings when updating to a new platform branch, so you’ll have to copy these values manually.
Select “Next” and repeat these steps for each of the configuration options, copying the previous settings to your new environment.
On the “Review” page, review your settings and select “Submit.” Elastic Beanstalk will then launch your environment.
Select “Configuration” from the left panel and compare this with the configuration of your outdated environment. Ensure that the values of the two environments match.
If you make any changes to your configuration, make sure to select “Apply changes.”
Step 3: Upgrade Configuration Files
Does your application utilize GitLab CI/CD Pipelines, GitHub Workflows, or Docker images?
Search your project code for “node” and update the Node version number to reflect your newly installed version in your YML files, Dockerfiles, and other configuration files.
If your pipeline configuration files specify the name of the Elastic Beanstalk environment to deploy to, update these files with the name of your newly created environment.
Step 4: Deploy Your Application to Your New Environment
Now that your application code and Elastic Beanstalk environment are updated to utilize Node 16, it’s time to deploy your application code to the newly created environment.
Follow your normal deployment steps, and upon a successful deployment, open the environment in Elastic Beanstalk. Select “Go to environment” from the left panel. This will open the deployed application.
Test that the application is working as expected and troubleshoot any issues you may encounter.
Step 5: Swap Environment Domains
After validating that your application is running without issue on your new Node 16 environment, you can swap your environment domain to direct your traffic to the new environment.
In Elastic Beanstalk, select “Environments” from the left panel. Select the radio button to the left of your new environment. Then click the “Actions” tab and select “Swap environment domain.”
Under environment, choose the name of the previous environment and select “Swap.”
Your newly deployed application is now live!
Step 6: Terminate the Old Environment
Before terminating your previous environment, we recommend that you wait a few days to ensure that your new environment doesn’t cause any unexpected issues.
By keeping your old environment, you have the option of rolling back quickly by swapping back the environment domain to your Node 14 environment.
When you’re satisfied with the state of your new environment in production, terminate your old environment with the following steps:
- In the left panel, choose “Environments” and select your outdated environment from the list.
- Click “Actions,” and choose “Terminate environment.”
- Use the dialog box to confirm environment termination.
Install Node 18
And that’s it! You have successfully updated your application and Elastic Beanstalk environment to utilize Node 16.
When you need to update to Node 18, simply follow these steps again.
If you need help getting started with a custom software development project or need help navigating the digital transformation, contact NextLink Labs for support.