in Back-End/lambdas/receive_sqs_message.py [0:0]
def get_all_odcr(account_number, region, cross_account_role):
# Init
var_list = []
# Use boto3 on source account
client_ec2 = create_boto_client(
account_number, region, 'ec2', cross_account_role)
# Page all reservations
paginator = client_ec2.get_paginator('describe_capacity_reservations')
for page in paginator.paginate():
for i in page['CapacityReservations']:
if i['State'] == 'active':
var_list.append(
{
'EntryType': 'odcr',
'AccountNumber': str(account_number),
'Region': str(region),
'AvailabilityZone': str(i['AvailabilityZone']),
'AvailableInstanceCount': int(i['AvailableInstanceCount']),
'Id': str(i['CapacityReservationId']),
'Qty Available': str(f"{i['AvailableInstanceCount']} of {i['TotalInstanceCount']}"),
'CreateDate': str(i['CreateDate']),
'EbsOptimized': str(i['EbsOptimized']),
'EndDateType': str(i['EndDateType']),
'EphemeralStorage': str(i['EphemeralStorage']),
'InstanceMatchCriteria': str(i['InstanceMatchCriteria']),
'InstancePlatform': str(i['InstancePlatform']),
'InstanceType': str(i['InstanceType']),
'State': str(i['State']),
'Tags': str(i['Tags']),
'Tenancy': str(i['Tenancy']),
'TotalInstanceCount': int(i['TotalInstanceCount'])
})
return var_list