0
0

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 3 years have passed since last update.

DynamoDB@boto3のクエリの書き方メモ(GSIを使う場合)

Last updated at Posted at 2020-08-19

DynamoDBのクエリの書き方@boto3メモ。忘れがちなあなたに。

DynamoDBのテーブルの項目定義

パーティションキー:id
ソートキー    :sid
属性1      :data1

で、

GSIとして↓を設定済み。
パーティションキー:id
ソートキー    :data1
インデックス名  :id-data1-index

↑の状態でGSIのid-data1-indexを使ってqueryする

コード

import boto3
client = boto3.client('dynamodb')

paginator = client.get_paginator('query')
operation_parameters = {
	'TableName': 'test-name',
	# キーとして、id と data1 を指定する
	'KeyConditionExpression': 'id = :id and begins_with(data1, :data1)',
	'ExpressionAttributeValues': {
		':id': {'S': 'id00'},
		':data1': {'S': 'data1-00-000'},
	},
	# GSIを指定
	'IndexName': 'id-data1-index',
}

page_iterator = paginator.paginate(**operation_parameters)
for page in page_iterator:
	# do something
	# del page['Items']
	print(page)
	pass
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?