8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

boto3でDynamoDBのセカンダリインデックスを使う

Last updated at Posted at 2017-04-05

DynamoDBのセカンダリインデックス

DynamoDBではセカンダリインデックスを使うことができます。詳しくはこの辺りを参照してください。

boto3からセカンダリインデックスでアイテムを探す

boto3からのアクセス方法が最初わからなかったので残しておきます。
グローバルセカンダリインデックスとしてsecondが設定しているテーブルに対してアクセスします。

DynamoDB · AWS Console 2017-04-05 18-25-13.png
DynamoDB · AWS Console 2017-04-05 18-27-45.png

import boto3
from boto3.dynamodb.conditions import Key

dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('test-table')

response = table.query(IndexName='second-index', KeyConditionExpression=Key('second').eq('hoge'))

print(response['Items'])

> [{'key': '1', 'second': 'hoge'}]

参考情報

amazon web services - How do we query on a secondary index of dynamodb using boto3? - Stack Overflow

8
4
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
8
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?