lambdaからDynamoDB内にある条件に一致したデータを取り出したい。

0

lambdaで指定したDynamoDBのテーブルから条件に一致した行だけを抜き出すため、以下のようなスクリプトを利用しています。

DynamoDBには指定した条件に一致した情報が登録があるにもかかわらず、lambdaでは"No matching item found."がプリント出力されてしまいます。

    query_kwargs = {
        "KeyConditionExpression": Key("userId").eq(userId) ,
        "FilterExpression": Key("recordId").eq(recordId)& Key("event_type").eq(event_type),
    }
    response_event = dynamodb_my_Table.query(**query_kwargs)
    print(response_event)
    if response_event['Items']:
        print(response_event)
    else:
        print("No matching item found.")

なにか解決策があればご教示いただけますと幸いです。よろしくお願いいたします。

yuuka_u
질문됨 한 달 전587회 조회
1개 답변
1

まずは以下の条件だけでレコードが取得できるか確認した方がよいと思います。

"KeyConditionExpression": Key("userId").eq(userId)

ここから徐々に条件を増やしていくのはいかがでしょうか?

"FilterExpression"はパーティションキー、ソートキーは使えないみたいなので注意してください。
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb/client/query.html

A FilterExpression does not allow key attributes. You cannot define a filter expression based on a partition key or a sort key.

profile picture
전문가
답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
  • @Riku Kobayashiさん、いつもご回答ありがとうございます。 細かく確認することは必要そうですね。 色々試してみます。 アドバイスありがとうございました。参考にさせていただきます。

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인