This is an automated email from the ASF dual-hosted git repository.

o-nikolas pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 8529c41db15 Add environment_variables to MWAA Serverless create/update 
workflow operators (#76496)
8529c41db15 is described below

commit 8529c41db1538a635cef470aa7a102abced4cd2e
Author: Bhuvana Komati <[email protected]>
AuthorDate: Thu Nov 5 10:04:58 2026 -0800

    Add environment_variables to MWAA Serverless create/update workflow 
operators (#76496)
    
    The MWAA Serverless CreateWorkflow and UpdateWorkflow APIs now accept an
    Environment field ({"Variables": {str: str}}) to set environment variables
    for tasks in a workflow. Expose it on MwaaServerlessCreateWorkflowOperator
    and MwaaServerlessUpdateWorkflowOperator as a templated
    `environment_variables` parameter.
    
    Requires botocore>=1.43.124, the first release whose mwaa-serverless model
    includes Environment.
---
 .../amazon/aws/operators/mwaa_serverless.py        | 21 +++++++++
 .../amazon/aws/operators/test_mwaa_serverless.py   | 52 ++++++++++++++++++++++
 2 files changed, 73 insertions(+)

diff --git 
a/providers/amazon/src/airflow/providers/amazon/aws/operators/mwaa_serverless.py
 
b/providers/amazon/src/airflow/providers/amazon/aws/operators/mwaa_serverless.py
index d0f8883c90d..0ecaeda3977 100644
--- 
a/providers/amazon/src/airflow/providers/amazon/aws/operators/mwaa_serverless.py
+++ 
b/providers/amazon/src/airflow/providers/amazon/aws/operators/mwaa_serverless.py
@@ -103,6 +103,10 @@ class 
MwaaServerlessCreateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
         optionally ``VersionId``. (templated)
     :param role_arn: The execution role ARN. (templated)
     :param description: Optional description. (templated)
+    :param environment_variables: Optional mapping of environment variable 
names to values
+        to set for tasks in the workflow. Sent to the API as 
``Environment.Variables``.
+        If not specified, the workflow has no environment variables. Requires
+        ``botocore>=1.43.124``. (templated)
     :param tags: Optional tags dict.
     :param create_workflow_kwargs: Optional parameters to pass to the 
``CreateWorkflow`` API for
         inputs this operator does not expose, such as ``NetworkConfiguration``,
@@ -119,11 +123,13 @@ class 
MwaaServerlessCreateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
         "code",
         "role_arn",
         "description",
+        "environment_variables",
         "create_workflow_kwargs",
     )
     template_fields_renderers = {
         "definition_s3_location": "json",
         "code": "json",
+        "environment_variables": "json",
         "create_workflow_kwargs": "json",
     }
 
@@ -135,6 +141,7 @@ class 
MwaaServerlessCreateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
         code: dict[str, Any] | None = None,
         role_arn: str,
         description: str | None = None,
+        environment_variables: dict[str, str] | None = None,
         tags: dict[str, str] | None = None,
         create_workflow_kwargs: dict[str, Any] | None = None,
         if_exists: Literal["fail", "skip"] = "skip",
@@ -146,6 +153,7 @@ class 
MwaaServerlessCreateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
         self.code = code
         self.role_arn = role_arn
         self.description = description
+        self.environment_variables = environment_variables
         self.tags = tags
         self.create_workflow_kwargs = create_workflow_kwargs or {}
         self.if_exists = if_exists
@@ -166,6 +174,8 @@ class 
MwaaServerlessCreateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
                 "Tags": self.tags,
             }
         )
+        if self.environment_variables is not None:
+            kwargs["Environment"] = {"Variables": self.environment_variables}
         try:
             response = self.hook.conn.create_workflow(**kwargs, 
**self.create_workflow_kwargs)
             workflow_arn = response["WorkflowArn"]
@@ -200,6 +210,11 @@ class 
MwaaServerlessUpdateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
         optionally ``VersionId``. (templated)
     :param role_arn: The execution role ARN. (templated)
     :param description: Optional updated description. (templated)
+    :param environment_variables: Optional mapping of environment variable 
names to values
+        to set for tasks in the workflow. Sent to the API as 
``Environment.Variables``.
+        The variables specified replace all existing environment variables of 
the workflow;
+        if not specified, the updated workflow has no environment variables. 
Requires
+        ``botocore>=1.43.124``. (templated)
     :param update_workflow_kwargs: Optional parameters to pass to the 
``UpdateWorkflow`` API for
         inputs this operator does not expose, such as ``NetworkConfiguration``,
         ``LoggingConfiguration``, ``EngineVersion`` and ``TriggerMode``. 
(templated)
@@ -212,11 +227,13 @@ class 
MwaaServerlessUpdateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
         "code",
         "role_arn",
         "description",
+        "environment_variables",
         "update_workflow_kwargs",
     )
     template_fields_renderers = {
         "definition_s3_location": "json",
         "code": "json",
+        "environment_variables": "json",
         "update_workflow_kwargs": "json",
     }
 
