From bea5f1d2c3b9ade3d911bc4997cf79430d63dae8 Mon Sep 17 00:00:00 2001 From: Ryan Scott Brown Date: Tue, 26 Apr 2022 23:19:34 -0400 Subject: [PATCH] fix: Silence home directory warning in Lambda Extensions (#1344) * fix: Silence home directory warning in Lambda Extensions This PR follows on to https://github.com/awslabs/smithy-rs/pull/893 which added LAMBDA_TASK_ROOT check. When running as a [Lambda Extension][ext] the environment variable for TASK_ROOT is redacted, so it is not reliable for testing whether you are in Lambda. Related commit: fbb4bc [ext]: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html * update changelog * fixup: use AWS_LAMBDA_FUNCTION_NAME which is available in both environments * Update CHANGELOG.next.toml * Fix failing unit test Co-authored-by: John DiSanti --- CHANGELOG.next.toml | 6 ++++++ aws/rust-runtime/aws-config/src/profile/parser/source.rs | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 91e968694..1bf22eaf3 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -34,3 +34,9 @@ message = "Upgrade to Smithy 1.21.0" references = ["smithy-rs#1330"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "jdisanti" + +[[aws-sdk-rust]] +message = "Suppress irrelevant `$HOME` expansion warning when running in a Lambda Extension" +references = ["smithy-rs#1344"] +meta = { "breaking" = false, "tada" = false, "bug" = true } +author = "ryansb" diff --git a/aws/rust-runtime/aws-config/src/profile/parser/source.rs b/aws/rust-runtime/aws-config/src/profile/parser/source.rs index 8bfcfb458..b5c127951 100644 --- a/aws/rust-runtime/aws-config/src/profile/parser/source.rs +++ b/aws/rust-runtime/aws-config/src/profile/parser/source.rs @@ -183,8 +183,8 @@ fn expand_home( /// [Lambdas set many environment variables](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime) /// that we can check. fn check_is_likely_running_on_a_lambda(environment: &aws_types::os_shim_internal::Env) -> bool { - // LAMBDA_TASK_ROOT – The path to your Lambda function code. - environment.get("LAMBDA_TASK_ROOT").is_ok() + // AWS_LAMBDA_FUNCTION_NAME – The name of the running Lambda function. Available both in Functions and Extensions + environment.get("AWS_LAMBDA_FUNCTION_NAME").is_ok() } #[cfg(test)] @@ -261,7 +261,7 @@ mod tests { #[traced_test] #[test] fn load_config_file_should_not_emit_warning_on_lambda() { - let env = Env::from_slice(&[("LAMBDA_TASK_ROOT", "/")]); + let env = Env::from_slice(&[("AWS_LAMBDA_FUNCTION_NAME", "someName")]); let fs = Fs::from_slice(&[]); let _src = load_config_file(FileKind::Config, &None, &fs, &env).now_or_never(); -- GitLab