2017-02-21 6 views
1

저는 Python으로 AWS Lambda 함수를 프로그래밍하고 있습니다. boto3을 사용하여 DynamoDB 데이터베이스에 연결하고 마지막 위치 항목을 검색하려고합니다.AWS Lambda DynamoDB 쿼리 오류

DynamoDB 테이블의 주 파티션 키는 "Serial"이며 문자열은 "Time"의 기본 정렬 키이며 문자열입니다.

내가 아래에 언급 한 바와 같이 시리얼 "0001"나는 다음과 같은 오류를 얻을

def getPriorGeofence(device): 
client = boto3.client('dynamodb') 
response = client.query(
    TableName='Locations', 
    IndexName='Serial', 
    Select='ALL_ATTRIBUTES', 
    Limit=1, 
    ScanIndexForward=True, 
    KeyConditions={ 
     "Serial":{ 
      'ComparisonOperator': "EQ", 
      'AttributeValueList': [device] 
     } 
    } 
    ) 
return response 

오류

{ 
    "stackTrace": [ 
    [ 
     "/var/task/lambda_function.py", 
     154, 
     "lambda_handler", 
     "priorGeofence = getPriorGeofence(serial)" 
    ], 
    [ 
     "/var/task/lambda_function.py", 
     110, 
     "getPriorGeofence", 
     "'AttributeValueList': [device]" 
    ], 
    [ 
     "/var/runtime/botocore/client.py", 
     253, 
     "_api_call", 
     "return self._make_api_call(operation_name, kwargs)" 
    ], 
    [ 
     "/var/runtime/botocore/client.py", 
     517, 
     "_make_api_call", 
     "api_params, operation_model, context=request_context)" 
    ], 
    [ 
     "/var/runtime/botocore/client.py", 
     572, 
     "_convert_to_request_dict", 
     "api_params, operation_model)" 
    ], 
    [ 
     "/var/runtime/botocore/validate.py", 
     270, 
     "serialize_to_request", 
     "raise ParamValidationError(report=report.generate_report())" 
    ] 
    ], 
    "errorType": "ParamValidationError", 
    "errorMessage": "Parameter validation failed:\nInvalid type for parameter KeyConditions.Serial.AttributeValueList[0], value: 0001, type: <type 'unicode'>, valid types: <type 'dict'>" 
} 

답변

0

변경 AttributeValueList 값의 마지막 항목을 얻으려고,이 코드를 실행하면 (즉, 데이터 유형을 String 'S'명시 적으로 언급). -

KeyConditions={ 
     "Serial":{ 
      'ComparisonOperator': "EQ", 
      'AttributeValueList': [{'S' : device}] 
     } 
    }