Skip to content

Python 3 library for retrieval and processing of Amazon EC2 Spot Price history data

License

Notifications You must be signed in to change notification settings

fstab50/spotlib

Repository files navigation


spotlib


Summary

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


Contents

--

back to the top


Dependencies

spotlib requires:

back to the top


Installation

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

back to the top


Use


Use / Spotlib Library

spotlib can be used most flexibly as an importable library:

  1. 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)
    
  2. Set custom endpoints (start & end date times, 10 days back from today):

    >>> start, end = sp.set_endpoints(duration=10)
  3. Retrieve spot price data for the custom time period for a particular region:

    >>> prices = sp.generate_pricedata(regions=['eu-west-1'])
  4. Examine price data returned:

    >>> from libtools.js import export_iterobject
    >>> export_iterobject(prices)

--

back to the top


Use / Spotcli Helper Application / Options

To display the help menu for spotcli, the included command line helper application:

    $ spotcli --help

--

back to the top


Use / Spotcli Helper Application / Data Retrieval (1 region)

To run a test of the spotlib library, retrieve spot price data and writeout to disk:

$ spotcli --duration-days 3 --region eu-west-1

--

back to the top


Use / Spotcli Helper Application / Data Retrieval (multi-region)

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

--

back to the top


IAM Permissions

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.

--

back to the top


Author & Copyright

All works contained herein copyrighted via below author unless work is explicitly noted by an alternate author.

  • Copyright Blake Huber, All Rights Reserved.

back to the top


License

  • 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

back to the top


Disclaimer

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.

back to the top


Releases

No releases published

Packages

No packages published