2016-06-17 3 views
0

dynamodb 쿼리 또는 스캔 결과에 어떤 필드를 포함 시킬지 선택할 수있는 방법이 있는지 궁금합니다. 나는 AttributesToGet에게DynamoDB에서 반환 할 필드를 선택할 수 있습니까?

def filter_ga_account_by_email(self, email): 
    response = Table.scan(
     FilterExpression=Attr('client_email').eq(email), 
     AttributesToGet=['id'], 
    ) 

    return response['Items'] 

를 사용하려고하고 지금은이 오류가 : ClientError: An error occurred (ValidationException) when calling the Scan operation: Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributesToGet} Expression parameters: {FilterExpression}

답변

1

확인을

당신이 'AttributesToGet'를 사용할 수 있습니다

:

client = boto3.client('dynamodb') 

response = client.get_item(TableName='tbl_name', Key={'client_email':{'N':str(email)}}, AttributesToGet=['id']) 

하지만주의하십시오

This is a legacy parameter, for backward compatibility. New applications should use ProjectionExpression instead. Do not combine legacy parameters and expression parameters in a single call; otherwise, DynamoDB will return a ValidationException exception. This parameter allows you to retrieve attributes of type List or Map; however, it cannot retrieve individual elements within a List or a Map.

http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html#API_Query_RequestSyntax

+0

ClientError : 스캔 작업을 호출 할 때 오류가 발생했습니다 (ValidationException). 동일한 요청에서 표현식과 비 표현식 매개 변수를 모두 사용할 수 없습니다. 표현식이 아닌 매개 변수 : {AttributesToGet} 표현식 매개 변수 : {FilterExpression} 'btw 나는 스캔을 고소하고있다. 나는 내 코드도 업데이트 할 것이다. – Alex

+0

내 대답을 편집했습니다. (단일 호출에서 레거시 매개 변수와 표현 매개 변수를 결합하지 마십시오. 그렇지 않으면 DynamoDB가 ValidationException 예외를 반환합니다.) –

+0

오류 'TypeError : object .__ new __ (thread.lock) .lock .__ new __()'나는 파이썬에서도 새내기입니다. – Alex

관련 문제