@@ -228,6 +245,7 @@ class 
MwaaServerlessUpdateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
         code: dict[str, Any] | None = None,
         role_arn: str,
         description: str | None = None,
+        environment_variables: dict[str, str] | None = None,
         update_workflow_kwargs: dict[str, Any] | None = None,
         **kwargs,
     ) -> None:
@@ -237,6 +255,7 @@ class 
MwaaServerlessUpdateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
         self.code = code
         self.role_arn = role_arn
         self.description = description
+        self.environment_variables = environment_variables
         self.update_workflow_kwargs = update_workflow_kwargs or {}
 
     @property
@@ -254,6 +273,8 @@ class 
MwaaServerlessUpdateWorkflowOperator(AwsBaseOperator[AwsBaseHook]):
                 "Description": self.description,
             }
         )
+        if self.environment_variables is not None:
+            kwargs["Environment"] = {"Variables": self.environment_variables}
         response = self.hook.conn.update_workflow(**kwargs, 
**self.update_workflow_kwargs)
         workflow_arn = response["WorkflowArn"]
         self.log.info("Workflow %s updated to version %s", workflow_arn, 
response.get("WorkflowVersion"))
diff --git 
a/providers/amazon/tests/unit/amazon/aws/operators/test_mwaa_serverless.py 
b/providers/amazon/tests/unit/amazon/aws/operators/test_mwaa_serverless.py
index 6937deded0c..471a3324e35 100644
--- a/providers/amazon/tests/unit/amazon/aws/operators/test_mwaa_serverless.py
+++ b/providers/amazon/tests/unit/amazon/aws/operators/test_mwaa_serverless.py
@@ -34,6 +34,7 @@ from unit.amazon.aws.utils.test_template_fields import 
validate_template_fields
 
 WORKFLOW_ARN = 
"arn:aws:mwaa-serverless:us-east-1:123456789012:workflow/test-workflow"
 RUN_ID = "run-abc123"
+ENVIRONMENT_VARIABLES = {"ENV": "prod", "LOG_LEVEL": "INFO"}
 
 
 class TestMwaaServerlessStartWorkflowRunOperator:
@@ -221,6 +222,29 @@ class TestMwaaServerlessCreateWorkflowOperator:
         )
         assert result == WORKFLOW_ARN
 
+    @mock.patch.object(AwsBaseHook, "conn", new_callable=mock.PropertyMock)
+    def test_execute_with_environment_variables(self, mock_conn):
+        op = MwaaServerlessCreateWorkflowOperator(
+            task_id="create_workflow",
+            workflow_name=WORKFLOW_NAME,
+            definition_s3_location=S3_LOCATION,
+            role_arn=ROLE_ARN,
+            environment_variables=ENVIRONMENT_VARIABLES,
+        )
+        mock_client = mock.MagicMock()
+        mock_client.create_workflow.return_value = {"WorkflowArn": 
WORKFLOW_ARN}
+        mock_conn.return_value = mock_client
+
+        result = op.execute({})
+
+        mock_client.create_workflow.assert_called_once_with(
+            Name=WORKFLOW_NAME,
+            DefinitionS3Location=S3_LOCATION,
+            RoleArn=ROLE_ARN,
+            Environment={"Variables": ENVIRONMENT_VARIABLES},
+        )
+        assert result == WORKFLOW_ARN
+
     def test_template_fields(self):
         validate_template_fields(self.operator)
 
@@ -280,6 +304,34 @@ class TestMwaaServerlessUpdateWorkflowOperator:
         )
         assert result == WORKFLOW_ARN
 
+    @mock.patch.object(AwsBaseHook, "conn", new_callable=mock.PropertyMock)
+    @pytest.mark.parametrize("environment_variables", [ENVIRONMENT_VARIABLES, 
{}])
+    def test_execute_with_environment_variables(self, mock_conn, 
environment_variables):
+        op = MwaaServerlessUpdateWorkflowOperator(
+            task_id="update_workflow",
+            workflow_arn=WORKFLOW_ARN,
+            definition_s3_location=S3_LOCATION,
+            role_arn=ROLE_ARN,
+            environment_variables=environment_variables,
+        )
+        mock_client = mock.MagicMock()
+        mock_client.update_workflow.return_value = {
+            "WorkflowArn": WORKFLOW_ARN,
+            "WorkflowVersion": "ghi789",
+            "ModifiedAt": "2026-05-12T00:00:00Z",
+        }
+        mock_conn.return_value = mock_client
+
+        result = op.execute({})
+
+        mock_client.update_workflow.assert_called_once_with(
+            WorkflowArn=WORKFLOW_ARN,
+            DefinitionS3Location=S3_LOCATION,
+            RoleArn=ROLE_ARN,
+            Environment={"Variables": environment_variables},
+        )
+        assert result == WORKFLOW_ARN
+
     @mock.patch.object(AwsBaseHook, "conn", new_callable=mock.PropertyMock)
     def test_execute_not_found(self, mock_conn):
         mock_client = mock.MagicMock()

Reply via email to