在aws lambda

时间:2017-03-02 00:56:51

标签: python-2.7 amazon-web-services aws-lambda python-datetime

我在aws lambda上部署了一个python代码。代码使用此代码:

datetime.utcnow() + datetime.timedelta(minutes=30)

我在文件的开头使用import datetime。但是当我在Lambda上部署此代码时,我收到此错误:No module named datetime

datetime是python的一部分所以它应该在aws中自己导入,这很奇怪。我怎样才能解决这个问题?我应该添加什么包?

我尝试在带有代码文件的aws lambda包中添加datetime.py但是它会抛出nonetype' object has no attribute 'strftime'

请指导!

更新:附上以下信息 -

日志: enter image description here

制作了zip包的文件 Zip Structure

仅粘贴lambda处理程序代码(使用名称和稍作修改,尝试维护一般流程)

import sys
import json
import traceback
import os
import datetime
from dynamo_db_helper import DynamoDBHelper
from api_helper import ApiHelper
from google_drive_helper import GoogleDriveHelper
from sflogger import Logger


def lambda_handler(event, context):
    try:
        id = event["Id"]
        set_config(id)

        val1 = event["key1"]
        val2 = event["key2"]
        val3 = event["key3"]
        val4 = event["key4"]
        val5 = event["key5"]
        val6 = event["key6"]
        val7 = event["key7"]
        val8 = event["key8"]
        val9 = event["key9"]
        val10 = stop_session_url.replace("/stopsession", "/verify/")

        db_helper = DynamoDBHelper(URL, DYNAMO_DB_METADATA_TABLE_NAME, stream_id)
        data = db_helper.get_item_from_db(id)

        if data is not None \
                and data['LastModifiedTime'] < datetime.datetime.utcnow() + datetime.timedelta(minutes=30):
            link = data["Link"]
        else:
            if data is not None \
                    and data['Time'] > datetime.datetime.utcnow() + datetime.timedelta(minutes=30):
                db_helper.delete_item_from_db(id)

            link = perform_this(event, db_helper, val10)

        if link is None:
            response = set_fail("error_message")
            return response

        response = set_success(link)
        return response

    except Exception as e:
        response = set_fail("error_message")
        return response


def set_fail(msg):
    response = {"status": "Google Editing session Failed", "message": msg}
    return json.dumps(response)


def set_success(link):
    response = {"status": "Success", "webViewLink": webViewLink}
    return json.dumps(response)

如果有任何需要,请告诉我

1 个答案:

答案 0 :(得分:1)

以下代码有效。

import datetime

def lambda_handler(event, context):
  print(datetime.datetime.utcnow() + datetime.timedelta(minutes=30))