Skip to content

Commit

Permalink
Merge pull request #28 from DistributedScience/setup_aws
Browse files Browse the repository at this point in the history
create setup_AWS.py
  • Loading branch information
ErinWeisbart authored Mar 31, 2023
2 parents 215d4b5 + 4813af0 commit 102fd32
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 57 deletions.
4 changes: 2 additions & 2 deletions documentation/DS-documentation/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Distributed-Something:
* simplifies the process of distributing and running software in the cloud.
* decreases the cost of cloud computing by optimizing resources used.
* makes workflows reproducible.
* is Python based which makes creating new implementations broadly accessible to intermediate computationalists.
* only requires human-readable configuration to run an implementation which makes it broadly accessible to novice computationalists.
* is Python based which makes creating new implementations broadly accessible to intermediate computationalist developers.
* only requires human-readable configuration to run an implementation which makes it broadly accessible to novice computationalist users.

You will need to customize Distributed-Something for your particular use case.
See [Customizing Distributed-Something](customizing_DS.md) for customization details.
Expand Down
17 changes: 15 additions & 2 deletions documentation/DS-documentation/overview_2.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Using Distributed-Something
The architecture of Distributed-Something is based in the [worker pattern](https://web.archive.org/web/20220116213859/https://aws.amazon.com/blogs/compute/better-together-amazon-ecs-and-aws-lambda/) for distributed systems.
We have adapted and simplified that architecture for Distributed-Something.
In short, Distributed-Something uses a control node to submit jobs to AWS and those jobs are run in parallel on EC2 instances that are automatically managed by ECS.

## What happens in AWS when I run Distributed-Something?

Expand Down Expand Up @@ -42,7 +45,7 @@ If SQS tells them there are no visible jobs then they shut themselves down.
**Optional Step 4 (E)**:
If you choose to run `python3 run.py monitor` it will automatically scale down your hardware (e.g. intelligently scale down your spot fleet request) during a run and clean up all of the infrastructure you created for the run at the end of the run.

## What does this look like?
## What does an instance configuration look like?

![Example Instance Configuration](images/sample_DCP_config_1.png)

Expand All @@ -65,4 +68,14 @@ How long a job takes to run and how quickly you need the data may also affect ho
* Running a few large Docker containers (as opposed to many small ones) increases the amount of memory all the copies of your software are sharing, decreasing the likelihood you'll run out of memory if you stagger your job start times.
However, you're also at a greater risk of running out of hard disk space.

Keep an eye on all of the logs the first few times you run any workflow and you'll get a sense of whether your resources are being utilized well or if you need to do more tweaking of your configuration.
Keep an eye on all of the logs the first few times you run any workflow and you'll get a sense of whether your resources are being utilized well or if you need to do more tweaking of your configuration.

## What does this look like on AWS?
The following five are the primary resources that Distributed-Something interacts with.
After you have finished [preparing for Distributed-Something](step_0_prep), you do not need to directly interact with any of these services outside of Distributed-Something.
If you would like a granular view of what Distributed-Something is doing while it runs, you can open each console in a separate tab in your browser and watch their individual behaviors, though this is not necessary, especially if you run the [monitor command](step_4_monitor.md) and/or have DS automatically create a Dashboard for you (see [Configuration](step_1_configuration.md)).
* [S3 Console](https://console.aws.amazon.com/s3)
* [EC2 Console](https://console.aws.amazon.com/ec2/)
* [ECS Console](https://console.aws.amazon.com/ecs/)
* [SQS Console](https://console.aws.amazon.com/sqs/)
* [CloudWatch Console](https://console.aws.amazon.com/cloudwatch/)
107 changes: 54 additions & 53 deletions documentation/DS-documentation/step_0_prep.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,71 @@
# Step 0: Prep
There are two classes of AWS resources that Distributed-Something interacts with: 1) infrastructure that is made once per AWS account to enable any Distributed-Something implementation to run and 2) infrastructure that is made and destroyed with every run.
This section describes the creation of the first class of AWS infrastructure and only needs to be followed once per account.

Distributed-Something runs many parallel jobs in EC2 instances that are automatically managed by ECS.
To get jobs started, a control node to submit jobs and monitor progress is needed.
This section describes what you need in AWS and in the control node to get started.
This guide only needs to be followed once per account.
(Though we recommend each user has their own control node, further control nodes can be created from an AMI after this guide has been followed to completion once.)

## 1. AWS Configuration

The AWS resources involved in running Distributed-Something can be primarily configured using the [AWS Web Console](https://aws.amazon.com/console/).
The architecture of Distributed-Something is based in the [worker pattern](https://web.archive.org/web/20220116213859/https://aws.amazon.com/blogs/compute/better-together-amazon-ecs-and-aws-lambda/) for distributed systems.
We have adapted and simplified that architecture for Distributed-Something.
## AWS Configuration
The AWS resources involved in running Distributed-Something are configured using the [AWS Web Console](https://aws.amazon.com/console/) and a setup script we provide ([setup_AWS.py](../../setup_AWS.py)).
You need an active AWS account configured to proceed.
Login into your AWS account, and make sure the following list of resources is created:

You need an active account configured to proceed. Login into your AWS account, and make sure the following list of resources is created:

### 1.1 Access keys
* Get [security credentials](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html) for your account.
### 1.1 Manually created resources
* **Security Credentials**: Get [security credentials](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html) for your account.
Store your credentials in a safe place that you can access later.
* You will probably need an ssh key to login into your EC2 instances (control or worker nodes).
* **SSH Key**: You will probably need an ssh key to login into your EC2 instances (control or worker nodes).
[Generate an SSH key](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html) and store it in a safe place for later use.
If you'd rather, you can generate a new key pair to use for this during creation of the control node; make sure to `chmod 600` the private key when you download it.

### 1.2 Roles and permissions
* You can use your default VPC, subnet, and security groups; you should add an inbound SSH connection from your IP address to your security group.
* [Create an ecsInstanceRole](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/instance_IAM_role.html) with appropriate permissions (An S3 bucket access policy CloudWatchFullAccess, CloudWatchActionEC2Access, AmazonEC2ContainerServiceforEC2Role policies, ec2.amazonaws.com as a Trusted Entity)
* [Create an aws-ec2-spot-fleet-tagging-role](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-requests.html) with appropriate permissions (just needs AmazonEC2SpotFleetTaggingRole); ensure that in the "Trust Relationships" tab it says "spotfleet.amazonaws.com" rather than "ec2.amazonaws.com" (edit this if necessary).
In the current interface, it's easiest to click "Create role", select "EC2" from the main service list, then select "EC2- Spot Fleet Tagging".
* **SSH Connection**: You can use your default AWS account VPC, subnet, and security groups.
You should add an inbound SSH connection from your IP address to your security group.

### 1.2 Automatically created resources
* Run setup_AWS by entering `python setup_AWS.py` from your command line.
It will automatically create:
* an [ecsInstanceRole](http://docs.aws.amazon.com/AmazonECS/latest/developerguide/instance_IAM_role.html) with appropriate permissions.
This role is used by the EC2 instances generated by your spot fleet request and coordinated by ECS.
* an [aws-ec2-spot-fleet-tagging-role](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-fleet-requests.html) with appropriate permissions.
This role grants the Spot Fleet the permissions to request, launch, terminate, and tag instances.
* an SNS topic that is used for triggering the auto-Monitor.
* a Monitor lambda function that is used for auto-monitoring of your runs (see [Step 4: Monitor](step_4_monitor.md) for more information).

### 1.3 Auxiliary Resources
*You can certainly configure Distributed-Something for use without S3, but most DS implementations use S3 for storage.*
* [Create an S3 bucket](http://docs.aws.amazon.com/AmazonS3/latest/gsg/CreatingABucket.html) and upload your data to it.
* Add permissions to your bucket so that [logs can be exported to it](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/S3ExportTasksConsole.html) (Step 3, first code block)

### 1.4 Primary Resources
The following five are the primary resources that Distributed-Something interacts with.
After you have finished preparing for Distributed-Something (this guide), you do not need to directly interact with any of these services outside of Distributed-Something.
If you would like a granular view of [what Distributed-Something is doing while it runs](overview_2.md), you can open each console in a separate tab in your browser and watch their individual behaviors, though this is not necessary, especially if you run the [monitor command](step_4_monitor.md).
* [S3 Console](https://console.aws.amazon.com/s3)
* [EC2 Console](https://console.aws.amazon.com/ec2/)
* [ECS Console](https://console.aws.amazon.com/ecs/)
* [SQS Console](https://console.aws.amazon.com/sqs/)
* [CloudWatch Console](https://console.aws.amazon.com/cloudwatch/)

### 1.5 Spot Limits
Add permissions to your bucket so that [logs can be exported to it](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/S3ExportTasksConsole.html) (Step 3, first code block).

### 1.4 Increase Spot Limits
AWS initially [limits the number of spot instances](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-limits.html) you can use at one time; you can request more through a process in the linked documentation.
Depending on your workflow (your scale and how you group your jobs), this may not be necessary.

## 2. The Control Node
The control node can be your local machine if it is configured properly, or it can also be a small instance in AWS.
## The Control Node
The control node is a machine that is used for running the Distributed-Something scripts.
It can be your local machine, if it is configured properly, or it can also be a small instance in AWS.
We prefer to have a small EC2 instance dedicated to controlling our Distributed-Something workflows for simplicity of access and configuration.
To login in an EC2 machine you need an ssh key that can be generated in the web console.
To login in an EC2 machine you need an SSH key that can be generated in the web console.
Each time you launch an EC2 instance you have to confirm having this key (which is a .pem file).
This machine is needed only for submitting jobs, and does not have any special computational requirements, so you can use a micro instance to run basic scripts to proceed.
(Though we recommend each user has their own control node, further control nodes can be created from an AMI after this guide has been followed to completion once.)

The control node needs the following tools to successfully run Distributed-Something.
Here we assume you are using the command line in a Linux machine, but you are free to try other operating systems too.
These instructions assume you are using the command line in a Linux machine, but you are free to try other operating systems too.

### 2.1 Make your own
### Create Control Node from Scratch
#### 2.1 Install Python 3.8 or higher and pip
Most scripts are written in Python and support Python 3.8 and 3.9.
Follow installation instructions for your platform to install Python.
pip should be included with the installation of Python 3.8 or 3.9, but if you do not have it installed, install pip.

#### 2.1.1 Clone this repo
#### 2.2 Clone this repository and install requirements
You will need the scripts in Distributed-Something locally available in your control node.
<pre>
sudo apt-get install git
git clone https://github.com/DistributedScience/Distributed-Something.git
cd Distributed-Something/
git pull
</pre>

#### 2.1.2 Python 3.8 or higher and pip
Most scripts are written in Python and support Python 3.8 and 3.9.
Follow installation instructions for your platform to install python and, if needed, pip.
After Python has been installed, you need to install the requirements for Distributed-Something following this steps:

<pre>
cd Distributed-Something/files
# install requirements
cd files
sudo pip install -r requirements.txt
</pre>

#### 2.1.3 AWS CLI
#### 2.3 Install AWS CLI
The command line interface is the main mode of interaction between the local node and the resources in AWS.
You need to install [awscli](http://docs.aws.amazon.com/cli/latest/userguide/installing.html) for Distributed-Something to work properly:

Expand All @@ -86,14 +75,26 @@ You need to install [awscli](http://docs.aws.amazon.com/cli/latest/userguide/ins
aws configure
</pre>

When running the last step, you will need to enter your AWS credentials.
When running the last step (`aws configure`), you will need to enter your AWS credentials.
Make sure to set the region correctly (i.e. us-west-1 or eu-east-1, not eu-west-2a), and set the default file type to json.

#### 2.1.4 s3fs-fuse (optional)
[s3fs-fuse](https://github.com/s3fs-fuse/s3fs-fuse) allows you to mount your s3 bucket as a pseudo-file system.
It does not have all the performance of a real file system, but allows you to easily access all the files in your s3 bucket.
Follow the instructions at the link to mount your bucket.

#### 2.1.5 Create Control Node AMI (optional)
### Create Control Node from AMI (optional)
Once you've set up the other software (and gotten a job running, so you know everything is set up correctly), you can use Amazon's web console to set this up as an Amazon Machine Instance, or AMI, to replicate the current state of the hard drive.
Create future control nodes using this AMI so that you don't need to repeat the above installation.

## Removing long-term infrastructure
If you decide that you never want to run Distributed-Something again and would like to remove the long-term infrastructure, follow these steps.

### Remove Roles, Lambda Monitor, and Monitor SNS
<pre>
python setup_AWS.py destroy
</pre>

### Remove EC2 Control node
If you made your control node as an EC2 instance, while in the AWS console, select the instance.
Select `Instance state` => `Terminate instance`.
Loading

0 comments on commit 102fd32

Please sign in to comment.