Home > Net >  Why I'm getting UTC( 00:00) even I'm runnning my aws lambda at ap-northeast-2 region?
Why I'm getting UTC( 00:00) even I'm runnning my aws lambda at ap-northeast-2 region?

Time:12-27

I'm running lambda at region ap-northeast-2

this is part of my code, getting a timestamp for DynamoDB

import datetime
a = datetime.datetime.now().astimezone().replace(microsecond=0).replace(second=0).isoformat()

if I run this, I get "2021-12-25T15:33:00 00:00"

while I get "2021-12-26T00:34:00 09:00" on my laptop.

I thought that lambda will return same as mine because I'm at Seoul so does ap-northeast-2 region is there a reason why I couldn't get my timezone?

CodePudding user response:

Lambda instances always use UTC as their time zone, see https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html under Reserved Environment Variables: TZ.

It would be awkward if the time zone switched depending on the region where you run.

Related: AWS Lambda Timezone (the link above came from the comments on that question).

  • Related