I am trying to use describe_target_health api of BOTO3 to get Target Details under some account. API Response is like below
{
"TargetHealthDescriptions": [
{
"Target": {
"Id": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
"AvailabilityZone": "all",
},
"TargetHealth": {
"State": "unavailable",
"Reason": "Target.HealthCheckDisabled",
"Description": "Health checks are not enabled for this target"
}
}
"Target": {
"Id": "arn:aws:lambda:us-west-2:213242434:function:my-function",
"AvailabilityZone": "all",
},
"TargetHealth": {
"State": "unavailable",
"Reason": "Target.HealthCheckDisabled",
"Description": "Health checks are not enabled for this target"
}
}
]
}
Trying to fetch all Target Id from above response like below
for tg in tg_arn_list:
response=lb_client.describe_target_health(TargetGroupArn=tg)
# print("---PRINTING RESPONSE---")
# print(response4)
tg_dict={}
for t in response['TargetHealthDescriptions']:
tg_main_list.append({
"Id":t['Target'].get("Id","NA"),
"HealthCheckPort1":t['Target'].get("Port","NA"),
"TargetHealth":t['TargetHealth'].get("State","NA"),
"TargetGroupArn":tg
})
But this loop is skipping 1st Target only fetching Target 2, can someone help with required changes to be done in code.