Python 3 library for retrieving historical spot prices from Amazon EC2 Service.
Internally, spotlib utilises a paged generator architecture to achieve maximum performance with non-blocking state transition.
Although spotlib was designed for maximum flexibility as a library, spotlib also includes a cli helper application, spotcli, a cli binary which can be used directly for retrieving spot price data simple use cases.
Version: 0.2.10
--
spotlib requires:
spotlib may be installed on Linux via pip, python package installer in one of two methods:
To install spotlib for a single user:
$ pip3 install spotlib --user
To install spotlib for all users (Linux):
$ sudo -H pip3 install spotlib
spotlib can be used most flexibly as an importable library:
-
Initial Setup: Default endpoints for data retreival is a period of 1 day
>>> from spotlib import SpotPrices, DurationEndpoints >>> sp = SpotPrices()
# Display datetime endpoints >>> sp.start datetime.datetime(2019, 9, 17, 0, 0) >>> sp.end datetime.datetime(2019, 9, 18, 0, 0)
-
Set custom endpoints (start & end date times, 10 days back from today):
>>> start, end = sp.set_endpoints(duration=10)
-
Retrieve spot price data for the custom time period for a particular region:
>>> prices = sp.generate_pricedata(regions=['eu-west-1'])
-
Examine price data returned:
>>> from libtools.js import export_iterobject >>> export_iterobject(prices)
--
To display the help menu for spotcli, the included command line helper application:
$ spotcli --help
--
To run a test of the spotlib library, retrieve spot price data and writeout to disk:
$ spotcli --duration-days 3 --region eu-west-1
--
To run a test of the spotlib library, retrieve spot price data and writeout to disk:
$ spotcli --duration-days 1 --region eu-west-1 eu-west-2 us-east-1
--
Either an Identity and Access Management user or role must be used to retrieve spot price data from AWS. The following is the minimum permissions required to retrieve data:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:DescribeSpotPriceHistory",
"ec2:DescribeRegions"
],
"Resource": "*"
}
]
}
Alternatively, if more permissive (but still read-only) permissions can be tolerated, the AWS Managed Policy 'AmazonEC2ReadOnlyAccess' can be used via the following ARN:
- arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess
The permissions above for IAM are a subset of the AmazonEC2ReadOnlyAccess policy. Either should work without problems.
--
All works contained herein copyrighted via below author unless work is explicitly noted by an alternate author.
- Copyright Blake Huber, All Rights Reserved.
- Software contained in this repo is licensed under the license agreement. You may display the license and copyright information by issuing the following command:
$ spotcli --version
Code is provided "as is". No liability is assumed by either the code's originating author nor this repo's owner for their use at AWS or any other facility. Furthermore, running function code at AWS may incur monetary charges; in some cases, charges may be substantial. Charges are the sole responsibility of the account holder executing code obtained from this library.
Additional terms may be found in the complete license agreement.