1 Answer
- Newest
- Most votes
- Most comments
1
You can check the "InstanceType" and "cpu_options" with the following code.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2/client/describe_instances.html
Also, the function "instance.get()" does not exist, resulting in an error.
If the instance tag is not set, nothing will be output.
import json
import boto3
def lambda_handler(event, context):
s_region = "ap-northeast-1"
instance_ids = []
ec2 = boto3.client('ec2', region_name=s_region)
print(boto3.__version__)
print(" ")
response = ec2.describe_instances(InstanceIds=instance_ids)
instances_full_details = response['Reservations']
for instance_detail in instances_full_details:
group_instances = instance_detail['Instances']
for instance in group_instances:
instance_id = instance['InstanceId']
print("ID: " + instance_id)
print(instance['InstanceType'])
print(instance['CpuOptions'])
# s_temp = instance.get("InstanceType")
# print('InstanceType=' + s_temp)
# temp = instance.get("cpu_options")
# s_temp = str(temp.keys())