Skip to content
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

Add AWS_LAMBDA_INITIALIZATION_TYPE env var #7533

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions samcli/local/lambdafn/env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/local/lambdafn/test_env_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
}

Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Loading