def get_or_create_instance_profile(boto_iam, boto_ec2, instanceRoleName,
                                   instanceProfileName):
    """
    Find an instance profile named instanceProfileName, or create one and attach
    instanceRoleName to it.
    """

    response = None
    try:
        response = boto_iam.get_instance_profile(
            InstanceProfileName=instanceProfileName)

    except boto_iam.exceptions.NoSuchEntityException:
        response = boto_iam.create_instance_profile(
            InstanceProfileName=instanceProfileName)
        boto_iam.add_role_to_instance_profile(
            InstanceProfileName=instanceProfileName,
            RoleName=instanceRoleName,
        )

    return response['InstanceProfile']['Arn']