-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Add system test for Lambda executor Dead Letter Queue (DLQ) processing #54042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
vincbeck
merged 8 commits into
apache:main
from
aws-mwaa:iiruoha/add-lambda-executor-dlq-test
Aug 6, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b005886
Create lambda executor dlq system test file
isaiahiruoha 1817a74
Pre-commit changes for CI tests
isaiahiruoha c4c6191
Add DLQ to spellcheck
isaiahiruoha 19b7cbd
Adjusted spellling wordlist
isaiahiruoha bf07a60
Ignore system test related generated doc files
vincbeck 1ba1e66
Fix static checks
isaiahiruoha 3f584a6
Fix static checks
isaiahiruoha 1e93b4f
Fix doc building
vincbeck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -529,6 +529,9 @@ Dlp | |
| dlp | ||
| DlpJob | ||
| DlpServiceClient | ||
| DLQ | ||
| Dlq | ||
| dlq | ||
| dms | ||
| DNs | ||
| dns | ||
|
|
||
114 changes: 114 additions & 0 deletions
114
providers/amazon/tests/system/amazon/aws/tests/test_lambda_executor_dlq.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| # 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 | ||
|
|
||
| import os | ||
| import time | ||
| from datetime import datetime, timedelta, timezone | ||
| from urllib.parse import urlparse | ||
|
|
||
| import boto3 | ||
|
|
||
| from airflow.utils.trigger_rule import TriggerRule | ||
|
|
||
| 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, task | ||
| else: | ||
| from airflow.decorators import task # type: ignore[attr-defined,no-redef] | ||
| 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 SystemTestContextBuilder | ||
|
|
||
| sys_test_context_task = SystemTestContextBuilder().build() | ||
|
|
||
| DAG_ID = "test_lambda_executor_dlq" | ||
|
|
||
|
|
||
| @task | ||
| def verify_test_setup(): | ||
| """Verify Lambda executor DLQ configuration is available""" | ||
| dlq_url = os.environ.get("AIRFLOW__AWS_LAMBDA_EXECUTOR__DEAD_LETTER_QUEUE_URL") | ||
| print(f"Lambda executor DLQ URL: {dlq_url}") | ||
|
|
||
| parsed_url = urlparse(dlq_url) | ||
| dlq_queue_name = parsed_url.path.split("/")[-1] | ||
| return dlq_queue_name | ||
|
|
||
|
|
||
| # Configuration to search for this poison pill has been done within the Lambda app.py handler code | ||
| @task(executor_config={"poison_pill": True}) | ||
| def cause_lambda_failure(): | ||
| return "This task is designed to fail at Lambda service level, injected within the function handler" | ||
|
|
||
|
|
||
| @task(trigger_rule=TriggerRule.ALL_DONE) | ||
| def verify_dlq_activity(dlq_queue_name: str): | ||
| """Verify DLQ processing occurred by checking CloudWatch metrics""" | ||
|
|
||
| cloudwatch = boto3.client("cloudwatch") | ||
| # Try for up to 10 attempts (5 minutes total) | ||
| for attempt in range(10): | ||
| end_time = datetime.now(timezone.utc) | ||
| start_time = end_time - timedelta(minutes=5) | ||
| received_response = cloudwatch.get_metric_statistics( | ||
| Namespace="AWS/SQS", | ||
| MetricName="NumberOfMessagesDeleted", | ||
| Dimensions=[{"Name": "QueueName", "Value": dlq_queue_name}], | ||
| StartTime=start_time, | ||
| EndTime=end_time, | ||
| Period=300, | ||
| Statistics=["Sum"], | ||
| ) | ||
|
|
||
| total_deleted = sum(point["Sum"] for point in received_response["Datapoints"]) | ||
| if total_deleted > 0: | ||
| print(f"Messages deleted from DLQ: {total_deleted}") | ||
| return "DLQ Processing Confirmed" | ||
| print("No messages detected in DLQ yet") | ||
| if attempt < 9: | ||
| time.sleep(30) | ||
| raise AssertionError("FAIL: No DLQ activity detected after 5 minutes of polling") | ||
|
|
||
|
|
||
| with DAG( | ||
| dag_id=DAG_ID, | ||
| schedule="@once", | ||
| start_date=datetime(2021, 1, 1), | ||
| tags=["test"], | ||
| catchup=False, | ||
| ) as dag: | ||
| test_context = sys_test_context_task() | ||
| dlq_name = verify_test_setup() | ||
| failed_task = cause_lambda_failure() | ||
| verify_task = verify_dlq_activity(dlq_name) | ||
|
|
||
| chain( | ||
| test_context, | ||
| dlq_name, | ||
| failed_task, | ||
| verify_task, | ||
| ) | ||
| from tests_common.test_utils.watcher import watcher | ||
|
|
||
| verify_task >> watcher() | ||
|
|
||
| from tests_common.test_utils.system_tests import get_test_run # noqa: E402 | ||
|
|
||
| test_run = get_test_run(dag) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.