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).