lifadev / archive_aws-lambda-go

A fast and clean way to execute Go on AWS Lambda.
https://github.com/eawsy/aws-lambda-go
Apache License 2.0
699 stars 36 forks source link

setting environment variables in handler.go/handle #10

Closed Zambiorix closed 7 years ago

Zambiorix commented 7 years ago
    for k, v := range env {
        os.Setenv(k, v)
    }

Is there a specific reason to set event-environment variables for each call?

Since the lambda handler can be called concurrently, is it possible that these can conflict? Or is there a guaranteed clean environment with every new call?

I do not need environment variables in my project, is it possible to give the option to turn this off with a call? For example in init() ?

func init() {

    runtime.HandleFunc(handle)

    runtime.SetEnv(false)
}
fsenart commented 7 years ago

So, environment variables are well, ... very tricky in Lambda.

We have to set them with each call because of the underlying official runtime has the same behaviour. Thus, if you go through the code of the official Python or NodeJS interfaces (not officially available but visible inside the Lambda execution environment) , you will see this behaviour.

The reason is pretty simple, you can change Lambda role permissions and then Lambda environment has to regenerate new credentials (tmp key, session, etc) and it can be made at any time.

Moreover, we won't provide any interface (like runtime.SetEnv) because this project should be as closely as possible the same as any official AWS interfaces. The goal here is to provide seamless integration and no (or nearly no) gap for future migration to official interfaces.

PS1: Your lambda function is guaranteed to not be called concurrently. This is how Lambda works. PS2: Trust me you don't even lose a millisecond of execution time because of these env vars (when creating this project we paid attention to 2 things, performance and memory, fanatically).

Zambiorix commented 7 years ago

seems like you guys are the experts here :-)