AWS offers so many amazing managed services. I happen to stumble upon the AWS Apprunner recently when I was looking up the list of choice that can deploy web applications with little know-how. It is a little similar to the Elastic Beanstalk in function, however, the difference lie in the part where Apprunner can run automatic deploy the web application directly from Github. You do not need to zip the source code and upload it like what is required when using Elastic Beanstalk. Although an exception is manually using GitHub to deploy to Elastic Beanstalk
One other difference is the SSL certificate that comes with the AWS Apprunner service URL by default, while for AWS Elastic Beanstalk and EC2 deployments you will need to manually configure SSL with the LoadBalancer HTTPs protocol, or redirect with an domain provider DNS certificate.
what is AWS app runner
Like I mentioned earlier, AWS App Runner is a fully managed service that makes it easy for you to quickly build, deploy, and manage containerized web applications and APIs at scale and with no prior infrastructure experience required. Starting with the source code or a container image, App Runner will automatically build, scale, and secure the web application in the AWS Cloud.
And so, we will deploy a BootStrapped NodeJS application using the AWS Apprunner service.
source code source
Also, using AWS Apprunner to deploy web application with docker requires a Dockerfile. I created one. You will find the link to the GitHub repository later in this demo.
That been said, let’s move into the business of the day.
create the apprunner service
Search for Apprunner from the AWS Console search bar. Click on Create Service
deploy from GITHUB source code repository
On the next screen, you will be asked to select the Source for AWS Apprunner to deploy your web application. For now, we will use Source Code Repository. And there you will connect your GitHub repository to AWS Apprunner a similar process to deploying Elastic Beanstalk from GitHub.
Select Source Code Repository, click on the Add New.
CONFIGURE SOURCE CODE CONNECTION
In the next screen, enter a Connection Name, then click the Install Another (for new github connections). A pop up window will open for you to select your GitHub organizations. Select any of the organization and then the repository containing the source code of your web application.
Once you are done with the configuring the repository where AWS Apprunner will deploy from, you will be returned to the Apprunner Connection window with the location automatically updated. Click Next.
You will return to the AWS Apprunner Source window. Select the Organization, the Repository and the Branch if it not automatically populated.
Scroll down under deployment settings, select Automatic. This will make AWS Apprunner automatically pick up any changes from GitHub repository and deploy the web application.
SELECT RUNTIME FOR WEB APPLICATION
In the Build Settings, select NodeJS 16 (16 is the version). Thereafter, enter the npm install and npm start, and 3000 (your application port) in the Build command, Start command, and Port respectively. This will ensure AWS Apprunner compile, build and start the web application we deploy on the correct port number.
If you choose to Use a Configuration File, check this repository for sample yml file
In the Service Settings window, enter a Service Name to identify the web application Apprunner will deploy. However, if your web application uses some environment variables, you can specify them in the Environmental Variables field in the Key-Value format.
Once done, click on Next.
On the review page, review all the configuration especially the port, build and, start command. Then Click Create & Deploy.
It takes about 10 minutes for AWS Apprunner service to configure your environment and deploy the web application. Therefore, exercise a little patient when it is deploying.
After Apprunner deploy the web application, you will get the green ribbon notification, and the URL to access the Apprunner deployed web application.
access the application using the apprunner url
Paste the URL from Apprunner to view you deployed website. Now you can easily make changes in your application source code, push it to GitHub and AWS Apprunner will automatically run the process to deploy your web application.
using ECR Docker Registry WITH APP RUNNER
We will see how to configure AWS Apprunner to deploy the same web application using docker image. Already created AWS container registry is a prerequisite to this option. Follow this tutorial to see how to create an AWS Container Registry You also need to create a Dockerfile in the root of your project.
Clone the project repository with Dockerfile here.
Navigate under the source, select the Container Registry option. Choose the Amazon ECR and paste in the URI of the container registry. Alternatively, click the Browse and select the repository and the image tag of the repository.
Under Deployment Settings, select Automatic, and Create New Service Role under the ECR access role. Click Next. Follow this demo to create and use custom IAM service role.
Under the Service Settings, enter a name and enter the port number. The port number should be the same as the port exposed in your Dockerfile
Click on the Next to review you application setting, then click Create & Deploy.
TEST YOUR APPLICATION
It takes a couple of minutes for Apprunner to deploy your web application with docker. Once done, grab the URL and access you application from the browser. You can also use a custom domain and SSL certificate with this URL.
You will agree with me that AWS Apprunner service is one of the best service to use to deploy web application. I recommend you practice over again until you are comfortable with it.
Also, I strongly advise you delete the application once you are done with the demo if you are not using Apprunner for production deployment yet. Leaving the service running could attract some billing to your account.
TROUBLESHOOTING APPRUNNER WEB APPLICATION DEPLOYMENT
- ERROR: Application not found when accessed from the web browser
SOLUTION: Check that the application port configured n the Apprunner service is the same. Also check that the environment variables is correctly entered during configuration.
NB: You may need to redeploy the who application from the beginning with Apprunner service