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.