Skip to content

Commit 5d358d2

Browse files
refactor(parameters): Consistently reference env (#319)
* refactor(parameters): Contistently reference env Use the defined constants to look up service name environment varialbe NOTE: This does not default to `service_undefined` * chore: bump ci * refactor: Apply suggestions from code review Co-authored-by: Heitor Lessa <heitor.lessa@hotmail.com> * fix: Add missing import * refactor: Use resolve_env_var_choice Co-authored-by: Heitor Lessa <heitor.lessa@hotmail.com>
1 parent 681ffd4 commit 5d358d2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

aws_lambda_powertools/tracing/tracer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
99

1010
from ..shared import constants
11-
from ..shared.functions import resolve_truthy_env_var_choice
11+
from ..shared.functions import resolve_env_var_choice, resolve_truthy_env_var_choice
1212
from ..shared.lazy_import import LazyLoader
1313
from .base import BaseProvider, BaseSegment
1414

@@ -720,7 +720,7 @@ def __build_config(
720720
):
721721
""" Populates Tracer config for new and existing initializations """
722722
is_disabled = disabled if disabled is not None else self._is_tracer_disabled()
723-
is_service = service if service is not None else os.getenv(constants.SERVICE_NAME_ENV)
723+
is_service = resolve_env_var_choice(choice=service, env=os.getenv(constants.SERVICE_NAME_ENV))
724724

725725
self._config["provider"] = provider or self._config["provider"] or aws_xray_sdk.core.xray_recorder
726726
self._config["auto_patch"] = auto_patch if auto_patch is not None else self._config["auto_patch"]

aws_lambda_powertools/utilities/parameters/appconfig.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from botocore.config import Config
1212

1313
from ...shared import constants
14+
from ...shared.functions import resolve_env_var_choice
1415
from .base import DEFAULT_PROVIDERS, BaseProvider
1516

1617
CLIENT_ID = str(uuid4())
@@ -68,7 +69,9 @@ def __init__(
6869

6970
config = config or Config()
7071
self.client = boto3.client("appconfig", config=config)
71-
self.application = application or os.getenv(constants.SERVICE_NAME_ENV, "service_undefined")
72+
self.application = resolve_env_var_choice(
73+
choice=application, env=os.getenv(constants.SERVICE_NAME_ENV, "service_undefined")
74+
)
7275
self.environment = environment
7376
self.current_version = ""
7477

docs/utilities/parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,4 @@ Here is the mapping between this utility's functions and methods and the underly
407407
| Secrets Manager | `SecretsManager.get` | `secretsmanager` | [get_secret_value](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/secretsmanager.html#SecretsManager.Client.get_secret_value) |
408408
| DynamoDB | `DynamoDBProvider.get` | `dynamodb` | ([Table resource](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#table)) | [get_item](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Table.get_item)
409409
| DynamoDB | `DynamoDBProvider.get_multiple` | `dynamodb` | ([Table resource](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#table)) | [query](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Table.query)
410-
| App Config | `get_app_config` | `appconfig` | [get_configuration](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfig.html#AppConfig.Client.get_configuration) |
410+
| App Config | `get_app_config` | `appconfig` | [get_configuration](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfig.html#AppConfig.Client.get_configuration) |

0 commit comments

Comments
 (0)