

# Workflow environments in Amazon SageMaker Unified Studio
<a name="workflow-environments"></a>

Use a shared workflow environment to share workflows with other project members. You have two options for setting up a workflow environment in your project:
+ **Create a new workflow environment** – Create a new Amazon MWAA environment that Amazon SageMaker Unified Studio provisions and manages for you. Use this option when you do not have an existing Amazon MWAA environment.
+ **Connect an existing Amazon Managed Workflows for Apache Airflow (Amazon MWAA) environment** – Connect an Amazon MWAA environment that you already manage in your AWS account. Use this option when you want to use an existing environment with Amazon SageMaker Unified Studio workflows.

Only one workflow environment can exist in a project at a time. To update or delete a workflow environment, you must be an owner of the project that the workflow environment is in. After a project owner creates or connects a workflow environment, any project member can sync their files to share them in the environment.
+ [Create a workflow environment](#create-workflow-environment)
+ [Connect an existing Amazon MWAA environment](#connect-existing-mwaa)
+ [Update a workflow environment](#update-workflow-environment)
+ [Delete a workflow environment](#delete-workflow-environment)

## Connect an existing Amazon MWAA environment
<a name="connect-existing-mwaa"></a>

You can connect an existing Amazon Managed Workflows for Apache Airflow (Amazon MWAA) environment to your Amazon SageMaker Unified Studio project. Use your existing MWAA environment to run and monitor workflows directly from Amazon SageMaker Unified Studio.

### Prerequisites
<a name="connect-existing-mwaa-prerequisites"></a>

Before you connect an existing Amazon MWAA environment, make sure that you meet the following requirements:
+ You are a project owner or project contributor in the project (managed in project members).
+ You have an existing Amazon MWAA environment in your AWS account.
+ The environment runs Airflow 2.x or later for running and monitoring workflows. To use the visual authoring experience (the **Create workflow** button in **Workflows**), Airflow 3 or later is required.
+ The MWAA environment execution role has the required IAM permissions to interact with Amazon SageMaker Unified Studio. Attach the following policy to the execution role of your MWAA environment:

  ```
  {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Sid": "DataZoneAccess",
        "Effect": "Allow",
        "Action": [
          "datazone:ListEnvironmentBlueprints",
          "datazone:ListEnvironments",
          "datazone:GetEnvironment"
        ],
        "Resource": "*"
      },
      {
        "Sid": "SageMakerAndReadActions",
        "Effect": "Allow",
        "Action": [
          "ec2:DescribeInstanceTypes",
          "ssm:GetParameter",
          "sagemaker:AddTags",
          "sagemaker:ListTags",
          "sagemaker:CreateTrainingJob",
          "sagemaker:DescribeTrainingJob"
        ],
        "Resource": "*"
      },
      {
        "Sid": "PassRoleToSageMaker",
        "Effect": "Allow",
        "Action": "iam:PassRole",
        "Resource": "arn:aws:iam::<account-id>:role/<project-role-name>",
        "Condition": {
          "StringEquals": {
            "iam:PassedToService": "sagemaker.amazonaws.com"
          }
        }
      }
    ]
  }
  ```

  Replace `<account-id>` with your AWS account ID and `<project-role-name>` with the name of your SageMaker Unified Studio project role.

### Configure your MWAA environment for Amazon SageMaker Unified Studio
<a name="connect-existing-mwaa-configure"></a>

You must add Airflow configuration options to your MWAA environment so that it can connect to your Amazon SageMaker Unified Studio project.

1. Open the Amazon MWAA console and navigate to your environment.

1. Choose **Edit** to edit the environment configuration.

1. In the **Airflow configuration options** section, add the following three key-value pairs:
   + `workflows.datazone_domain_id` – The ID of your DataZone domain.
   + `workflows.datazone_domain_region` – The region of your DataZone domain (for example, `us-west-2`).
   + `workflows.datazone_project_id` – The ID of your DataZone project.

1. Choose **Save**.

1. Wait for the environment status to change to **Available** before proceeding.

### Connect the environment in Amazon SageMaker Unified Studio
<a name="connect-existing-mwaa-steps"></a>

After you configure your MWAA environment, connect it to your Amazon SageMaker Unified Studio project.

1. Navigate to Amazon SageMaker Unified Studio using the URL from your admin and log in using your SSO or AWS credentials. 

1. Navigate to a project that was created with the **Data analytics and AI-ML model development** project profile. To do this, choose a project from the project selector dropdown at the top of the page.

1. In the left navigation pane, choose **Compute**.

1. On the **Workflow environments** tab, choose **Connect**.

1. Choose the MWAA environment that you configured in the preceding steps.

1. Choose **Connect workflow environment**.

## Create a workflow environment
<a name="create-workflow-environment"></a>

To create a workflow environment, you must be an owner of the project that you want to create a workflow environment in.

To create a workflow environment, complete the following steps:

1. Navigate to Amazon SageMaker Unified Studio using the URL from your admin and log in using your SSO or AWS credentials. 

1. Navigate to a project that was created with the **Data analytics and AI-ML model development** project profile. To do this, choose a project from the project selector dropdown at the top of the page.

1. In the left navigation pane, choose **Compute**.

1. On the **Workflow environments** tab, confirm that there are no workflow environments in the project yet. Then choose **Create**.

1. In the **Create workflow environment** window, review the parameters of the workflow environment. These are determined by your admin. If you want any of these parameters to change, contact your admin.

1. Choose **Create workflow environment**.

**Note**  
Workflow environment creation takes several minutes to complete.

## Update a workflow environment
<a name="update-workflow-environment"></a>

To update a workflow environment, you must be an owner of the project that you want to update a workflow environment in.

To update a workflow environment, complete the following steps:

1. Navigate to Amazon SageMaker Unified Studio using the URL from your admin and log in using your SSO or AWS credentials. 

1. Navigate to the project that contains the workflow environment that you want to update. To do this, choose a project from the project selector dropdown at the top of the page.

1. In the left navigation pane, choose **Compute**.

1. On the **Workflow environments** tab, expand the **Actions** menu and choose **Update**.

1. Choose **Update workflow environment**.

**Note**  
Updating a workflow environment takes several minutes to complete.

## Delete a workflow environment
<a name="delete-workflow-environment"></a>

To delete a workflow environment, you must be an owner of the project that contains the workflow environment that you want to delete.

To delete a workflow environment, complete the following steps:

1. Navigate to Amazon SageMaker Unified Studio using the URL from your admin and log in using your SSO or AWS credentials. 

1. Navigate to the project that contains the workflow environment that you want to delete. To do this, choose a project from the project selector dropdown at the top of the page.

1. In the left navigation pane, choose **Compute**.

1. On the **Workflow environments** tab, expand the **Actions** menu and choose **Delete**.

1. Confirm the action by typing `confirm`, then choose **Delete workflow environment**.

**Note**  
Deleting a workflow environment takes several minutes to complete.