DEV Community

GargeeBhatnagar for AWS Community Builders

Posted on

AWS App Runner : How to deploy containerized applications using App Runner

“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.

Amazon Elastic Container Registry (Amazon ECR) is an AWS managed container image registry service that is secure, scalable and reliable. Amazon ECR supports private repositories with resource-based permissions using AWS IAM. This is so that specified users or Amazon EC2 instances can access your container repositories and images. You can use your preferred CLI to push, pull and manage Docker images, Open Container Initiative (OCI) images and OCI compatible artifacts.

Amazon ECR contains the following components:

  1. Registry - An Amazon ECR private registry is provided to each AWS account; you can create one or more repositories in your registry and store images in them. For more information, see Amazon ECR private registries.
  2. Authorization Token - Your client must authenticate to Amazon ECR registries as an AWS user before it can push and pull images. For more information, see Private registry authentication.
  3. Repository - An Amazon ECR repository contains your Docker images, Open Container Initiative (OCI) images and OCI compatible artifacts. For more information, see Amazon ECR private repositories.
  4. Repository policy - You can control access to your repositories and the images within them with repository policies. For more information, see Repository policies.
  5. Image - You can push and pull container images to your repositories. You can use these images locally on your development system, or you can use them in Amazon ECS task definitions and Amazon EKS pod specifications. For more information, see Using Amazon ECR images with Amazon ECS and Using Amazon ECR Images with Amazon EKS.

AWS App Runner is an AWS service that provides a fast, simple and cost-effective way to deploy from source code or a container image directly to a scalable and secure web application in the AWS Cloud. You don’t need to learn new technologies, decide which compute service to use, or know how to provision and configure AWS resources.

App Runner connects directly to your code or image repository. It provides an automatic integration and delivery pipeline with fully managed operations, high performance, scalability and security.

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 (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 of AWS services in those regions.

NOTE : You can also use an Amazon EC2 Server for AWS CLI. Checkout Getting started with amazon EC2 provides instructions on how to launch an EC2 Server.

Architecture Overview

Image description
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

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 Image description Image description Image description Image description Image description
  2. Image tagged with name as latest. Image description

Phase 2: Created role for App Runner ECR Access

  1. Created a role named AppRunnerAccessRole and a policy named AWSAppRunnerServicePolicyForECRAccess. Image description Image description Image description Image description

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 Image description
  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 Image description Image description Image description Image description Image description Image description Image description

Phase 4: Testing output and logs of App Runner

Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description
Image description

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. To learn more, read the Amazon Elastic Container Registry documentation. For more details on AWS App Runner, Checkout Get started AWS App Runner, open the AWS App Runner console. To learn more, read the AWS App Runner documentation.

Thanks for reading!

Connect with me: Linkedin
Image description

Discussion (0)