简体   繁体   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",

I am using a filter on dynamodb table.我在 dynamodb 表上使用过滤器。 it throws error the following error.它会引发以下错误。 Boto3 documentation shows response = table.scan(FilterExpression=Attr('myattribute').eq('myvalue') Boto3 文档显示 response = table.scan(FilterExpression=Attr('myattribute').eq('myvalue')

I did same thing.我做了同样的事情。 I want items in this table where the agentRole = Receiver我想要此表中 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"
       ]
   }

This is the code:这是代码:

   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.

相关问题 AWS Lambda Python Boto3 - 项目计数 dynamodb 表 - AWS Lambda Python Boto3 - Item count dynamodb table Python Boto3 AWS Lambda TypeDeserializer - 错误:TypeError:Dynamodb 类型<name>不支持</name> - Python Boto3 AWS Lambda TypeDeserializer - Error: TypeError: Dynamodb type <name> is not supported AWS Lambda Python Boto3 - 在调用 PutItem 操作时将数据插入 dynamodb 会引发错误 ResourceNotFoundException):请求的资源", - AWS Lambda Python Boto3 - Inserting data into dynamodb throws error ResourceNotFoundException) when calling the PutItem operation: Requested resou", Python从带有boto3错误的代码中调用我的AWS Lambda - Python call my AWS lambda from code with boto3 error 带有dynamodb的AWS Lambda错误(模块初始化错误:未定义名称&#39;dynamodb&#39;) - AWS Lambda error (module initialization error: name 'dynamodb' is not defined) with dynamodb 如何使用 boto3(lambda) 对 AWS dynamodb 表进行分组并获取分区键的最新值? - how to group AWS dynamodb table and get latest value of partition key using boto3(lambda)? 测试 Python AWS Lambda boto3 初始化 - Testing Python AWS Lambda boto3 initialization 如何在 aws dynamodb boto3 上正确使用日期过滤器 - How to use date filter correctly on aws dynamodb boto3 如何使用Python boto3从AWS DynamoDB表中获取特定属性的所有项目? - How to fetch all items of a particular Attribute from an AWS DynamoDB Table using Python boto3? Python Boto3 AWS DynamoDB从表中获取项目而无排序键 - Python Boto3 AWS DynamoDB get item from table without sort key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM