2

I want to delete all environment variables from a lambdas "$latest" version via our C# .NET tool. For that, I use this code:

using (var lambdaClient = new AmazonLambdaClient(awsCredentials, RegionEndpoint.EUCentral1))
{
    // Get the lambda config.
    var lambdaConfig = lambdaClient.GetFunctionConfigurationAsync(lambdaName).Result;

    var request = new UpdateFunctionConfigurationRequest()
    {
        FunctionName = lambdaName,
        Environment = new Amazon.Lambda.Model.Environment()
        {
            // Remove all environment variables.
            Variables = new Dictionary<string, string>(),
        }
    };

    var response = lambdaClient.UpdateFunctionConfigurationAsync(request).Result;

    // This is currently hit every time, as the environment variables are not deleted.
    if (response.Environment.Variables != null && response.Environment.Variables.Any())
        Debug.LogError("Could not delete lambda environment variables!");
}

I know that I can do this by hand via the AWS web console, but I want this do be automated for every new lambda deployment, so that only required environment variables are configured on the lambda.

I want to remove the variables from the "$latest" version, not the published ones, as I know that published versions can't have their environment variables changed, only the '$latest' one.

I'm using the NuGet package AWSSDK.Lambda for .NET Core, version 3.3.103.25.

1 Answer 1

3

So apparently this works in other languages, but not in C#. The AWS support confirmed, that this is a bug. The service team has released a new version since, AWSSDK.Lambda version 3.3.104.1, and I can confirm that this works now.

They added a new property 'IsVariablesSet', which must be set to 'true' if you want to change the environment variables on the lambda. The following request now deletes all environment variables from the selected lambda:

var request = new UpdateFunctionConfigurationRequest()
{
    FunctionName = lambdaName,
    Environment = new Amazon.Lambda.Model.Environment()
    {
        Variables = new Dictionary<string, string>(),
        IsVariablesSet = true,
    }
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.