Skip to content

Commit

Permalink
Adding AWS_LAMBDA_INITIALIZATION_TYPE env var (#7533)
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrodamascena authored Oct 4, 2024
1 parent f5b729c commit 4656a42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 4656a42

Please sign in to comment.