Skip to content

Commit

Permalink
wrapper handler
Browse files Browse the repository at this point in the history
  • Loading branch information
chaudharysaket committed Apr 29, 2024
1 parent cf86fb5 commit 5334238
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 8 additions & 2 deletions checks/handler_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type handlerConfigs struct {
conf *config.Configuration
}

var handlerPath = "/var/task"
var handlerPath = util.GetEnvOrDefault("LAMBDA_TASK_ROOT", "/var/task")

func handlerCheck(ctx context.Context, conf *config.Configuration, reg *api.RegistrationResponse, r runtimeConfig) error {
if r.language != "" {
Expand Down Expand Up @@ -56,7 +56,7 @@ func (r runtimeConfig) getTrueHandler(h handlerConfigs) string {
if esm == "true" {
return h.handlerName
}
if util.PathExists("/.dockerenv") {
if isDockerEnvironment() {
return h.handlerName
}
}
Expand All @@ -78,3 +78,9 @@ func pathFormatter(functionHandler string, fileType string) string {
p := fmt.Sprintf("%s/%s.%s", handlerPath, functionHandler, fileType)
return p
}

func isDockerEnvironment() bool {
_, dockerHost := os.LookupEnv("DOCKER_HOST")
_, dockerCgroup := os.LookupEnv("container")
return dockerHost || dockerCgroup
}
7 changes: 7 additions & 0 deletions util/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ func AnyEnvVarsExistString(keys []string) string {

return ""
}

func GetEnvOrDefault(key string, defaultValue string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return defaultValue
}

0 comments on commit 5334238

Please sign in to comment.