lib/cloudcost/aws.rb
#
#   Use the AWS Ruby SDK to get pricing data.
#
#   https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Pricing/Client.html#get_products-instance_method
#
#   get_products
#   describe_services
#
Use the AWS Ruby SDK to get pricing data.


Use the AWS Ruby SDK to get pricing data .
def collect_and_build(output_dir)
       files = []    
       files << get_products( 
            output_dir: output_dir,
            name: "storage-e1", 
            options: { 
                service_code: "AmazonEC2", 
                filters: [ 
                    { type: "TERM_MATCH", field: "productFamily",   value: "storage" },  
                    { type: "TERM_MATCH", field: "location", value: AWS_REGIONS['us-east-1'] }
                ]
            } 
        )
       files <<  get_products( 
            output_dir: output_dir,
            name: "linux-e1",     
            options: { 
                service_code: "AmazonEC2", 
                filters: [ 
                    { field: "operatingSystem",  type:  "TERM_MATCH",  value: "Linux", },
                    { field: "location",         type:  "TERM_MATCH",  value: AWS_REGIONS["us-east-1"], },
                    { field: "operation",        type:  "TERM_MATCH",  value: "RunInstances", },
                    { field: "capacitystatus",   type:  "TERM_MATCH",  value: "Used", },
                    { field: "preInstalledSw",   type:  "TERM_MATCH",  value: "NA", },
                    { field: "servicename",      type:  "TERM_MATCH",  value: "Amazon Elastic Compute Cloud", },
                    { field: "tenancy",          type:  "TERM_MATCH",  value: "Shared", }, 
                ] 
            }
        )
        files << get_products( 
            output_dir: output_dir,
            name: "windows-e1",     
            options: { 
                service_code: "AmazonEC2", 
                filters: [ 
                    { field: "operatingSystem",  type:  "TERM_MATCH",  value: "windows", },
                    { field: "licenseModel",     type:  "TERM_MATCH",  value: "No License required", },
                    { field: "location",         type:  "TERM_MATCH",  value: AWS_REGIONS["us-east-1"], },
                    { field: "capacitystatus",   type:  "TERM_MATCH",  value: "Used", },
                    { field: "preInstalledSw",   type:  "TERM_MATCH",  value: "NA", },
                    { field: "servicename",      type:  "TERM_MATCH",  value: "Amazon Elastic Compute Cloud", },
                    { field: "tenancy",          type:  "TERM_MATCH",  value: "Shared", }, 
                ] 
            }
        )
        merge_all_files('aws.json',files, output_dir)
    end
def collect_and_build ( output_dir ) files = [ ] files << get_products ( output_dir : output_dir , name : "storage-e1" , options : { service_code : "AmazonEC2" , filters : [ { type : "TERM_MATCH" , field : "productFamily" , value : "storage" } , { type : "TERM_MATCH" , field : "location" , value : AWS_REGIONS [ 'us-east-1' ] } ] } ) files << get_products ( output_dir : output_dir , name : "linux-e1" , options : { service_code : "AmazonEC2" , filters : [ { field : "operatingSystem" , type : "TERM_MATCH" , value : "Linux" , } , { field : "location" , type : "TERM_MATCH" , value : AWS_REGIONS [ "us-east-1" ] , } , { field : "operation" , type : "TERM_MATCH" , value : "RunInstances" , } , { field : "capacitystatus" , type : "TERM_MATCH" , value : "Used" , } , { field : "preInstalledSw" , type : "TERM_MATCH" , value : "NA" , } , { field : "servicename" , type : "TERM_MATCH" , value : "Amazon Elastic Compute Cloud" , } , { field : "tenancy" , type : "TERM_MATCH" , value : "Shared" , } , ] } ) files << get_products ( output_dir : output_dir , name : "windows-e1" , options : { service_code : "AmazonEC2" , filters : [ { field : "operatingSystem" , type : "TERM_MATCH" , value : "windows" , } , { field : "licenseModel" , type : "TERM_MATCH" , value : "No License required" , } , { field : "location" , type : "TERM_MATCH" , value : AWS_REGIONS [ "us-east-1" ] , } , { field : "capacitystatus" , type : "TERM_MATCH" , value : "Used" , } , { field : "preInstalledSw" , type : "TERM_MATCH" , value : "NA" , } , { field : "servicename" , type : "TERM_MATCH" , value : "Amazon Elastic Compute Cloud" , } , { field : "tenancy" , type : "TERM_MATCH" , value : "Shared" , } , ] } ) merge_all_files ( 'aws.json' , files , output_dir ) end
Use the AWS Ruby SDK to get pricing data.
Use the AWS Ruby SDK to get pricing data .
output_dir