john-jac commented on code in PR #66046: URL: https://github.com/apache/airflow/pull/66046#discussion_r3161946028
########## providers/amazon/tests/system/amazon/aws/example_mwaa_serverless.py: ########## @@ -0,0 +1,182 @@ +# 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.mwaa_serverless import ( + MwaaServerlessStartWorkflowRunOperator, +) +from airflow.providers.common.compat.sdk import DAG, chain + +from system.amazon.aws.utils import ENV_ID_KEY, SystemTestContextBuilder +from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS + +if AIRFLOW_V_3_0_PLUS: + from airflow.sdk import TriggerRule, task +else: + from airflow.decorators import task # type: ignore[attr-defined,no-redef] + from airflow.utils.trigger_rule import TriggerRule # type: ignore[no-redef,attr-defined] + +DAG_ID = "example_mwaa_serverless" + +# Valid MWAA Serverless YAML: tasks as mapping, FQN operators, flat parameters. +# This workflow runs an S3KeySensor that checks for the workflow YAML file itself. +WORKFLOW_YAML = """\ +systest_mwaa_serverless: + schedule: null + description: "System test: S3 key sensor on workflow definition" + tasks: + check_file: + task_id: check_file + operator: airflow.providers.amazon.aws.sensors.s3.S3KeySensor + bucket_name: {bucket} + bucket_key: workflow.yaml +""" + +sys_test_context_task = SystemTestContextBuilder().build() + +with DAG( + dag_id=DAG_ID, + schedule=None, + start_date=datetime(2024, 1, 1), + catchup=False, +) as dag: + test_context = sys_test_context_task() + env_id = test_context[ENV_ID_KEY] + bucket_name = f"{env_id}-mwaa-sl" + + @task + def create_bucket_and_workflow(bucket: str) -> str: + """Create S3 bucket with workflow YAML, IAM role, and MWAA Serverless workflow.""" + import json + import time + + import boto3 + + s3 = boto3.client("s3") + s3.create_bucket(Bucket=bucket) + s3.put_object( + Bucket=bucket, + Key="workflow.yaml", + Body=WORKFLOW_YAML.format(bucket=bucket).encode(), + ) + + iam = boto3.client("iam") + role_name = f"{bucket}-role" + trust = json.dumps( + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Principal": {"Service": "airflow-serverless.amazonaws.com"}, + "Action": "sts:AssumeRole", + } + ], + } + ) + try: + role_arn = iam.create_role(RoleName=role_name, AssumeRolePolicyDocument=trust)[ Review Comment: Taking a look now at that sample to incorporate that guidance. Thanks! -- 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]
