From a38c5751ccc65a0554ab32b97e350562d172abaf Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Mon, 8 Mar 2021 11:19:16 -0800 Subject: [PATCH 1/5] refactor(parameters): Contistently reference env Use the defined constants to look up service name environment varialbe NOTE: This does not default to `service_undefined` --- aws_lambda_powertools/utilities/parameters/appconfig.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/parameters/appconfig.py b/aws_lambda_powertools/utilities/parameters/appconfig.py index 75840be5e5e..a74801ccf0a 100644 --- a/aws_lambda_powertools/utilities/parameters/appconfig.py +++ b/aws_lambda_powertools/utilities/parameters/appconfig.py @@ -10,6 +10,7 @@ import boto3 from botocore.config import Config +from ...shared import constants from .base import DEFAULT_PROVIDERS, BaseProvider CLIENT_ID = str(uuid4()) @@ -33,6 +34,7 @@ class AppConfigProvider(BaseProvider): **Retrieves the latest configuration value from App Config** >>> from aws_lambda_powertools.utilities import parameters + >>> >>> appconf_provider = parameters.AppConfigProvider(environment="my_env", application="my_app") >>> >>> value : bytes = appconf_provider.get("my_conf") @@ -66,7 +68,7 @@ def __init__( config = config or Config() self.client = boto3.client("appconfig", config=config) - self.application = application or os.getenv("POWERTOOLS_SERVICE_NAME") or "application_undefined" + self.application = application or os.getenv(constants.SERVICE_NAME_ENV, "service_undefined") self.environment = environment self.current_version = "" From 0d30f0ef5e40ccd3207ec529da07b1ebaf330622 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Mon, 8 Mar 2021 11:29:58 -0800 Subject: [PATCH 2/5] chore: bump ci --- docs/utilities/parameters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/utilities/parameters.md b/docs/utilities/parameters.md index 5ca2395f264..9eab97105ed 100644 --- a/docs/utilities/parameters.md +++ b/docs/utilities/parameters.md @@ -407,4 +407,4 @@ Here is the mapping between this utility's functions and methods and the underly | 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) | | 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) | 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) -| App Config | `get_app_config` | `appconfig` | [get_configuration](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfig.html#AppConfig.Client.get_configuration) | +| App Config | `get_app_config` | `appconfig` | [get_configuration](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/appconfig.html#AppConfig.Client.get_configuration) | From be5f7319e0ffeb762486134d3328b5df2fe96110 Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Tue, 9 Mar 2021 06:38:48 -0800 Subject: [PATCH 3/5] refactor: Apply suggestions from code review Co-authored-by: Heitor Lessa --- aws_lambda_powertools/utilities/parameters/appconfig.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/parameters/appconfig.py b/aws_lambda_powertools/utilities/parameters/appconfig.py index a74801ccf0a..95225d03305 100644 --- a/aws_lambda_powertools/utilities/parameters/appconfig.py +++ b/aws_lambda_powertools/utilities/parameters/appconfig.py @@ -68,7 +68,7 @@ def __init__( config = config or Config() self.client = boto3.client("appconfig", config=config) - self.application = application or os.getenv(constants.SERVICE_NAME_ENV, "service_undefined") + self.application = resolve_env_var_choice(choice=application, env=os.getenv(constants.SERVICE_NAME_ENV, "service_undefined")) self.environment = environment self.current_version = "" From 3262d997d274cd7e1aba0892c915be67bc7a916d Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Tue, 9 Mar 2021 06:41:05 -0800 Subject: [PATCH 4/5] fix: Add missing import --- aws_lambda_powertools/utilities/parameters/appconfig.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aws_lambda_powertools/utilities/parameters/appconfig.py b/aws_lambda_powertools/utilities/parameters/appconfig.py index 95225d03305..8e10540b186 100644 --- a/aws_lambda_powertools/utilities/parameters/appconfig.py +++ b/aws_lambda_powertools/utilities/parameters/appconfig.py @@ -11,6 +11,7 @@ from botocore.config import Config from ...shared import constants +from ...shared.functions import resolve_env_var_choice from .base import DEFAULT_PROVIDERS, BaseProvider CLIENT_ID = str(uuid4()) @@ -68,7 +69,9 @@ def __init__( config = config or Config() self.client = boto3.client("appconfig", config=config) - self.application = resolve_env_var_choice(choice=application, env=os.getenv(constants.SERVICE_NAME_ENV, "service_undefined")) + self.application = resolve_env_var_choice( + choice=application, env=os.getenv(constants.SERVICE_NAME_ENV, "service_undefined") + ) self.environment = environment self.current_version = "" From 8a00c039ee8bd99926b1c993e7a54088f785a8fa Mon Sep 17 00:00:00 2001 From: Michael Brewer Date: Tue, 9 Mar 2021 06:46:21 -0800 Subject: [PATCH 5/5] refactor: Use resolve_env_var_choice --- aws_lambda_powertools/tracing/tracer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aws_lambda_powertools/tracing/tracer.py b/aws_lambda_powertools/tracing/tracer.py index f5b9ac92728..dd136998dfd 100644 --- a/aws_lambda_powertools/tracing/tracer.py +++ b/aws_lambda_powertools/tracing/tracer.py @@ -8,7 +8,7 @@ from typing import Any, Callable, Dict, List, Optional, Tuple, Union from ..shared import constants -from ..shared.functions import resolve_truthy_env_var_choice +from ..shared.functions import resolve_env_var_choice, resolve_truthy_env_var_choice from ..shared.lazy_import import LazyLoader from .base import BaseProvider, BaseSegment @@ -720,7 +720,7 @@ def __build_config( ): """ Populates Tracer config for new and existing initializations """ is_disabled = disabled if disabled is not None else self._is_tracer_disabled() - is_service = service if service is not None else os.getenv(constants.SERVICE_NAME_ENV) + is_service = resolve_env_var_choice(choice=service, env=os.getenv(constants.SERVICE_NAME_ENV)) self._config["provider"] = provider or self._config["provider"] or aws_xray_sdk.core.xray_recorder self._config["auto_patch"] = auto_patch if auto_patch is not None else self._config["auto_patch"]