我试图将一个csv从S3上传到Lambda以进行简单处理,但得到了“errorMessage”:“module”对象不可调用”
我使用的是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",
" File \"<frozen importlib._bootstrap>\", line 671, in _load_unlocked\n",
" File \"<frozen importlib._bootstrap_external>\", line 783, in exec_module\n",
" File \"<frozen importlib._bootstrap>\", 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作为测试数据。不确定需要改变什么
而不是:
应该有:
可能是因为下面的打字错误
应该是
相关问题 更多 >
编程相关推荐