How to set up AWS App Runner?

ELAKIA VM
featurepreneur
Published in
5 min readAug 7, 2022

What & Why App Runner?

Developers want to write code and build applications, but the time spent preparing and managing the infrastructure limits their productivity. AWS App runner makes it easy for the developer to run the web application with the scale with no prior AWS experience required.

Begin with the source code or a container image, then the App runner will automatically build and deploys the web application then scales the infrastructure needed and the load-balanced traffic with end-to-end encryption. With just a few clicks, you can create the web application using app runner, which will take carry of the run time configuration, networking, load balancing and integration with your deploying pipeline, empowering you to focus on your work. App runner will also make scalability, simple and cost-effective, It streamlets skill up resources in response to the traffic and scales down when there is reduced activity. You will save time because the resources and infrastructure components are fully managed and integrated with AWS security and operation best practices.

AWS App runner delivers easy and convenient, developer experiences in running the web application.

How to deploy?

First, have your source code which should contain a Dockerfile and docker-compose file.

Sample hello world application in the flask with docker.

app.py file:

from flask import Flask,render_templateapp = Flask(__name__)@app.route("/",methods=["GET","POST"])def start ():    return "Hello what ever"
if __name__ =="__main__": app.run(debug=True,host="0.0.0.0",port=2000)

Dockerfile:

FROM python:3.9.6-slim-busterADD . /appWORKDIR /appRUN pip install -r requirements.txtEXPOSE 2000CMD ["python","app.py"]

docker-compose file:

version: '3'services:    firstservice:        container_name: firstcontainer        build: .        ports:            - "2000:2000"

And have your requirements file also.

The second step is to go to the AWS console and search for ECR (Elastic Container Register).

Just click the button Get Started and after that, you will end up on this page .

In the Visibility setting clicks private or public according to your requirements like, whether your repository will be public or private. A public repository is visible on the Amazon ECR Public Gallery and the contents are available to pull by anyone. A private repository is only accessible to users who have explicit permission through either an IAM policy or a repository policy. Once a repository has been created, the visibility setting can’t be changed.

Then fill in the name for your repository this is to identify your repository and the name should be following the rules given.

After that, you can go and click create repository.

Then you will see the repository is created and click your repository, after that you can see the view push commands button getting enabling then click that button. It will show something like this.

Just run the commands in your terminal. If you don’t have AWS CLI then go ahead and set up the CLI in your terminal after that you can run those commands.

The third step is going to the App Runner service.

Click on create an app runner service button and you will end on this page.

Here you choose Container registry as we are using ECR container and choose just Amazon ECR because we have given a private repository. After that just click on the Browse button then you can search for the repository and press the Continue button.

After that, you create an IAM role for giving access permission to the ECR, use AWSAppRunnerServicePolicyForECRAccess manage policy. And choose that IAM role, after that click the Next button

Then you land on this page.

Fill in the name of the service you want to give and change the port number to your application, then just leave everything as it is and you can add a tag to your service and click the Next button. Review your set up and after checking you can press Create & deploy button. Then it will start deploying your application.

Hold on for a few mins it will take time for deploying the application. After you will see that you get the service being deployed.

If you click on the Default domain URL and you can see the application running.

For Deleting the service you can click on the Action and click on the Delete button.

Summary:

First, you need to have Dockerfile and docker-compose file for your application and go to ECR and create a container for your application and then go to App runner service and deploy it.

If you need the code that I have used in this article, here is the:

GitHub link: https://github.com/elakiavm/docker-basic

--

--