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 <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry 2021-04-25 12:38:37 -07:00 committed by Denton Gentry
parent cc6ab0a70f
commit 3c1a73d370

View File

@ -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
}