2017-10-17 149 views
0

我正在嘗試使用下面的代碼,但我無法使其工作。它不斷給我一個關於過濾器表達式是錯誤類型的錯誤消息,即使我正在執行the documentation中的完成操作。我能做些什麼來解決這個問題?Boto Scan Filterexpression:參數的類型無效

def EndpointDeleted(event): 
 
    endpoint = event['Attributes']['EndpointArn'] 
 
    if('EndpointArn' in event['Attributes']): 
 
     client = boto3.client('dynamodb') 
 
     response = client.scan(
 
      TableName='sniffergps-mobilehub-812282467-Users', 
 
      Select='ALL_ATTRIBUTES', 
 
      FilterExpression=Attr('Endpoints').contains(endpoint) 
 
     ) 
 
     return response

,但我得到一個錯誤,指出該過濾器表達式的類型不正確。我有以下的進口消息: import boto3 from boto3.dynamodb.conditions import Key from boto3.dynamodb.conditions import Attr

錯誤消息:

{ 
 
    "errorMessage": "Parameter validation failed:\nInvalid type for parameter FilterExpression, value: <boto3.dynamodb.conditions.Contains object at 0x7fdca25e0b38>, type: <class 'boto3.dynamodb.conditions.Contains'>, valid types: <class 'str'>", 
 
    "errorType": "ParamValidationError", 
 
    "stackTrace": [ 
 
    [ 
 
     "/var/task/lambda_function.py", 
 
     13, 
 
     "lambda_handler", 
 
     "return EndpointDeleted(event)" 
 
    ], 
 
    [ 
 
     "/var/task/lambda_function.py", 
 
     24, 
 
     "EndpointDeleted", 
 
     "FilterExpression=Attr('Endpoints').contains(endpoint)" 
 
    ], 
 
    [ 
 
     "/var/runtime/botocore/client.py", 
 
     312, 
 
     "_api_call", 
 
     "return self._make_api_call(operation_name, kwargs)" 
 
    ], 
 
    [ 
 
     "/var/runtime/botocore/client.py", 
 
     575, 
 
     "_make_api_call", 
 
     "api_params, operation_model, context=request_context)" 
 
    ], 
 
    [ 
 
     "/var/runtime/botocore/client.py", 
 
     630, 
 
     "_convert_to_request_dict", 
 
     "api_params, operation_model)" 
 
    ], 
 
    [ 
 
     "/var/runtime/botocore/validate.py", 
 
     291, 
 
     "serialize_to_request", 
 
     "raise ParamValidationError(report=report.generate_report())" 
 
    ] 
 
    ] 
 
}

回答

2

注意在Boto3 DynamoDB Client語法之間的區別,以及表Resource

DynamoDB客戶端的參數FilterExpression需要一個字符串。

您用於設置FilterExpression參數的方法看起來像您使用DynamoDB.Table資源的方式。

相關問題