Skip to content

Commit 9b70ffa

Browse files
authored
RUST-1645 Fix AWS Lambda detection logic (#876)
1 parent 6a6c309 commit 9b70ffa

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/cmap/establish/handshake/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ impl FaasEnvironmentName {
223223
fn new() -> Option<Self> {
224224
use FaasEnvironmentName::*;
225225
let mut found: Option<Self> = None;
226-
if var_set("AWS_EXECUTION_ENV") || var_set("AWS_LAMBDA_RUNTIME_API") {
226+
let lambda_env = env::var_os("AWS_EXECUTION_ENV")
227+
.map_or(false, |v| v.to_string_lossy().starts_with("AWS_Lambda_"));
228+
if lambda_env || var_set("AWS_LAMBDA_RUNTIME_API") {
227229
found = Some(AwsLambda);
228230
}
229231
if var_set("VERCEL") {

src/test/spec/faas.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,9 @@ async fn invalid_wrong_type() -> Result<()> {
114114
])
115115
.await
116116
}
117+
118+
#[cfg_attr(feature = "tokio-runtime", tokio::test)]
119+
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
120+
async fn invalid_aws_not_lambda() -> Result<()> {
121+
check_faas_handshake(&[("AWS_EXECUTION_ENV", "EC2")]).await
122+
}

0 commit comments

Comments
 (0)