From 5fdcba13fdacf0a30effac9b500269ec6d0b3627 Mon Sep 17 00:00:00 2001 From: Leandro Damascena Date: Thu, 3 Oct 2024 22:48:16 +0100 Subject: [PATCH] Adding AWS_LAMBDA_INITIALIZATION_TYPE env var --- samcli/local/lambdafn/env_vars.py | 1 + tests/unit/local/lambdafn/test_env_vars.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/samcli/local/lambdafn/env_vars.py b/samcli/local/lambdafn/env_vars.py index ebf52ce5be..87d0ae280b 100644 --- a/samcli/local/lambdafn/env_vars.py +++ b/samcli/local/lambdafn/env_vars.py @@ -176,6 +176,7 @@ def _get_aws_variables(self): "AWS_ACCESS_KEY_ID": self.aws_creds.get("key", self._DEFAULT_AWS_CREDS["key"]), "AWS_SECRET_ACCESS_KEY": self.aws_creds.get("secret", self._DEFAULT_AWS_CREDS["secret"]), "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", } # Session Token should be added **only** if the input creds have a token and the value is not empty. diff --git a/tests/unit/local/lambdafn/test_env_vars.py b/tests/unit/local/lambdafn/test_env_vars.py index f831bfe61a..4259028de9 100644 --- a/tests/unit/local/lambdafn/test_env_vars.py +++ b/tests/unit/local/lambdafn/test_env_vars.py @@ -122,6 +122,7 @@ def test_with_no_additional_variables(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", "AWS_REGION": "some region", "AWS_DEFAULT_REGION": "some region", "AWS_ACCESS_KEY_ID": "some key", @@ -151,6 +152,7 @@ def test_with_only_default_values_for_variables(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", "AWS_REGION": "us-east-1", "AWS_ACCESS_KEY_ID": "defaultkey", "AWS_SECRET_ACCESS_KEY": "defaultsecret", @@ -184,6 +186,7 @@ def test_with_shell_env_value(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", "AWS_REGION": "us-east-1", "AWS_ACCESS_KEY_ID": "defaultkey", "AWS_SECRET_ACCESS_KEY": "defaultsecret", @@ -225,6 +228,7 @@ def test_with_overrides_value(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", "AWS_REGION": "us-east-1", "AWS_ACCESS_KEY_ID": "defaultkey", "AWS_SECRET_ACCESS_KEY": "defaultsecret", @@ -282,6 +286,7 @@ def test_must_work_with_overridden_aws_creds(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", "AWS_SESSION_TOKEN": "some other token", } @@ -300,6 +305,7 @@ def test_must_work_without_any_aws_creds(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", # Default values assigned to these variables "AWS_REGION": "us-east-1", "AWS_DEFAULT_REGION": "us-east-1", @@ -323,6 +329,7 @@ def test_must_work_with_partial_aws_creds(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", # Values from the input creds "AWS_REGION": "some other region", "AWS_DEFAULT_REGION": "some other region", @@ -346,6 +353,7 @@ def test_must_work_with_text_logformat(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", # Default values assigned to these variables "AWS_REGION": "us-east-1", "AWS_DEFAULT_REGION": "us-east-1", @@ -369,6 +377,7 @@ def test_must_work_with_default_json_logging_config(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", # Default values assigned to these variables "AWS_REGION": "us-east-1", "AWS_DEFAULT_REGION": "us-east-1", @@ -393,6 +402,7 @@ def test_must_work_with_set_application_log_level(self): "AWS_LAMBDA_LOG_GROUP_NAME": f"aws/lambda/{self.name}", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", # Default values assigned to these variables "AWS_REGION": "us-east-1", "AWS_DEFAULT_REGION": "us-east-1", @@ -417,6 +427,7 @@ def test_must_work_with_custom_log_group_name(self): "AWS_LAMBDA_LOG_GROUP_NAME": "myCustomLogGroup", "AWS_LAMBDA_LOG_STREAM_NAME": "$LATEST", "AWS_ACCOUNT_ID": "123456789012", + "AWS_LAMBDA_INITIALIZATION_TYPE": "on-demand", # Default values assigned to these variables "AWS_REGION": "us-east-1", "AWS_DEFAULT_REGION": "us-east-1",