简体   繁体   English

带有dynamodb的AWS Lambda错误(模块初始化错误:未定义名称'dynamodb')

[英]AWS Lambda error (module initialization error: name 'dynamodb' is not defined) with dynamodb

I'm trying to run a lambda function that takes an attribute about the AWS IoT Dash button, its serialNumber , and queries it in DynamoDB. 我正在尝试运行一个lambda函数,该函数采用有关AWS IoT Dash按钮的attribute及其serialNumber ,并在DynamoDB中对其进行查询。 Consequently, it is supposed to print the entire row. 因此,应该打印整个行。

Here is the code ---> 这是代码--->

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)

Here is the error message I keep receiving ---> 这是我一直收到的错误消息--->

module initialization error: name 'dynamodb' is not defined

The reason the error was appearing was stupid. 错误出现的原因是愚蠢的。 The simple solution was to simply eliminate some tabs. 简单的解决方案是简单地消除一些标签。 Backspace them so everything has proper indentation. 将它们退格,以便所有内容都有适当的缩进。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM