DEV Community

Python App Deploy to AWS App Runner using GitHub Actions

AWS App Runner is a fully managed service that makes it easy for developers to quickly deploy containerized web applications and APIs, at scale and with no prior infrastructure experience required.

In this scenario, we going to deploy a simple python application via AWS App Runner. We use the Github action CI/CD tool.

First of all, go through the Architectural diagram.
Image description

You can follow these steps.

Creating IAM Role

  • In the AWS management console search App Runner service and go-
    to service. After clicking Create role button.
    Image description

  • Next Trusted entity type as Custom trust policy and paste
    following policy.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "build.apprunner.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Image description
After that click, the Next button.

  • Next select policy as AWS Managed
    "AWSAppRunnerServicePolicyForECRAccess" policy and click next
    button.
    Image description

  • Give the Name and Description(Optional) for the Role and
    click Create role button.
    Image description
    Image description

Create a GitHub repository and push the following files. You can get sample files using the following repository.

Repository URL
Github get-started guide guide

Use the following folder structure.
Image description

Next, add Secrets inside GitHub repository settings.

Image description

Create the following repository secrets.
Image description

  1. You can easily create AWS AWS_ACCESS_KEY_ID & AWS_SECRET_ACCESS_KEY using creating new IAM role. Don't create access keys for the root user.
  2. AWS_REGION is your AWS region. Ex - us-east-2
  3. ROLE_ARN means the previous step created IAM role ARN. You can easily copy it go to the app-runner-sr role.

Create ECR Private repository.

In the AWS management console find AWS App Runner. After that create ECR private repository like the following.
Image description
Image description

Next, go to the local repository or remote repository and change files, and push it.

After inside the Github repository and select the action section. you can see the pipeline is running & after a few minutes it becomes completed.
Image description

AWS App Runner dashboard you can see your application is up and running.
Image description

Finally, in the Service overview section Copy the Default domain and paste the web browser. You can see your running application.
Image description

AWS App Runner References - https://docs.aws.amazon.com/apprunner/latest/dg/what-is-apprunner.html

Thanks for reading the Article.

Top comments (0)