AWS List Reserved Instance Contracts

1). Install the AWS CLI for PowerShell

https://docs.aws.amazon.com/powershell/latest/userguide/pstools-getting-set-up-windows.html

Click Start > type PowerShell > right click run as Administrator

Run commands:

1
2
3
4
5
6
7
8
Install-Module -Name AWS.Tools.Installer
Install-Module -Name AWSPowerShell
Set-ExecutionPolicy RemoteSigned

Set-AWSCredential `
       -AccessKey 1234567890 `
       -SecretKey 1234567890 `
       -StoreAs UserX

2). Using the CLI
https://docs.aws.amazon.com/cli/latest/userguide/welcome-examples.html

3). Create the PowerShell Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#region Set Parameters

Param(
    # Run with the -profile_name flag to set the credentials to use
    [string]$profile_name = 'UserX',

    # Run with the -region flag select the data center
    [string]$region = 'us-east-1',

    # Run with the -output_file flag to set the output file name
    [string]$output_file = 'c:\Users\UserX\Desktop\ec2-reservations.csv'
)

#endregion

# query the API for a list of the reservations and save to CSV
# https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2ReservedInstance.html
Get-EC2ReservedInstance `
     -ProfileName $profile_name `
     -Region $region `
     -Filter @{Name="state";Values="active"} | `
  Select-Object ReservedInstancesId,InstanceType,ProductDescription,InstanceCount,FixedPrice,Start,End,OfferingType | `
  Export-Csv -Path $output_file

4). Describe the Reserved Instance Contracts

1
.\get-reservations.ps1 -profile_name UserX -region us-east-1 -output_file C:\Users\UserX\Desktop\res-east1.csv