AWS App Runner : How to deploy containerized applications using App Runner
Tags: aws, awsecr, awsapprunner, awsiam
Published: 2021-11-21 17:45:58

“Problems faced while running the container image with pipeline and issue of time and handling infrastructure''. I have tried to find out certain solutions from a scalable and cost perspective. Instead of creating a pipeline, AWS App Runner made my work easy. It Is easy to configure, there is no issue of scaling and can create a default domain. In terms of cost, charges are based on an hourly basis. Also, app runner has a benefit as it is easy to use, scales with traffic and saves time.

A keyword define "**Devtron**" play an important role in sorting the complexity of DevOps, AppOps and Kubernetes. Also "**GitHub**" helps to integrate and automate. Both Devtron and GitHub is an open source one.

In this post, you will get to know how to deploy containerized applications using app runner. Here I have used a aws cli to build the image and push it on ECR and then run it using app runner.

#Prerequisites
You’ll need [AWS Command Line Interface](https://docs.aws.amazon.com/cli/latest/userguide/installing.html) (AWS CLI) installed and configured on your machine. For this blog, I assume that the default AWS CLI region is set to oregon (us-west-2) and that you have access to the AWS services described in this post. If you use other regions, you should check the [availability](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services/) of AWS services in those regions.

NOTE : You can also use an Amazon EC2 Server for AWS CLI. Checkout [Getting started with amazon EC2](https://aws.amazon.com/ec2/getting-started/) provides instructions on how to launch an EC2 Server.

#Architecture Overview
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eobfb4u4g33gjbs3qtlj.png)
The architecture diagram shows the overall deployment architecture with data flow, application server, local machine, Amazon ECR, AWS App Runner.

#Solution overview
The blog post consists of the following phases:
1. Create a repository and push container image to ECR
2. Created role for App Runner ECR Access
3. Configuration of App Runner with ECR container image
4. Testing output and logs of App Runner

I am using a local machine to build the container image as below (Docker, Git and AWS CLI are installed on the local machine) →
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iduoqbtd2n70jp7rolv1.png)

##Phase 1: Create a repository and push container image to ECR
1. Open the local terminal, Created a repository in ECR named as hello-app-runner. Then done the authentication with Login succeeded. Then build the image then push it to ECR.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m3jsm7yren3qvqzbdgc4.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5zeqa68rqph2d5p2tcbt.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e3kybrwvspxc5fln7o3a.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8nctunl4a64d2jxqiwi.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9jy2hxlw802qcn2bee90.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aypeuvjksgpkmw5kdb2w.png)
2. Image tagged with name as latest.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b38o6ajpmike7o19fs5e.png)

##Phase 2: Created role for App Runner ECR Access
1. Created a role named AppRunnerAccessRole and a policy named AWSAppRunnerServicePolicyForECRAccess. 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e52tv0fsnh2cgra9ev36.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bvaaiac39kvfh1xbz4j.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8y242vrhu6sfg4cmf7mr.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nep32rnjz7ie9xfhn2qn.png)

##Phase 3: Configuration of App Runner with ECR container image  
1. Open the AWS App Runner console, Click on create an App Runner service button. In the source section: choose the repository type as container registry, provider as Amazon ECR, input container image URI, Process set as automatic and role created as AppRunnerAccessRole then click next.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqpzcmh7nmjhb09vb4pb.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gltfk02aoaq7q2dm8sbp.png)
2. Give the service name as hello-app-runner and leave the other settings as default. Review and create the configuration and then click on the create and deploy button.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mjcrlxbu98yuyl4haknr.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sbik7zgrk0kps1jt7xq6.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q78r89juld1f2l25g0s5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58w69gp6dqgu1fioo7yh.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oyxebiv27zvqa9gm75kw.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ckb4yudojfzhceyhxihy.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jvhgvnpukuva06qklra3.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ioxo0eebomogrblo715.png)

##Phase 4: Testing output and logs of App Runner 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/heorzqac6mjdyksrbze8.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vg8a0zozxpawuqktpthm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3y7tblgk7aizngi9h5f.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yce3fmju7ysfit7mbgdm.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9kom5xmjfocmxud9jkuq.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/prbh9e45de25zg8qc59h.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pcp8n37st0ieftioere5.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gyelhtpe3bfln8rjnlk7.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/meyf6yanjas5xr4jx5hc.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/au29rmn78h423mksyw41.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zqpfdfad32stg2jfnbyl.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5yc2dxe3pu8fqbmisy7e.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/egsnz4z6xnip0dimpj0d.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g9wak9a0aisn6stcxzkx.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iu8et7mjeu5y4pm5e4i1.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tg3b39gjv6a3r6ueep6w.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/njy97vvvbq8gd4i9i60m.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4fpbken6jmfa22f3iqf.png)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/177p5z47n80vyhb0bzgh.png)

#Clean-up
Delete Amazon ECR Repository.
Delete the AWS App Runner Service.

#Pricing
I review the pricing and estimated cost of this example. 
Cost of EC2 Container Registry (ECR) = $0.10 per GB-month of data storage = $0.004 GB-Mo.
Cost of AWS App Runner = $0.007 / GB-hour, $0.064 / vCPU-hour, $1 per application per month(Automatic Deployment), $0.005 per build-minute(Build Fee) = $(0.007+0.384+1+0.1) = $1.491
Cost of Data Transfer = $0.0 
Cost of Simple Notification Service = $0.0
Cost of Cloudwatch = $0.0
Total Cost = $(0.004+1.491+0.0+0.0+0.0) = $1.495

#Summary
In this post, I had shown you how to deploy containerized applications using app runner.

For more details on Amazon Elastic Container Registry, Checkout Get started Amazon Elastic Container Registry, open the [Amazon Elastic Container Registry console](https://us-west-2.console.aws.amazon.com/ecr/home?region=us-west-2). To learn more, read the [Amazon Elastic Container Registry documentation](https://docs.aws.amazon.com/ecr/?id=docs_gateway). For more details on AWS App Runner, Checkout Get started AWS App Runner, open the [AWS App Runner console](https://us-west-2.console.aws.amazon.com/apprunner/home?region=us-west-2#/welcome). To learn more, read the [AWS App Runner documentation](https://docs.aws.amazon.com/apprunner/?id=docs_gateway).

For more details on **Devtron and GitHub**, Checkout Links:
[Devtron Website](https://devtron.ai/)
[GitHub Repo](https://github.com/devtron-labs/devtron)
[Join the Discord Community](https://discord.com/invite/jsRG5qx2gp)
[Follow on Twitter](https://twitter.com/DevtronL)
[Raise feature requests, suggest enhancements, report bugs](https://github.com/devtron-labs/devtron/issues)
[Read Devtron Blog](https://devtron.ai/blog/)

Lets quickly adopt and try it! And post the response using **#AdoptK8sWithDevtron** **#devtron**

The above blog is submitted as part of 'Devtron Blogathon 2022' - [https://devtron.ai/](https://devtron.ai/)
Check out Devtron's GitHub repo - [https://github.com/devtron-labs/devtron/](https://github.com/devtron-labs/devtron/) and give a ⭐ to show your love & support.
Follow Devtron on LinkedIn - [https://www.linkedin.com/company/devtron-labs/](https://www.linkedin.com/company/devtron-labs/) and Twitter - [https://twitter.com/DevtronL/](https://twitter.com/DevtronL/), to keep yourself updated on this Open Source project.

Thanks for reading!

Connect with me: [Linkedin](https://www.linkedin.com/in/gargee-bhatnagar-6b7223114)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/38sdi4nsp89fnui8h7dk.png)