This script deploys code to EC2 in a single step, as simply as possible. It is written with Windows users in mind, but should work for Unix (Mac OS X) as well (not yet tested). Full explanation in this Medium article.
What the script does not do is manage your cloud infrastructure. It is just a one-off script to get your code in the cloud and running, ASAP. In order to terminate or manage your resources, you will need to do that manually or write your own script. For higher-level ways to automate your cloud infrastructure, look into Ansible, Terraform, or pyinfra.
The default code in /upload is a bitcoin moving average crossover algorithm for Coinbase Pro, written up in this post.
- Have AWS account set up. This code works with free tier, but you'll still need to input payment information.
- This free script assumes you've already run EC2 at least once (it uses the default VPC and subnet from previous set up).
- Install AWS CLI. Direct download (for Windows).
- Configure AWS CLI. Quickstart
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: json
- Install paramiko
pip install paramiko - Clone repo
git clone https://github.com/samchaaa/ec2deploy.git - Replace default values with your own. Relevant values:
ec2deploy.py
region(line 29) It is important this matches your AWS account, otherwise everything else will break!to_execute(line 35) By default this isbtc_algo.py, you can leave this the same or replace with your own script in/upload.
btc_algo.py If you do use the default algo in /upload, replace with your Coinbase Pro credentials. Credentials must have 'View' and 'Trade' authorized.
api_key(line 7)passphrase(line 8)secret(line 9)
- Navigate to repo in cmd
python ec2deploy.py- That's it!
The script uses the python library subprocess to make calls to AWS CLI in python.
It gets your default VPC, the subnet associated with that VPC, creates a new security group, generates a new key pair, then starts an EC2 instance.
Then using the python library paramiko the script connects to your ec2 instance (once it finishes starting up) and transfers your code to EC2.
Finally, the script unzips and runs your code in a detached screen before closing the connection.
Subscribe to my Substack for additional code (including creating fresh VPC, fresh substack, and quitting your python process on EC2) and future extensions.