Skip to content

Bug: logger breaks on nodejs Docker lambdas since 2.4.0 #2851

Closed
@ralbertazzi

Description

@ralbertazzi

The base image used to build Docker images, public.ecr.aws/lambda/nodejs:20, sets the environment variable TZ=:/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 condition

Code snippet

import { Logger } from "@aws-lambda-powertools/logger";

const log = new Logger();
log.info("Hello");

Steps to Reproduce

  1. Build a Docker Lambda from public.ecr.aws/lambda/nodejs:20
  2. Install the logger library
  3. Log something

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

RangeError: Invalid time zone specified: :/etc/localtime
    at new DateTimeFormat (<anonymous>)
    at #getDateFormatter (/var/task/node_modules/.pnpm/@[email protected]/node_modules/@aws-lambda-powertools/logger/lib/cjs/formatter/LogFormatter.js:85:16)
    at #generateISOTimestampWithOffset (/var/task/node_modules/.pnpm/@[email protected]/node_modules/@aws-lambda-powertools/logger/lib/cjs/formatter/LogFormatter.js:103:82)
    at PowertoolsLogFormatter.formatTimestamp (/var/task/node_modules/.pnpm/@[email protected]/node_modules/@aws-lambda-powertools/logger/lib/cjs/formatter/LogFormatter.js:53:56)
    at PowertoolsLogFormatter.formatAttributes (/var/task/node_modules/.pnpm/@[email protected]/node_modules/@aws-lambda-powertools/logger/lib/cjs/formatter/PowertoolsLogFormatter.js:32:29)
    at Logger.createAndPopulateLogItem (/var/task/node_modules/.pnpm/@[email protected]/node_modules/@aws-lambda-powertools/logger/lib/cjs/Logger.js:722:39)
    at Logger.processLogItem (/var/task/node_modules/.pnpm/@[email protected]/node_modules/@aws-lambda-powertools/logger/lib/cjs/Logger.js:827:46)
    at Logger.info (/var/task/node_modules/.pnpm/@[email protected]/node_modules/@aws-lambda-power

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcompletedThis item is complete and has been merged/shippedgood-first-issueSomething that is suitable for those who want to start contributingloggerThis item relates to the Logger Utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions