Skip to content

Commit 62a98f2

Browse files
author
Tom McCarthy
committed
feat: add environment variable to allow disabling idempotency functionality to make testing easier
1 parent b010ebf commit 62a98f2

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

aws_lambda_powertools/shared/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@
2121

2222
XRAY_SDK_MODULE: str = "aws_xray_sdk"
2323
XRAY_SDK_CORE_MODULE: str = "aws_xray_sdk.core"
24+
25+
IDEMPOTENCY_DISABLED_ENV: str = "POWERTOOLS_IDEMPOTENCY_DISABLED"

aws_lambda_powertools/utilities/idempotency/idempotency.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
"""
44
import functools
55
import logging
6+
import os
67
from typing import Any, Callable, Dict, Optional, cast
78

89
from aws_lambda_powertools.middleware_factory import lambda_handler_decorator
10+
from aws_lambda_powertools.shared.constants import IDEMPOTENCY_DISABLED_ENV
911
from aws_lambda_powertools.shared.types import AnyCallableT
1012
from aws_lambda_powertools.utilities.idempotency.base import IdempotencyHandler
1113
from aws_lambda_powertools.utilities.idempotency.config import IdempotencyConfig
@@ -56,6 +58,9 @@ def idempotent(
5658
>>> return {"StatusCode": 200}
5759
"""
5860

61+
if os.getenv(IDEMPOTENCY_DISABLED_ENV):
62+
return handler(event, context)
63+
5964
config = config or IdempotencyConfig()
6065
args = event, context
6166
idempotency_handler = IdempotencyHandler(
@@ -122,6 +127,9 @@ def process_order(customer_id: str, order: dict, **kwargs):
122127

123128
@functools.wraps(function)
124129
def decorate(*args, **kwargs):
130+
if os.getenv(IDEMPOTENCY_DISABLED_ENV):
131+
return function(*args, **kwargs)
132+
125133
payload = kwargs.get(data_keyword_argument)
126134

127135
if payload is None:

0 commit comments

Comments
 (0)