def METHOD_NAME(cfg: Config, min_healthy_percent: int, motd: str):
    """Refreshes an environment.
    This replaces all the instances in the ASGs associated with an environment with
    new instances (with the latest code), while ensuring there are some left to handle
    the traffic while we update."""
    set_update_message(cfg, motd)
    for asg in get_autoscaling_groups_for(cfg):
        group_name = asg["AutoScalingGroupName"]
        if asg["DesiredCapacity"] == 0:
            print(f"Skipping ASG {group_name} as it has a zero size")
            continue
        describe_state = as_client.describe_instance_refreshes(AutoScalingGroupName=group_name)
        existing_refreshes = [
            x for x in describe_state["InstanceRefreshes"] if x["Status"] in ("Pending", "InProgress")
        ]
        if existing_refreshes:
            refresh_id = existing_refreshes[0]["InstanceRefreshId"]
            print(f"  Found existing refresh {refresh_id} for {group_name}")
        else:
            if not are_you_sure(f"Refresh instances in {group_name} with version {describe_current_release(cfg)}", cfg):
                continue
            print("  Starting new refresh...")
            refresh_result = as_client.start_instance_refresh(
                AutoScalingGroupName=group_name, Preferences=dict(MinHealthyPercentage=min_healthy_percent)
            )
            refresh_id = refresh_result["InstanceRefreshId"]
            print(f"  id {refresh_id}")
        last_log = ""
        while True:
            time.sleep(5)
            describe_state = as_client.describe_instance_refreshes(
                AutoScalingGroupName=group_name, InstanceRefreshIds=[refresh_id]
            )
            refresh = describe_state["InstanceRefreshes"][0]
            status = refresh["Status"]
            if status == "InProgress":
                log = (
                    f"  {status}, {refresh['PercentageComplete']}%, "
                    f"{refresh['InstancesToUpdate']} to update. "
                    f"{refresh.get('StatusReason', '')}"
                )
            else:
                log = f"  Status: {status}"
            if log != last_log:
                print(log)
                last_log = log
            if status in ("Successful", "Failed", "Cancelled"):
                break
    set_update_message(cfg, "")