From 3c1a73d3700056b084eb017ebe02dbbca7c3b064 Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Sun, 25 Apr 2021 12:38:37 -0700 Subject: [PATCH] hostinfo: detect AWS Lambda as a container. AWS Lambda uses Docker containers but does not have the string "docker" in its /proc/1/cgroup. Infer AWS Lambda via the environment variables it sets. Signed-off-by: Denton Gentry --- control/controlclient/hostinfo_linux.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/control/controlclient/hostinfo_linux.go b/control/controlclient/hostinfo_linux.go index e79eaaa89..364e1098b 100644 --- a/control/controlclient/hostinfo_linux.go +++ b/control/controlclient/hostinfo_linux.go @@ -62,6 +62,9 @@ func osVersionLinux() string { if inKnative() { attrBuf.WriteString("; env=kn") } + if inAwsLambda() { + attrBuf.WriteString("; env=lm") + } attr := attrBuf.String() id := m["ID"] @@ -121,3 +124,14 @@ func inKnative() bool { } return false } + +func inAwsLambda() bool { + // https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html + if os.Getenv("AWS_LAMBDA_FUNCTION_NAME") != "" && + os.Getenv("AWS_LAMBDA_FUNCTION_VERSION") != "" && + os.Getenv("AWS_LAMBDA_INITIALIZATION_TYPE") != "" && + os.Getenv("AWS_LAMBDA_RUNTIME_API") != "" { + return true + } + return false +}