如何解决将CSV从S3上传到AWS Lambda时出错:TypeError:“模块”对象不可调用
我试图将csv从S3上载到Lambda中以进行简单处理,但是却收到了““ errorMessage”:“'模块'对象不可调用”,“。
我正在使用Python3.8,这是简单的Lambda函数:
import boto3
s3_client = boto3("s3")
def readindata(event,context):
bucket_name = event['Records'][0]['s3']['bucket']['name']
s3_file_name = event['Records'][0]['s3']['object']['key']
resp = s3_client.get_object(Bucket=bucket_name,Key=s3_file_name)
data = resp['Body'].read().decode("utf-8")
print(data)
我为此使用了无服务器和CloudFormation,但是Yaml文件也非常简单:
service: readincsvdata2
# app and org for use with dashboard.serverless.com
#app: your-app-name
#org: your-org-name
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
provider:
name: aws
runtime: python3.8
region: us-east-1
profile: serverless-admin
timeout: 10
memorySize: 128
iamRoleStatements:
- Effect: "Allow"
Action:
- "s3:*"
Resource: "*"
custom:
bucket: prototypeuploadcsv-08-13-2020v2
pythonRequirements:
dockerizePip: true
functions:
protomodel-readcsv:
handler: handler.readindata
events:
- s3:
bucket: ${self:custom.bucket}
event: s3:ObjectCreated:*
而且我不断收到此错误:
Response:
{
"errorMessage": "'module' object is not callable","errorType": "TypeError","stackTrace": [
" File \"/var/lang/lib/python3.8/imp.py\",line 234,in load_module\n return load_source(name,filename,file)\n"," File \"/var/lang/lib/python3.8/imp.py\",line 171,in load_source\n module = _load(spec)\n"," File \"<frozen importlib._bootstrap>\",line 702,in _load\n",line 671,in _load_unlocked\n"," File \"<frozen importlib._bootstrap_external>\",line 783,in exec_module\n",line 219,in _call_with_frames_removed\n"," File \"/var/task/handler.py\",line 3,in <module>\n s3_client = boto3(\"s3\")\n"
]
}
Request ID:
似乎我在调用或实例化一个对象错误,但是我没有看到它。我只是使用一个超级简单的测试csv作为测试数据。不确定需要更改什么。
解决方法
可能是由于以下错字造成的。
s3_client = boto3("s3")
应该是
s3_client = boto3.client("s3")
,
代替:
s3_client = boto3("s3")
应该是:
s3_client = boto3.client("s3")
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。