I'm looking to make the log level for my AWS Lambda functions in .NET more dynamic. I found a suggestion about using AWS Systems Manager Parameter Store to help change log levels when simply modifying environment variables isn't suitable. Is Parameter Store the right approach for this, or should I consider something else? Additionally, is there a method to force a refresh of the execution environments in Lambda so that all instances reflect the new log level, or do I just have to wait for new environments to start up? Thanks!
3 Answers
Changing an environment variable should trigger a restart of the Lambda runtime, which is likely the simplest way to ensure the new settings are applied.
Parameter Store is definitely the way to go! It's the standard for managing dynamic configuration in AWS. Plus, it provides versioning and encryption features, which are super useful for your needs.
As for forcing a refresh of execution environments in Lambda, there's no direct method for that. Lambda uses its own logic to decide when to spin up new environments. You might try updating the function's code or configuration as a workaround, but that's a bit iffy. Typically, you'll have to wait for the instances to cycle naturally to adopt the new log level.
Thank you! I really appreciate the feedback!
There's actually a Lambda extension that polls the Parameter Store based on a TTL to keep itself updated with the latest values. You can check it out here: https://docs.aws.amazon.com/systems-manager/latest/userguide/ps-integration-lambda-extensions.html. Otherwise, if you set the log level as an environment variable and deploy, new instances will take that change into account while existing ones will terminate after finishing their current requests.

Or, if you want a more advanced approach, you could treat the parameter like a cache that expires. Have a global variable that tracks when you last checked the parameter, and if it’s older than a set duration, fetch it again from Parameter Store.