【发布时间】:2018-11-01 09:45:03
【问题描述】:
我正在尝试将我的 python 代码上传到 AWS Lambda。我一直在按照本指南创建部署包 (https://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html)。
我在桌面上创建了一个文件夹“project-dir”,并将我的 python 文件“Twilio_Alerts_AWS.py”移动到该文件夹中。我已经使用了命令:
pip install module-name -t /path/to/project-dir
将我所有的库安装到文件夹中。接下来,我突出显示所有内容并通过右键单击文件夹中突出显示的文件点击“压缩”。这会生成一个名为“存档”的压缩文件
我将'archive.zip' 放在 AWS 上的 S3 存储桶中,并将其调用到 AWS Lambda 中。即使我已将 numpy 安装到文件夹中,我仍然收到错误 Unable to import module 'Twilio_Alerts_AWS': Missing required dependencies ['numpy']
。
不知道我做错了什么。
我正在尝试上传的代码:
from twilio.rest import Client
import time
import datetime
import requests
import pandas as pd
from pandas.io.json import json_normalize
def lambda_handler(event, context):
# Your Account SID from twilio.com/console
account_sid = "xxx"
# Your Auth Token from twilio.com/console
auth_token = "xxx"
client = Client(account_sid, auth_token)
current_datetime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'x-api-key': 'xxx',
'x-organization-id': 'xxx',
'x-facility-id': 'xxx',
'x-user-id': 'xxx',
}
orders_staging_api_call = requests.get('URL', headers=headers, verify=False)
consumers_staging_api_call = requests.get('URL', headers=headers, verify=False)
inventory_staging_api_call = requests.get('URL', headers=headers, verify=False)
lst = ["+1234567890"]
##Consumers API Alert
if consumers_staging_api_call.status_code !=200:
for i in lst:
message = client.messages.create(
to=i,
from_="+1234567890",
body="API connection between A and B has failed for: Consumers.Datetime of check:{}".format(current_datetime))
time.sleep(5)
print(message.sid)
else:
print('done')
编辑: 使用 osx 机器。
【问题讨论】:
标签: python amazon-web-services numpy aws-lambda