Utiliser DynamoDB avec Python

Quand j'ai écrit Lambda dans Node.js, j'ai été frappé par le traitement asynchrone, j'ai donc décidé d'utiliser le Lambda / Python récemment publié et l'ai essayé.

document

http://boto3.readthedocs.org/en/latest/guide/dynamodb.html

Préparation

import boto3
import json
from boto3.dynamodb.conditions import Key, Attr


dynamodb = boto3.resource('dynamodb')
table    = dynamodb.Table('MY_TABLE_NAME')

query


res = table.query(
        IndexName='MY_INDEX_NAME',
        KeyConditionExpression=Key('MY_INDEX_NAME').eq(MY_INDEX_VALUE)
    )
for row in res['Items']:
    print(row)

delete_item

table.delete_item(Key={'key1': key1, 'key2': key2})

put_item

table.put_item(
    Item={
        "key1": value1,
        "key2": value2
   }
)

get_item

items = table.get_item(
            Key={
                 "key1": key1
            }
        )

batch_write

with table.batch_writer() as batch:
    for i in range(50):
        batch.put_item(
            Item={
                'account_type': 'anonymous',
                'username': 'user' + str(i),
                'first_name': 'unknown',
                'last_name': 'unknown'
            }
        )

http://boto3.readthedocs.org/en/latest/guide/dynamodb.html#batch-writing

La limite de DynamoDB est de 25, mais il semble que l'envoi de 25 chacun soit gênant.

list_tables

dynamodb = boto3.resource('dynamodb')
table_list = dynamodb.tables.all()
for table in table_list:
    print(table.table_name)

Recommended Posts

Utiliser DynamoDB avec Python
[Python] Utiliser JSON avec Python
Utiliser mecab avec Python 3
Utilisez Python 3.8 avec Anaconda
Utiliser python avec docker
Utiliser l'API Trello avec python
Utiliser l'API Twitter avec Python
Utiliser l'API subsonique avec python3
Python: comment utiliser async avec
Utiliser la caméra Point Grey avec Python (PyCapture2)
Utilisez vl53l0x avec RaspberryPi (python)
Utiliser rospy avec virtualenv dans Python3
Utiliser Python mis en pyenv avec NeoVim
Utiliser la synthèse vocale Windows 10 avec Python
Utiliser OpenCV avec Python 3 dans Window
Utiliser PostgreSQL avec Lambda (Python + psycopg2)
FizzBuzz en Python3
Grattage avec Python
Statistiques avec python
Grattage avec Python
Python avec Go
Intégrer avec Python
Jouez avec 2016-Python
AES256 avec python
Testé avec Python
python commence par ()
avec syntaxe (Python)
Bingo avec python
Zundokokiyoshi avec python
Excel avec Python
Micro-ordinateur avec Python
Cast avec python
Utilisez smbus avec python3 sous environnement pyenv
Utiliser DeepL avec python (pour la traduction d'articles)
Utiliser Amazon Simple Notification Service avec Python
[Introduction à Python] Utilisons foreach avec Python
Utilisez PIL ou Pillow avec Cygwin Python
Utiliser le chiffrement de la bibliothèque de chiffrement avec l'image Python de Docker
Manipulation des données DynamoDB avec Lambda (Node et Python)
Utiliser Application Insights avec Python 3 (y compris les bouteilles)
Utilisation des fonctions C ++ de python avec pybind11
Utilisez le pilote Web phantomjs de sélénium avec unittest de python
Jusqu'à ce que vous puissiez utiliser opencv avec python
Utiliser Python et MeCab avec Azure Functions
Communication série avec Python
Zip, décompressez avec python
Jugement des nombres premiers avec Python
Python avec eclipse + PyDev.
Utilisez Thingsspeak de Python
Communication de socket avec Python
Analyse de données avec python 2
Grattage en Python (préparation)
Utilisez mecab-ipadic-neologd avec igo-python
Essayez de gratter avec Python.
Utilisez RTX 3090 avec PyTorch
Utilisez config.ini avec Python
Recherche séquentielle avec Python
"Orienté objet" appris avec python