[英]AWS Lambda error (module initialization error: name 'dynamodb' is not defined) with dynamodb
我正在尝试运行一个lambda函数,该函数采用有关AWS IoT Dash按钮的attribute
及其serialNumber
,并在DynamoDB中对其进行查询。 因此,应该打印整个行。
这是代码--->
from __future__ import print_function
import boto3
import json
import decimal
from boto3.dynamodb.conditions import Key, Attr
def lambda_handler(event, context):
print ('Init 1Push_Care_DATAprint')
print (event)
serialNumber = event['serialNumber']
class DecimalEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, decimal.Decimal):
if o % 1 > 0:
return float(o)
else:
return int(o)
return super(DecimalEncoder, self).default(o)
dynamodb = boto3.resource('dynamodb',region_name='us-east-1')
table = dynamodb.Table('1Push_Care_USERinfo')
response = table.query(
KeyConditionExpression=Key('Device_ID').eq('serialNumber')
)
items = response['Items']
print(items)
这是我一直收到的错误消息--->
module initialization error: name 'dynamodb' is not defined
错误出现的原因是愚蠢的。 简单的解决方案是简单地消除一些标签。 将它们退格,以便所有内容都有适当的缩进。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.