If anybody comes here looking for a pure bash solution.
Using jq to filter and parse the response of AWS CLI :
aws elb describe-load-balancers | jq -r '.LoadBalancerDescriptions[] | select(.Instances[].InstanceId == "<YOUR-INSTANCE-ID>") | .LoadBalancerName '
Also in aws-codedeploy-samples they define this function in common_functions.sh. I haven't tested it as I use ASG, but I suppose it will work
# Usage: get_elb_list <EC2 instance ID>
#
# Finds all the ELBs that this instance is registered to. After execution, the variable
# "INSTANCE_ELBS" will contain the list of load balancers for the given instance.
#
# If the given instance ID isn't found registered to any ELBs, the function returns non-zero
get_elb_list() {
local instance_id=$1
local elb_list=""
local all_balancers=$($AWS_CLI elb describe-load-balancers \
--query LoadBalancerDescriptions[*].LoadBalancerName \
--output text | sed -e $'s/\t/ /g')
for elb in $all_balancers; do
local instance_health
instance_health=$(get_instance_health_elb $instance_id $elb)
if [ $? == 0 ]; then
elb_list="$elb_list $elb"
fi
done
if [ -z "$elb_list" ]; then
return 1
else
msg "Got load balancer list of: $elb_list"
INSTANCE_ELBS=$elb_list
return 0
fi
}