AWS App Runner adds support for monorepos
AWS App Runner is a fully managed container application service that lets you build, deploy, and run containerized web applications and API services without prior infrastructure or container experience. Starting today, AWS App Runner supports deploying services from source code repositories that follow a monorepo structure. Now you can tell AWS App Runner the source directory you’d like to deploy from a monorepo that hosts source code for multiple services.
Monorepo is a software development strategy in which code for multiple distinct projects is stored in a single repository with well-defined relationships. Cloud computing customers are adopting monorepo development strategies to increase collaboration, avoid code duplication, and improve visibility. This is especially beneficial for developing modern applications that follow a micro-services based architecture.
Customers use AWS App Runner build-from-source capability to deploy services directly from source code, thereby offloading the build and deployment workflow management to AWS App Runner. Previously, AWS App Runner only supported the root directory of the repository to run your build and start commands. Starting today, you don’t need to manage separate build and deployment pipelines for your applications. You can define the source directory in your AWS App Runner service configuration that it uses to build and deploy your application.
You can also enable automatic deployment for your services. With automatic deployment enabled, AWS App Runner rebuilds and deploys a service when there is any update in the source directory or dependency of your service. AWS App Runner won’t redundantly rebuild and deploy your service if other applications or folders outside of the source directory are updated.
This means customers can benefit from the AWS App Runner build-from-source capability to deploy services directly from a source-code repository that follows a monorepo structure. Customers pay the standard build fee for source-code based services. Customers can benefit from the flexibility of their monorepo applications with the simplicity of running them on AWS App Runner.
To showcase monorepo support in AWS App Runner, we’ll walk you through a demonstration. We’ll deploy a sample application with two services — one frontend and one backend — from a single source-code repository.
The sample application is backed by a monorepo of two microservices that runs a website for a fictional hotel. Both the frontend and backend are NodeJS applications served by the Express web framework. We’ll use AWS App Runner to create two services to host the application.
As part of the infrastructure to support the application, we’ll create an Amazon Relational Database Service (Amazon RDS) database and the Amazon Virtual Private Cloud (Amazon VPC) networking components we need to communicate between our two services and the database. Public internet traffic will be able to reach the frontend service and make requests to manage the hotel rooms.
These requests travel securely through the VPC Connector and VpcIngressConnection to the Backend Service that serves the requests by querying the Amazon RDS database. Finally, the request is served and the requestor receives a response. To learn more about private networking with AWS App Runner, refer to our deep dive posts on VPC Networking and Private Services.
When we create the AWS App Runner services, we’ll configure their respective SourceDirectory with AutoDeployments enabled so that commits made to each SourceDirectory will only deploy to their respective services.
Figure 1: Architecture diagram showing two Monorepo AWS App Runner Services connected within the AWS Cloud.
You’ll need these setup to complete the walkthrough:
AWS App Runner connection
For code-based Services, AWS App Runner requires a connection to deploy code from your repository. We’ve created a GitHub Monorepo of the hotel application for you to fork for the purposes of this walkthrough.
First, access this GitHub repository and create a fork of the monorepo branch in your personal GitHub account. Store your repository URL as an environment variable:
Next, access the AWS App Runner Console in us-east-2 to create an AWS App Runner Connection with the name GitHubConnection connecting to your personal GitHub application. Once authenticated, you’ll be able to create AWS App Runner services from your GitHub repositories. See our Developer Guide for more details on how this handshake works.
Store the ConnectionArn locally for future use:
Networking and database infrastructure
Clone the sample repository (or your newly forked repository) which contains the code for our solution:
Let’s build the infrastructure by deploying the AWS CloudFormation template infrastructure/base-infrastructure.yaml to provision a VPC, VPC Endpoint, VPC Connector, Amazon RDS instance, and a Secrets Store for the database credentials:
Wait for the above AWS CloudFormation stack to complete. Once the stack has been provisioned, run the below commands to get output values from the stack:
Creating the Monorepo services
We now have all of infrastructure necessary to support our backend and frontend AWS App Runner services.
Let’s now create the backend service. First, run the below command to create a local file create_backend_service.json with the configuration for your service. Note that the SourceDirectory is specified as backend as seen in the git repository.
Create the service:
Store the backend ServiceArn from the response:
By default, AWS App Runner services are accessible publicly over the internet. But the backend service isn’t meant to be exposed publicly. We have to ensure that it is only accessible within our VPC.
To restrict network access to the backend service, we’ll create an AWS App Runner VPC Ingress Connection resource or a VpcIngressConnection. VPC Ingress Connection establishes a connection between a VPC interface endpoint and an AWS App Runner service, making your App Runner service accessible from only within an Amazon VPC.
Create a VpcIngressConnection to allow private access to your backend service:
Store the VpcIngressConnectionArn and DomainName from the response:
It’s now time to deploy the frontend service. Run the below command to create a local file create_frontend_service.json with the configuration for your service. Note that the SourceDirectory is specified as frontend as seen in the git repository.
Create the frontend service:
Store the frontend ServiceArn and ServiceUrl from the response:
Check the status of the creation while you wait for it to complete:
Once the service is available, access your application through the FRONTEND_URL.
Figure 2: Running Hotel application built with Monorepo frontend and backend services.
From here you can choose the Create button to create the database schema, and then add and view your hotel rooms. With AutoDeployments enabled, any changes committed to the frontend/ directory in your GitHub repository launches a deployment to the frontend service, but not the backend service. Give it a try!
AWS resources created during this walkthrough will incur cost. After finishing the demonstration, be sure to delete the infrastructure you created.
First, delete the AWS App Runner VpcIngressConnection:
Next, delete the frontend and backend services:
Finally, delete the AWS CloudFormation stack:
In this post, we showed you how you can deploy services from a monorepo using AWS App Runner. We used App Runner’s monorepo support to deploy a sample application, which has both a frontend and backend tier in a single source-code repository. We would encourage you to try out this new feature for your production web applications with AWS App Runner. Please learn more about AWS App Runner from our documentation and developer guide.