簡體   English   中英

AWS Lambda Boto3 python - dynamodb 表上的過濾器表達式拋出錯誤“errorMessage”:“名稱'Attr'未定義”,

[英]AWS Lambda Boto3 python - filter expression on dynamodb table throw error "errorMessage": "name 'Attr' is not defined",

我在 dynamodb 表上使用過濾器。 它會引發以下錯誤。 Boto3 文檔顯示 response = table.scan(FilterExpression=Attr('myattribute').eq('myvalue')

我做了同樣的事情。 我想要此表中 agentRole = Receiver 的項目

  Response
  {
        "errorMessage": "name 'Attr' is not defined",
        "errorType": "NameError",
        "requestId": "1b2fbee6-5fa2-4951-8689-3d1bfec76e5c",
         "stackTrace": [
              "  File \"/var/task/lambda_function.py\", line 21, in lambda_handler\n    
          response = tableresource.scan(FilterExpression=Attr('agentRole').eq('Receiver'))\n"
       ]
   }

這是代碼:

   import json
   import os
   import boto3
   from pprint import pprint

    #Find records that has agentRole as 'Receiver'

    tableName = os.environ.get('TABLE')
    fieldName = os.environ.get('FIELD')
    keytofind = os.environ.get('FILTER')
    fieldname = "agentRole"
    dbclient = boto3.resource('dynamodb')

    def lambda_handler(event, context):
   
         tableresource = dbclient.Table(tableName)
         count = tableresource.item_count
         response = tableresource.scan(FilterExpression=Attr('agentRole').eq('Receiver'))
        
 
 
from boto3.dynamodb.conditions import Attr

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM