LoginSignup
0
0

More than 1 year has passed since last update.

boto3.Sessionを利用した場合のGSIに対するクエリの書き方

Last updated at Posted at 2023-03-22

DynamoDBのGSIに対してクエリをかける方法を調べたのでまとめます。

結論

dynamodb = boto3.Session(profile_name=profile_name).client("dynamodb")
response = dynamodb.query(
            TableName="TABLE_NAME",
            IndexName="INDEX_NAME",
            KeyConditionExpression="index_key = :index_key",
            ExpressionAttributeValues={":index_key": {"S": "00000000"}},
        )

レスポンスはItemsをキーとしたオブジェクトが返ってきます。

{'Items':[{"index_key":{"S":"00000000"}, "primary_key":{"S":"pk1"},"sort_key":{"S":"sk1"}}],}
}

リクエストでもレスポンスでも型を(文字列型ならば"S"のように)指定をしなければいいけないというところで躓きました。

参考文献

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0