qaziashikin commented on code in PR #62240: URL: https://github.com/apache/airflow/pull/62240#discussion_r2841916203
########## providers/amazon/tests/system/amazon/aws/example_sagemaker_unified_studio_notebook.py: ########## @@ -0,0 +1,130 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from datetime import datetime + +from airflow.providers.amazon.aws.operators.sagemaker_unified_studio_notebook import ( + SageMakerUnifiedStudioNotebookOperator, +) +from airflow.providers.amazon.aws.sensors.sagemaker_unified_studio_notebook import ( + SageMakerUnifiedStudioNotebookSensor, +) + +from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS + +if AIRFLOW_V_3_0_PLUS: + from airflow.sdk import DAG, chain +else: + from airflow.models.baseoperator import chain # type: ignore[attr-defined,no-redef] + from airflow.models.dag import DAG # type: ignore[attr-defined,no-redef,assignment] + +from system.amazon.aws.utils import ENV_ID_KEY, SystemTestContextBuilder + +""" +Prerequisites: The account which runs this test must have the following: +1. A SageMaker Unified Studio Domain (with default VPC and roles) +2. A project within the SageMaker Unified Studio Domain +3. A notebook asset registered in the project with a known notebook_id + +This test calls the DataZone StartNotebookRun / GetNotebookRun APIs directly +via boto3 using standard IAM credentials. No MWAA environment emulation is performed. +""" + +DAG_ID = "example_sagemaker_unified_studio_notebook" + +# Externally fetched variables: +DOMAIN_ID_KEY = "DOMAIN_ID" +PROJECT_ID_KEY = "PROJECT_ID" +NOTEBOOK_ID_KEY = "NOTEBOOK_ID" + +sys_test_context_task = ( + SystemTestContextBuilder() + .add_variable(DOMAIN_ID_KEY) + .add_variable(PROJECT_ID_KEY) + .add_variable(NOTEBOOK_ID_KEY) + .build() +) + +with DAG( + DAG_ID, + schedule="@once", + start_date=datetime(2021, 1, 1), + catchup=False, +) as dag: + test_context = sys_test_context_task() + + test_env_id = test_context[ENV_ID_KEY] + domain_id = test_context[DOMAIN_ID_KEY] + project_id = test_context[PROJECT_ID_KEY] + notebook_id = test_context[NOTEBOOK_ID_KEY] + + # [START howto_operator_sagemaker_unified_studio_notebook] + run_notebook = SageMakerUnifiedStudioNotebookOperator( + task_id="notebook-task", + notebook_id=notebook_id, # This should be the notebook asset identifier from within the SageMaker Unified Studio domain + domain_id=domain_id, + project_id=project_id, + client_token="unique-idempotency-token", # optional Review Comment: Makes sense, I will add some kind of unique identifier here since this is the example that ends up on the Airflow documentation - it would be good to include as an example of what parameters can be passed into the operator -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
