The content in this folder uses CDK to deploy the infrastructure, IAM roles and policies required to run a Sagemaker Notebook ready to fetch and display EC2 Spot historic prices using a Jupyter notebook. You can see how that notebook looks like here.
The easier way to setup and deploy your environment is using Cloud9 following this instructions.
- Create a Cloud9 environment :
- On the console run the following commands:
npm install -g --force aws-cdk
pip install virtualenv
git clone https://github.com/awslabs/ec2-spot-labs.git
cd $HOME/environment/ec2-spot-labs/ec2-spot-history-notebook/cdk
virtualenv .env
source .env/bin/activate
pip install -r requirements.txt
cdk deploy
Once you are done, you can destroy the cdk deployment and delete the cloud9 environment.
cdk destroy
Note the user you run this with, should be able to create Cloud9 environments create deploy CloudFormation stacks, add extra IAM roles and have access to Sagemaker.
To execute this project, you just need to follow the usual steps required to work with CDK projects. You can follow the CDK Getting Started page content, install node/npm and aws cdk.
The cdk.json
file tells the CDK Toolkit how to execute your app.
This project is set up like a standard Python project. There is also a .env
virtualenv directory. To create the virtualenv it assumes that there is a python3
(or python
for Windows) executable in your path with access to the venv
package. If for any reason the automatic creation of the virtualenv fails, you can create the virtualenv manually.
To manually create a virtualenv on MacOS and Linux:
$ python3 -m venv .env
After the init process completes and the virtualenv is created, you can use the following step to activate your virtualenv.
$ source .env/bin/activate
If you are a Windows platform, you would activate the virtualenv like this:
% .env\Scripts\activate.bat
Once the virtualenv is activated, you can install the required dependencies.
$ pip install -r requirements.txt
At this point you can now synthesize the CloudFormation template for this code.
$ cdk synth
Finally to drive the installation of the presentation
$ cdk deploy
Other useful cdk
commands:
cdk ls
list all stacks in the appcdk synth
emits the synthesized CloudFormation templatecdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk docs
open CDK documentation
By default CDK will use the default profile. To change the profile use the following command
before executing any of the cdk
commands.
$ export AWS_PROFILE=my_profile
By default the URL points to https://github.com/awslabs/ec2-spot-labs.git
You can modify the default repository to load by executing the following command
before executing any of the cdk
commands. This might be useful for example when working on Pull requests.
$ export AWS_SPOT_REPO="https://github.com/ruecarlo/ec2-spot-labs.git"
This will change the configuration to load the right repository.