[英]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.