-
Notifications
You must be signed in to change notification settings - Fork 153
Bug: logger breaks on nodejs Docker lambdas since 2.4.0 #2851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks for opening your first issue here! We'll come back to you as soon as we can. |
Hi @ralbertazzi - thank you for opening this issue. I confirm that I am able to reproduce the issue: I agree also with the fix proposed, if the value is public formatTimestamp(now: Date): string {
const defaultTimezone = 'UTC';
/**
* If a specific timezone is configured and it's not the default `UTC`,
* format the timestamp with the appropriate timezone offset.
**/
- const configuredTimezone = this.envVarsService?.getTimezone();
+ const envVartimezone = this.envVarsService?.getTimezone();
+ const configuredTimezone =
+ envVartimezone === ':/etc/localtime' ? defaultTimezone : envVartimezone;
if (configuredTimezone && !configuredTimezone.includes(defaultTimezone))
return this.#generateISOTimestampWithOffset(now, configuredTimezone);
return now.toISOString();
} Additionally, we should also add a test case at the bottom of this block here to test for this case, similar to: it('uses the default UTC timezone when the TZ env variable is set to `:/etc/localtime`', () => {
// Prepare
process.env.TZ = ':/etc/localtime';
const formatter = new PowertoolsLogFormatter({
envVarsService: new EnvironmentVariablesService(),
});
// Act
const timestamp = formatter.formatTimestamp(new Date());
// Assess
expect(timestamp).toEqual('2016-06-20T12:08:10.000Z');
}); I'll mark the issue as If nobody picks it up, we'll work on it and include the fix in the next release (~next Wednesday). In the meantime, as a stopgap solution you can set the In parallel, I'll also consult the AWS Lambda team to see if the container image should align its behavior with the managed runtime & set the value to |
I would like to take this issue :) |
This issue is now closed. Please be mindful that future comments are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so. |
This is now released under v2.7.0 version! |
The base image used to build Docker images,
public.ecr.aws/lambda/nodejs:20
, sets the environment variableTZ=:/etc/localtime
. This value is not recognised as valid one and throws an error. I believe this was introduced by this PR that was merged in 2.4.0.Expected Behavior
Building a Docker Lambda using the logger library without further configuration, i.e. I'd expect the library to print times in UTC when TZ is
:/etc/localtime
Current Behavior
RangeError: Invalid time zone specified: :/etc/localtime
is raised when logging anything under this conditionCode snippet
Steps to Reproduce
public.ecr.aws/lambda/nodejs:20
Possible Solution
The library should print times in UTC when TZ is
:/etc/localtime
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
20.x
Packaging format used
npm
Execution logs
The text was updated successfully, but these errors were encountered: