Skip to content

Commit

Permalink
Various README updates
Browse files Browse the repository at this point in the history
* Add more background to intro
* Add sections on Account Setup and Updating RV config
* More info about picking subnets for specific instance types
* More info about adding a ECR repos for "advanced users"
* Remove Terraform info
* Split table with variables to set into respective sections to avoid
confusion
  • Loading branch information
lewfish committed Jan 29, 2019
1 parent 4ac0293 commit 7d82740
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
88 changes: 41 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Raster Vision AWS Batch runner setup

This repository contains the deployment code that sets up the necessary AWS resources to utilize the AWS Batch runner in [Raster Vision](https://rastervision.io). Deployment can be driven either by [Terraform](https://terraform.io/) and the [AWS Command Line Interface (CLI)](http://aws.amazon.com/cli/) through a local Docker Compose environment, or via the AWS console using a [CloudFormation template](https://aws.amazon.com/cloudformation/aws-cloudformation-templates/).
This repository contains the deployment code that sets up the necessary AWS resources to utilize the AWS Batch runner in [Raster Vision](https://rastervision.io). Using Batch is advantageous because it starts and stops instances automatically and runs jobs sequentially or in parallel according to the dependencies between them. In addition, this deployment sets up distinct CPU and GPU resources and utilizes spot instances, which is more cost-effective than always using a GPU on-demand instance. Deployment is driven via the AWS console using a [CloudFormation template](https://aws.amazon.com/cloudformation/aws-cloudformation-templates/). This AWS Batch setup is an "advanced" option that assumes some familiarity with [Docker](https://docs.docker.com/), AWS [IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html), [named profiles](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html), [availability zones](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html), [EC2](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html), [ECR](https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html), [CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html), and [Batch](https://docs.aws.amazon.com/batch/latest/userguide/what-is-batch.html).

## Table of Contents ##

* [AWS Account Setup](#aws-account-setup)
* [AWS Credentials](#aws-credentials)
* [Packer Image](#packer-docker-image)
* [AMI Creation](#ami-creation)
* [Deploying Batch resources](#deploying-batch-resources)
* [Update Raster Vision configuration](#update-raster-vision-configuration)

## AWS Account Setup ##

In order to setup Batch using this repo, you will need setup your AWS account so that:
* you have either root access to your AWS account, or an IAM user with admin permissions. It may be possible with less permissions, but we haven't figured out how to do this yet after some experimentation.
* you have the ability to launch P2 or P3 instances which have GPUs. In the past, it was necessary to open a support ticket to request access to these instances. You will know if this is the case if the Packer job fails when trying to launch the instance.
* you have requested permission from AWS to use availability zones outside the USA if you would like to use them. (New AWS accounts can't launch EC2 instances in other AZs by default.) If you are in doubt, just use us-east-1.

## AWS Credentials ##

Expand All @@ -21,29 +30,21 @@ Default region name [us-east-1]: us-east-1
Default output format [None]:
```

You will be prompted to enter your AWS credentials, along with a default region. These credentials will be used to authenticate calls to the AWS API when using Terraform and the AWS CLI.

You will be prompted to enter your AWS credentials, along with a default region. The Access Key ID and Secret Access Key can be retrieved from the IAM console. These credentials will be used to authenticate calls to the AWS API when using Packer and the AWS CLI.

## AMI Creation ##

This step uses packer to install nvidia-docker on the base ECS AMI
in order to run GPU jobs on AWS Batch.
This step uses packer to install nvidia-docker on the base ECS AMI in order to run GPU jobs on AWS Batch.

### Configure the settings ###

Copy the `settings.mk.template` file to `settings.mk`, and fill out the options shown in the table below.
Please note that some of the entries must be filled-out before you run the `make create-image` command (e.g. `AWS_BATCH_BASE_AMI`)
and some of them can only be filled-out afterwards (e.g. `AMI_ID`).
Copy the `settings.mk.template` file to `settings.mk`, and fill out the options shown in the table below. *Remaining variables in the settings file will be filled in later.*

| `AWS_BATCH_BASE_AMI` | The AMI of the Deep Learning Base AMI (Amazon Linux) to use. |
| Variable | Description |
|------------------------------|------------------------------------------------------------------------------|
| `AWS_BATCH_BASE_AMI` | The AMI of the Deep Learning Base AMI (Amazon Linux) to use. |
| `AWS_ROOT_BLOCK_DEVICE_SIZE` | The size of the volume, in GiB, of the root device for the AMI. |
| `AMI_ID` | The AMI ID that comes from the `make create-image` step |
| `KEY_PAIR_NAME` | The key pair name for the batch EC2 instances |
| `AWS_REGION` | The AWS region to use. |
| `RASTER_VISION_IMAGE` | The raster vision image to use. e.g. quay.io/azavea/raster-vision:gpu-latest |
| `ECR_IMAGE` | The name for the ECR image |
| `ECR_IMAGE_TAG` | The ECR image tag to use, that is the tag in ECR_IMAGE |

To find the latest Deep Learning Base AMI, search in the AMI section of your EC2 AWS console for
`Deep Learning Base AMI (Amazon Linux)`.
Expand All @@ -70,60 +71,53 @@ so you should go through the three steps rather than copying from the screenshot

### Create the Custom AMI ###

Ensure that the AWS profile for the account you want to create the AMI in is set in your `AWS_PROFILE`
environment variable setting.
Ensure that the AWS profile for the account you want to create the AMI in is set in your `AWS_PROFILE` environment variable setting.

Then run:
```shell
> make create-image
> make create-ami
```

This will run packer, which will spin up an EC2 instance, install the necessary resources, create an AMI
off of the instance, and shut the instance down.

### Record the AMI ID ###

Be sure to record the AMI ID, which will be given in the last line of the output for `make create-image`
on a successful run. Put this in the `settings.mk` as `AMI_ID`.
This will run Packer, which will spin up an EC2 instance, install the necessary resources, create an AMI
off of the instance, and shut the instance down. Be sure to record the AMI ID, which will be given in the last line of the output.

## Deploying Batch resources ##

Once you have an AMI ready, you have two options for deploying Batch resources: you can use Terraform and the command line, or you can use the AWS CloudFormation console.

### Option A: Terraform and the command line

Create the AWS Batch compute environment, queue, and more by doing:

```shell
> make plan
> make apply
```

### Option B: AWS CloudFormation console

To deploy AWS Batch resources using AWS CloudFormation, start by logging into your AWS console. Then, follow the steps below:

- Navigate to `CloudFormation > Create Stack`
- In the `Choose a template field`, select `Upload a template to Amazon S3` and upload the template in `cloudformation/template.yml`
- Specify the following required parameters:
- `Stack Name`: The name of your CloudFormation stack
- `VPC`: The ID of the Virtual Private Cloud in which to deploy your resource. Your account should have at least one by default.
- `Subnets`: The ID of any subnets that you want to deploy your resources into. Your account should have at least two by default; make sure that the subnets you select are in the VPC that you chose by using the AWS VPC console, or else CloudFormation will throw an error. (Subnets are tied to availability zones, and so affect spot prices.)
- `SSH Key Name`: The name of the SSH key pair you want to be able to use to shell into your Batch instances. If you've created an EC2 instance before, you should already have one you can use; otherwise, you can create one in the EC2 console.
- `Subnets`: The ID of any subnets that you want to deploy your resources into. Your account should have at least two by default; make sure that the subnets you select are in the VPC that you chose by using the AWS VPC console, or else CloudFormation will throw an error. (Subnets are tied to availability zones, and so affect spot prices.) In addition, you need to choose subnets that are available for the instance type you have chosen. To find which subnets are available, go to Spot Pricing History in the EC2 console and select the instance type. Then look up the availability zones that are present in the VPC console to find the corresponding subnets. ![spot availability zones for p3 instances](/docs/images/spot-azs.png)
- `SSH Key Name`: The name of the SSH key pair you want to be able to use to shell into your Batch instances. If you've created an EC2 instance before, you should already have one you can use; otherwise, you can create one in the EC2 console. *Note: If you decide to create a new one, you will need to log out and then back in to the console before creating a Cloudformation stack using this key.*
- `AMI`: Provide the ID of the AMI that you created above.
- Adjust any preset parameters that you want to change (the defaults should be fine for most users) and click `Next`
- `Instance Types`: Provide the instance types you would like to use. (For GPUs, `p3.2xlarge` is approximately 4 times the speed for 4 times the price.)
- Adjust any preset parameters that you want to change (the defaults should be fine for most users) and click `Next`.
- Advanced users: If you plan on modifying Raster Vision and would like to publish a custom image to run on Batch, you will need to specify (CPU and GPU) ECR repo names and a tag name to use for both. Note that the repo names cannot be the same as the Stack name (the first field in the UI) and cannot be the same as any existing ECR repo names. If you are in a team environment where you are sharing the AWS account, the repo names should contain an identifier such as your username.
- Accept all default options on the `Options` page and click `Next`
- Accept `I acknowledge that AWS CloudFormation might create IAM resources with custom names` on the `Review` page and click `Create`
- Watch your resources get deployed!

### Publish the Raster Vision container to ECS
### Optional: Publish local Raster Vision images to ECR

Once you've deployed Batch resources with either Terraform or the AWS CloudFormation console, the last step is to publish your Raster Vision container to ECS where Batch can pull it.
If you setup ECR repositories during the CloudFormation setup (the "advanced user" option), then you will need to follow this step, which publishes local Raster Vision images to those ECR repositories. Every time you make a change to your local Raster Vision images and want to use those on Batch, you will need to run this step.

Use
Run `./docker/build` in the main Raster Vision repo to build local copies of the CPU and GPU images.

```shell
> make publish-container
```
In `settings.mk`, fill out the options shown in the table below.

| Variable | Description |
|------------------------------|------------------------------------------------------------------------------|
| `RASTER_VISION_CPU_IMAGE` | The local Raster Vision CPU image to use.
| `RASTER_VISION_GPU_IMAGE` | The local Raster Vision GPU image to use.
| `ECR_CPU_IMAGE` | The name of the ECR CPU image |
| `ECR_GPU_IMAGE` | The name of the ECR GPU image |
| `ECR_IMAGE_TAG` | The ECR image tag to use, that is the tag in ECR_CPU_IMAGE and ECR_GPU_IMAGE |

Run `make publish-container` to publish the CPU and GPU images to your ECR repositories.

## Update Raster Vision configuration

to publish the raster-vision container to your ECR repository.
Finally, make sure to update your [Raster Vision configuration](https://docs.rastervision.io/en/latest/setup.html#setting-up-aws-batch) with the Batch resources that were created.
2 changes: 1 addition & 1 deletion cloudformation/template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Metadata:
- KeyName
-
Label:
default: AMIs and Instance Types (Advanced)
default: AMIs and Instance Types (Required)
Parameters:
- GpuAMI
- CpuAMI
Expand Down
Binary file added docs/images/spot-azs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7d82740

Please sign in to comment.