code: def get_instance_aws_context(ec2_client):
    
    result = {}
    try:
      result["region"] = http_get_metadata("placement/availability-zone/")
      result["region"] = result["region"][:-1]
      result["instance_id"] = http_get_metadata('instance-id')
    except IOError as error:
      raise IOError("Error looking up metadata:availability-zone or instance-id: " + repr(error))
    try:
      instance_desc = ec2_client.describe_instances(InstanceIds=[result["instance_id"]])
    except Exception as error:
      raise IOError("Error calling describe_instances: " + repr(error))
    result["account"] = instance_desc["Reservations"][0]["OwnerId"]
    arn = instance_desc["Reservations"][0]["Instances"][0]["IamInstanceProfile"]["Arn"]
    result["role"] = arn.split(":")[5].split("/")[1]
    env = re.search("^(" + EFConfig.VALID_ENV_REGEX + ")-", result["role"])
    if not env:
      raise IOError("Did not find environment in role name: " + result["role"])
    result["env"] = env.group(1)
    result["env_short"] = result["env"].strip(".0123456789")
    result["service"] = "-".join(result["role"].split("-")[1:])
    return result
docs: Returns: a dictionary of aws context
      dictionary will contain these entries:
      region, instance_id, account, role, env, env_short, service
    Raises: IOError if couldn't read metadata or lookup attempt failed