StochSS-Compute on AWS¶
Install extra dependecies.
python -m pip install 'stochss_compute[AWS]'
# installs boto3, paramiko, and python-dotenv
Import necessary classes.
import gillespy2
from stochss_compute.cloud import EC2Cluster
from stochss_compute import RemoteSimulation
Launch an EC2 Instance. Make sure to check instance_type pricing before launching.
cluster = EC2Cluster()
cluster.launch_single_node_instace('t2.micro')
Run a simulation.
simulation = RemoteSimulation(model, server=cluster, solver=gillespy2.TauHybridSolver)
results = simulation.run()
results.plot()
Clean up.
cluster.clean_up()
AWS Configuration¶
Create an AWS account here if you have not already done so.
In order to make the AWS API calls to your account, you need an AWS access key and access key ID.
From the IAM dashboard, click ‘Manage access keys’.
Then, under the Access keys tab, click ‘Create New Access Key’.
This file can only be downloaded once, but if something happens you can just make a new one.
This file contains the Access Key ID and a Secret Access Key.
The simplest way to configure API calls is to download and install AWS Command Line Interface.
Then, run:
aws configure
You will be asked for your AWS Access Key ID, your AWS Secret Access Key, and default region name, such as ‘us-east-2’.
If you prefer not to install this, you can set the environment variables ‘AWS_ACCESS_KEY_ID’, ‘AWS_SECRET_ACCESS_KEY’, and ‘AWS_DEFAULT_REGION’.
For a full list of environment variables you can set, see here.
The stochss_compute AWS sub-package includes python-dotev which is handy for loading .env files into a python process.
from dotenv import load_dotenv
load_dotenv() # Loads from a file named .env by default