Skip to content

Automated deployment of a web app using AWS App Runner, with seamless GitHub integration and HTTPS support.

Notifications You must be signed in to change notification settings

vondermanzen/Hello-aws

 
 

Repository files navigation

© The Chancellor, Masters and Scholars of The University of Oxford. All rights reserved.

Explore different providers

This course is available for multiple cloud providers. Choose your preferred platform:

Instructions

Step 1. Fork (or make a copy of) this repository

Step 2


Step 2. Go to the AWS Console and type "app runner" in the search bar

Step 2


Step 3. Create a new service

Step 3


Step 4. Select source code repository and link your repository

Step 4


Step 5. Set deployment to automatic

Step 5


Step 6. Select "Use a configuration file" (apprunner.yaml is already in the repository)

Step 6


Step 7. Choose a name for your service and deploy it. Default settings like 1 CPU and 2 GB RAM are enough.

Step 7


Voilà! Access the URL.

Voilà


Going further

Modifying the code

You can commit some changes to your repository and watch how the service is updated automatically.

Updating a service

Using a custom domain

Step 1. If you want to use a custom domain (like hello.com), just click "Link domain".

Linking the domain


Step 2. If you are using Route 53, then AWS should create the record for you. You don't need to do this step but you might need to delete the records manually when you remove the service.

The DNS record


Voilà!

Voilà

Cleaning up

Don't forget to delete your service when you are no longer using it. You can always redeploy later.

Deleting a service

Adding an API endpoint

Add the following code in app.py

@app.route("/hello_api")
def hello_api():
    return {
		"name": "Wrinkle Five Star",
		"species": "Duck",
		"breed": "American Pekin",
		"hatching_date": "2020-09-09",
		"sex": "Male"
    }

Then test your endpoint

API endpoint

User interface

In app.py, change the default route from "index.html" to "user_interface.html"

@app.route("/")
def home():
    return render_template("user_interface.html")

Access the URL again and make sure the duck appears.

Duck

Below the duck, there are code snippets. Move on the "Storage bucket" chapter.

Storage bucket

Use the code snippet to create a S3 bucket

If you have enabled the user interface, you should find consoles under the duck. You have the choice between running a Python script or running a CLI command.

Create S3 bucket

Check the S3 bucket has been properly created

Since S3 buckets must be unique across all AWS users, only one of us could name the bucket "workshop-bucket". That's why the script adds your account ID in the name.

Created S3 bucket

Upload duck.glb to S3

Upload S3 bucket

Check the duck is in the S3 bucket

Uploaded S3 bucket

Download oxford.glb from the bucket

First, you need to modify the upload code to upload "oxford.glb" instead of "duck.glb", and run it again.

Upload S3 bucket

Then, you can use the third code snippet to download oxford.glb.

Download S3 bucket

Check that oxford.glb is downloaded

The 3D model should now be the door to St. Cross College.

Downloaded S3 bucket

Cleaning up

Run the fourth snippet to delete the bucket.

Cleanup S3 bucket

Check that the S3 bucket is deleted

Cleaned S3 bucket

TROUBLESHOOTING: Missing S3 permissions

Are you getting an error when you try to run the first code snippet? Most likely, this is because your AWS App Runner instance is not authorized to use S3.

Security error

In App Runner, go to Configuration, then Security, and check that the instance is associated to a role.

Security configuration

To this role, attach the S3 full access policy.

Attach policy

Testing on your local machine

After a while, it's not fun anymore to wait for deployment. You want to test your changes before.

Step 1. Install git and clone the repository on your local machine
	git clone {repository_link}

Step 2. Install Python
https://www.python.org/downloads/

Step 3. Install dependencies
	 py -m pip install flask

Step 4. Run flask
	 py -m flask run

Open localhost:5000 in your browser.


Local testing

Running a job on a separate machine

This web server is not powerful enough to handle sophisticated tasks. What if GPUs are needed for a heavy workflow? Then you need the ability to create machines dynamically and control them remotely (Infrastructure as Code).

Install dependencies Missing content

Working through CLI on your local machine

Setup the AWS CLI

Step 1. Install the AWS CLI on your local machine

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html


Step 2. In the AWS Console, go to security credentials

Security credentials


Step 3. Create an access key

Access key

Access key


Step 4. Configure AWS on your local machine

Command: aws configure

Access key


Upload the app to Elastic Container Registry

Step 1. Install Python on your local machine

https://www.python.org/downloads/


Step 2. Install Docker on your local machine

https://www.docker.com/get-started/


Step 3. Run script upload_ecr_image.py

Access key


Step 4. In the AWS Console search bar, type "ecr"

Access key


Step 5. Check that the repository appears

Ac


Step 6. Now you can go back to creating an App Runner service using the ECR. You have the choice to do that through the AWS Console again, or programmatically with a script in the next section.

Access key


Create the service using the ECR image

Step 1. Run script create_service.py

Create service


Step 2. Go to the AWS Console and type "app runner" in the search bar

Search app runner


Step 3. Check the service is up and running

Services


About

Automated deployment of a web app using AWS App Runner, with seamless GitHub integration and HTTPS support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • HTML 62.5%
  • Python 37.5%