LoginSignup
0
0

DynamoDB上のデータをPythonで扱う方法

Last updated at Posted at 2024-01-28

準備

  • AWSアクセスキーを設定(こちらはPython上では行わない)
  • boto3と使用とテーブルの接続
import boto3
dynamodb = boto3.resource("dynamodb")
table = dynamodb.Table("table_name")

データの取得と更新

取得

  • データの取得はget_itemを使用。引数に設定してあるプライマリーキーを使用することで特定のデータを参照できる
response = table.get_item(Key={"ID":"1"})
  • 仮に全データを取得する場合はscanを使用するが、頻繁な読み書きをDynamoDBは推奨していないため、その場合はRedshift等別のテーブル設定をする必要ばある
response = table.scan()

書き込み

data = {"ID":"100"}
response = put_item(Item=data)

ドキュメント

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