Deploy Next.js on AWS Amplify: A Step-by-Step Guide

Search for a command to run...

No comments yet. Be the first to comment.
Learn about Web Services (WS) and reference services. This series explores practical applications, best practices, and key concepts.
[A1] - Brute Force Time: O(n^2) Space: O(n^2) class Solution: def generate(self, numRows: int) -> List[List[int]]: # Initialize the triangle with the first row pascal_triangle = [] for i in range(numRows): # S...

YouTube Video https://youtu.be/hfN4VONP4HQ [A1] - Brute Force Time: O(n^2) Space: O(1) class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): for j in range(i+1, len(nums)): ...

LeetCode's Valid Anagram problem checks if two strings, `s` and `t`, are anagrams by comparing character frequencies.

LeetCode's Contains Duplicate problem checks if there are any duplicate elements in a given array, often solved using hash sets or sorting.

Our journey begins in the AWS Management Console. To start, first choose a Region. This is an important decision as it determines the location of your application's infrastructure. Consider factors like your target audience and any compliance requirements when making your selection.
Next, we'll use the search bar at the top of the console and type "Amplify." This will bring up the Amplify service in the search results. Once located, select "AWS Amplify." This will take you to the Amplify console, where you'll manage your applications.

And there you have it! You've successfully navigated to the AWS Amplify console. In the next step, we'll create a new application specifically for our Next.js project.
Now that we're in the Amplify console, it's time to create a new application.

Simply click the "Deploy an app" button to begin the process. This will guide you through the necessary steps to set up your Next.js project for deployment.
In this step, you'll connect your Next.js project's source code to AWS Amplify. Amplify supports various Git providers, ensuring a seamless connection to your repository.
Select a Git Provider: Choose your preferred Git provider from the options available—GitHub, Bitbucket, CodeCommit, or GitLab. For this example, we'll select GitHub.
Grant Access: AWS Amplify requires read-only access to your repository. Ensure you have authorized Amplify to connect to your Git provider. If this is your first time, you may need to log in and grant the necessary permissions.
Other Deployment Options: Alternatively, you can deploy without a Git provider by selecting the Deploy without Git option. This allows you to upload your app manually from Amazon S3 or a Zip file.
Templates: If you're starting fresh, Amplify offers templates for popular frameworks like Next.js, Vue, and Angular. These templates can be a great starting point for new projects.

Here I am selecting GitHub as the Git Provider for my project. Once you've made your selection, click the Next button to proceed to the next configuration step.
Authorize GitHub for AWS Amplify
After selecting GitHub as the source provider in the previous step, AWS Amplify will redirect you to GitHub for authorization.
You will see a screen titled "AWS Amplify Console would like permission to:".
Amplify requests read-only access to your repositories to link and deploy your project securely.
Click on the green Authorize AWS Amplify button to proceed.

Select Your GitHub Repository
Once authorized, you'll be redirected back to AWS Amplify to choose the specific repository for your application. You can choose all your repositories or some selected repositories.
If you have multiple repositories, select "Only select repositories".
In the dropdown menu, search for and choose your private repository (e.g., xopslab.org for my case) as shown in the image.
Click Install & Authorize to finalize the connection.

Note: If you're selecting a private repository, ensure the repository contains your Next.js application and all necessary dependencies to deploy successfully. AWS Amplify will have read-only access to the repository to fetch the code.
Select the Branch for Deployment
After authorizing the repository, AWS Amplify will display the selected repository and allow you to choose the branch you want to deploy from.
main). 
Monorepo Setting (Optional)
Amplify provides an option to configure monorepos. A monorepo is a single repository that holds multiple projects or applications, typically organized into separate folders. If your repository is a monorepo, you'll need to specify the folder containing the application you want to deploy.
Confirm the Configuration
Once you’ve selected the branch and ensured the monorepo setting is correct:

App Name
Build Settings
buildspec.yml file. You can modify this if your build process requires additional commands.Environment Variables
If your project requires environment variables (e.g., API keys or secrets), add them here by clicking Add Variable.
For example: NEXT_PUBLIC_API_URL = https://api.example.com
Be cautious about sensitive data—Amplify handles these securely.
Advanced Settings (Optional)
After completing these settings, click Next to proceed to the Review step.

Repository and Branch
App Details
Environment Variables
Once you’ve reviewed all the information and confirmed it’s correct, click the Save and Deploy or Next button to start the deployment process.
Monitor Deployment Status
After clicking Save and Deploy, AWS Amplify will take you to the Overview page.
Here, you can monitor the deployment status. The build process may take a few minutes to complete, depending on the size and configuration of your application.

Deployment Complete
Access Your Application
You can check your application by clicking the URL displayed on the overview page.
Alternatively, click the Visit Deployed URL button to open your live site in a new tab.
Congratulations! Your Next.js application is now successfully deployed using AWS Amplify.