Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import pytz into AWS lambda function

I'm writing a lambda function that works with datetimes and trying to import pytz so I can have timezone be accounted for when comparing.

import boto3
import pytz
from datetime import timedelta, date, datetime
from boto3.dynamodb.conditions import Key, Attr

causes this to display

{errorMessage=Unable to import module 'lambda_function'}

but when I remove import pytz the function fires (it just doesn't work properly without timezone info)

like image 712
Scott Decker Avatar asked Jan 20 '16 17:01

Scott Decker


Video Answer


1 Answers

If you don't have access to pytz in your environment, maybe you have access to python-dateutil. In that case you can do:

import datetime
import dateutil.tz

eastern = dateutil.tz.gettz('US/Eastern')
datetime.datetime.now(tz=eastern)

REF. How to get current time in Pacific Timezone when import pytz fails?

like image 143
yarick Avatar answered Sep 17 '22 17:09

yarick