Deploy Flask Application using AWS App Runner Source Code Repository (Github)

Aniket Kumavat
5 min readApr 27, 2023

--

What is the AWS App Runner?

AAWS App Runner automates containerized app deployment by removing the need for infrastructure setup, management, and scaling. App Runner, which supports several languages and frameworks, handles the heavy lifting of scaling, monitoring, and infrastructure management. Deploying code is simple with AWS App Runner, making it suitable for developers that prioritize app development over infrastructure administration.

For more information, follow this link.

Figure: Architecture diagram for the implementation of the proposed solution

AWS App Runner features:

  1. Fully Managed Service: AWS App Runner is a fully managed service, thus, it handles all of the underlying infrastructure and scaling for you. This relieves developers of the responsibility of managing servers, load balancers, and other infrastructure components.
  2. Automated Build and Deployment: App Runner automates the construction and deployment processes, allowing you to rapidly and easily launch containerized applications.
  3. Load Balancing: App Runner automatically balances traffic to ensure your applications’ reliability and availability.
  4. Auto Scaling: App Runner automatically App Runner automatically scales the number of containers up or down to meet the needs of your application.
  5. Monitoring and Logging: App Runner provides monitoring and logging features that allow developers to track application performance and troubleshoot issues. These logs are monitored with AWS CloudWatch.
  6. Security: App Runner provides several security features, including encryption at rest and in transit, role-based access control, and VPC support.
  7. Certificate Management: App Runner includes fully managed TLS with no setup needed. App Runner automatically renews the certificates before their expiration date.
  8. Cost Management: Easily pause and resume your App Runner applications using the console, CLI, or API. You’re only billed when the service is running. You are charged for the compute and memory resources used by your application.

Now we are performing an App Runner service and deploying a Flask application in it with a Github repository.

Follow this blog if you want to do App Ruuner service with container registry (ECR) Rushabh Mahale

Prerequisites -

  1. An AWS account is required.
  2. IAM administrator privileges.
  3. A Github account is required.

To run a Flask application, follow these steps:

  1. Create a Flask application that can be run from the command line.
  2. Make a GitHub repository and upload the Flask app code (for example, “App-Runner-flask”).
  3. Select a region (for example, Northern Virginia) to install the app in order to check reliability or availability.

Steps to create an AWS App Runner with Github-

  1. Login to your AWS account, then search for App Runner in the AWS search bar.

2. Go to App Runner and click on Create App Runner service.

3. As the source provider, select Source code repository. To use App
Runner, AWS provides Github as an SCM tool.

4. Choose Add new under Connect to GitHub, and then, if required, enter your GitHub credentials. After that, install the AWS connector for Github so that both are directly connected.
As shown, which repositories are you going to select for your application? Here, select only the repository where the Flask application is stored.

6. Now that the connection is established, give the service a connection name.

7. On the Configure Build page, for Configuration File, choose Configure all settings here. Provide the build settings to deploy application.

Provide the following build settings:

  • Runtime: Choose Python 3.
  • Build command: Enter pip install -r requirements.txt.
  • Start command: enter python flaskapp.py.
  • Port: Enter 5000

9. The default port used for Flask application is 5000.

Note:- The Python 3 runtime builds a Docker image using a base Python 3 image and your example Python code. It then launches a service that runs a container instance of this image.

10. To proceed to the Configure stage, click Next. Under service settings, give the service a name and configure the virtual CPU and virtual RAM. The App Runner used pay-as-you-go charging for CPU and memory usage.

Configure specific configuration for scalable instances based on incoming traffic to the application, or keep the default configuration.

After configuring health checks, security, networking, and other settings:

  1. Review the details on the “Review and Create” page before creating and deploying the service.
  2. It takes a few minutes for the service to build and deploy.
  3. If successful, the service dashboard displays an overview of the new service.
  4. Verify the URL of the deployed application, which should be the default domain of the service.

After successfully build service check the URLof App Runner service. And below is the running Flask application web page content that was successfully delivered.

Check the URL of the App Runner service after it has been successfully built. The running Flask application web page content that was successfully created is seen below.

Conclusion

“I learned earlier that the developers manually containerized and deployed the code, manually connecting it to various AWS services.” However, with AWS App Runner, it becomes easier since we only need to make changes to our code and let App Runner do the rest. AWS App Runner decreases developer workloads because it is a fully-managed service. We are also able to integrate Github with App Runner.

If you have any questions regarding this article, please feel free to comment in the comments section or contact me via Linkedin.

I want to thank my team at Guysinthecloud for all of their help.

Thank You

--

--