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
posta un mese fa587 visualizzazioni
1 Risposta
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
ESPERTO
con risposta un mese fa
profile picture
ESPERTO
verificato un mese fa
  • @Riku Kobayashiさん、いつもご回答ありがとうございます。 細かく確認することは必要そうですね。 色々試してみます。 アドバイスありがとうございました。参考にさせていただきます。

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande