Skip to content

Expose Environment variables in ILambdaContext #11

Closed

Description

@Kralizek

Right now, Environment variables are found in the ClientContext that is populated only when the function is invoked by the Mobile SDK.

Wouldn't be better to have the Environment variables available directly in the LambdaContext that we can receive at execution time?

I am aware that we can use System.Environment.GetEnvironmentVariable(<environmentvariablename>)but it makes the code so poorly testable.

Activity

  1. Kralizek commented on Dec 12, 2016

    @Kralizek
    Author

    I was actually thinking of giving it a try myself but I couldn't find any concrete implementation but the one in the Amazon.Lambda.TestUtilities package.

    Am I missing something?

  2. PavelSafronov commented on Dec 12, 2016

    @PavelSafronov

    Can you provide a list of the environment variables you are looking for? Some of these may already be exposed on ILambdaContext.

  3. Kralizek commented on Dec 12, 2016

    @Kralizek
    Author

    Mostly the custom ones you use to configure the Lambda.

  4. Kralizek commented on Jan 11, 2017

    @Kralizek
    Author

    Any comment about this suggestion? Also, is there any way I can contribute?

  5. Thaina commented on Jan 14, 2017

    @Thaina

    @PavelSafronov I think the point he mention is, Custom Env var that could be set at lambda function. It could be a long list of keyvalue. And whenever we want to edit that list we need to get the whole list without reserved and system env variable

    In my case I have lambda cron update everyday. I use environment variable to count number of day it was updated. I need to call GetFunctionConfiguration to get env list of current function, then update the day, and call SetFunctionConfiguration to set it back

    If we expose those env in context object it would be easier to access and set, without get

    But

    @Kralizek It sadly that the core system of lambda does not give that in any language. Not in nodejs or java. We need AWS team to update the system before we could write library to support it

  6. Kralizek commented on Jan 16, 2017

    @Kralizek
    Author

    Wouldn't be easy to fix for .NET?

    public interface ILambdaContext
    {
        ...
        IDictionary EnvironmentVariables { get; }
        ...
    }
    

    and, in the concrete class implementing ILambdaContext, simply add

    public IDictionary EnvironmentVariables => System.Environment.GetEnvironmentVariables();

    if you want to be fancy, you can cast that IDictionary into a IDictionary<string, string>

  7. adamhathcock commented on Jan 16, 2017

    @adamhathcock

    I don't understand why this has to be part of the SDK. If you really want it, just make your own class that wraps System.Environment.GetEnvironmentVariables() and inject it in your constructor yourself.

  8. Thaina commented on Jan 16, 2017

    @Thaina

    @Kralizek I used to think like you until I had found that there are EnvironmentVariables of system itself that I don't set it by myself and it hard to exclude all those

    So the best solution for me is using lambda.GetFunctionConfiguration().Environment.Variables

  9. normj commented on Jan 17, 2017

    @normj
    Member

    @Thaina it sounds like you are asking for the executing Lambda function to have a quick way to change the environment variables set in the Lambda function configuration. That brings in a host of concurrency questions and the service IAM role is likely not going to have permissions to modify the function's configuration.

  10. Thaina commented on Jan 17, 2017

    @Thaina

    @normj It not only for change but we could set our own env variable in a way that can be iterate. To iterate all EnvVariable directly and exclude system keyword is prone to error

    And I was set role of my lambda function to have lambda invoke permission. So it can change its own env variable programmatically when needed

    I don't think it againts concurrency. Because changing env variable of lambda not affect current call. It effect the next call. It more like parameter of recursive function

    In my perspective. Env Variable is like a parameter of Main function

  11. normj commented on Jan 26, 2017

    @normj
    Member

    I see where you are going with this but it is beyond the scope of what we can do for the .NET Core tooling. You are looking for a Lambda service change that affects all runtimes. For that type of request I'd suggest going to the Lambda forums, https://forums.aws.amazon.com/forum.jspa?forumID=186.

  12. added
    guidanceQuestion that needs advice or information.
    wontfixWe have determined that we will not resolve the issue.
    and removed on Jan 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    guidanceQuestion that needs advice or information.wontfixWe have determined that we will not resolve the issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions