aws 部署python lambda_AWS Lambda导入模块错误在python

我正在创建一个AWS Lambda python部署包。我正在使用一个外部依赖请求。我使用AWS文档

http://docs.aws.amazon.com/lambda/latest/dg/lambda-python-how-to-create-deployment-package.html安装了外部依赖关系。以下是我的python代码。

import requests

print('Loading function')

s3 = boto3.client('s3')

def lambda_handler(event, context):

#print("Received event: " + json.dumps(event, indent=2))

# Get the object from the event and show its content type

bucket = event['Records'][0]['s3']['bucket']['name']

key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']).decode('utf8')

try:

response = s3.get_object(Bucket=bucket, Key=key)

s3.download_file(bucket,key, '/tmp/data.txt')

lines = [line.rstrip('\n') for line in open('/tmp/data.txt')]

for line in lines:

col=line.split(',')

print(col[5],col[6])

print("CONTENT TYPE: " + response['ContentType'])

return response['ContentType']

except Exception as e:

print(e)

print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))

raise e

创建了Zip项目目录的内容并上传到lambda(Zip目录内容,而不是目录)。当我执行该函数时,我得到下面提到的错误。

START RequestId: 9e64e2c7-d0c3-11e5-b34e-75c7fb49d058 Version: $LATEST

**Unable to import module 'lambda_function': No module named lambda_function**

END RequestId: 9e64e2c7-d0c3-11e5-b34e-75c7fb49d058

REPORT RequestId: 9e64e2c7-d0c3-11e5-b34e-75c7fb49d058 Duration: 19.63 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 9 MB

请帮我调试错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值