[最終更新] 2022年10月3日
いつも忘れるのでメモ。随時追加していく。
- get_item()
- put_item()
- delete_item()
get_item()
以下のようなPKだけのシンプルなテーブルに対する操作とする。
Attr | Value |
pk_id | test |
正常系
確認日: 2022-05-25
res = table.get_item(Key={'pk_id': 'test'})
なにも間違えていない。なので、当然怒られない。正常なレスポンス。
{
"Item": {
"pk_id": "test"
},
"ResponseMetadata": {
"RequestId": "xxxx",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"server": "Server",
"date": "Tue, 24 May 2022 16:30:00 GMT",
"content-type": "application/x-amz-json-1.0",
"content-length": "32",
"connection": "keep-alive",
"x-amzn-requestid": "xxxx",
"x-amz-crc32": "3407680564"
},
"RetryAttempts": 0
}
}
Keyがない
確認日: 2022-05-25
res = table.get_item(Key={'hoge': 'test'})
以下のエラーが出て怒られる。
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the GetItem operation: The provided key element does not match the schema
PKの値が存在しない
確認日: 2022-05-25
res = table.get_item(Key={'pk_id': 'hoge'})
怒られない。ただしItemがない。
{
"ResponseMetadata": {
"RequestId": "xxxx",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"server": "Server",
"date": "Tue, 24 May 2022 16:26:45 GMT",
"content-type": "application/x-amz-json-1.0",
"content-length": "2",
"connection": "keep-alive",
"x-amzn-requestid": "xxxx",
"x-amz-crc32": "2745614147"
},
"RetryAttempts": 0
}
}
こんな感じ。
put_item()
正常系
確認日: 2022-05-25
item = {'pk_id': 'test'}
res = table.put_item(Item=item)
問題なく動く。
{
"ResponseMetadata": {
"RequestId": "xxxx",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"server": "Server",
"date": "Tue, 24 May 2022 17:21:29 GMT",
"content-type": "application/x-amz-json-1.0",
"content-length": "2",
"connection": "keep-alive",
"x-amzn-requestid": "xxxx",
"x-amz-crc32": "2745614147"
},
"RetryAttempts": 0
}
}
PKがない
確認日: 2022-05-25
item = {'hoge': 'test'}
res = table.put_item(Item=item)
怒られる。
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the PutItem operation: One or more parameter values were invalid: Missing the key pk_id in the item
PKの属性名まで表示される。
delete_item()
以下のようなPKだけのシンプルなテーブルに対する操作とする。
Attr | Value |
pk_id | test |
正常系
確認日: 2022-05-25
res = table.delete_item(Key={'pk_id': 'test'})
正常に動く。
{
"ResponseMetadata": {
"RequestId": "xxxx",
"HTTPStatusCode": 200,
"HTTPHeaders": {
"server": "Server",
"date": "Tue, 24 May 2022 17:26:32 GMT",
"content-type": "application/x-amz-json-1.0",
"content-length": "2",
"connection": "keep-alive",
"x-amzn-requestid": "xxxx",
"x-amz-crc32": "2745614147"
},
"RetryAttempts": 0
}
}
PK自体がない
確認日: 2022-05-25
res = table.delete_item(Key={'hoge': 'test'})
怒られる。
botocore.exceptions.ClientError: An error occurred (ValidationException) when calling the DeleteItem operation: The provided key element does not match the schema
PKの値が存在しない
確認日: 2022-10-03
res = table.delete_item(Key={'pk_id': 'test0'})
怒られない。
関連記事
aws の記事
- [2023年3月27日] Pythonで深いネストのlistやDictの値を調べてDecimalがあればint or floatに変換する
- [2023年3月21日] motoでDynamoDBのMockを作成する
- [2023年3月18日] DynamoDBのテーブル設計をテキストで記述したいのでChatGPT-4に教えてもらった
- [2022年12月1日] CognitoのIDトークンをLambda関数で検証するサンプルコード
- [2022年7月11日] API Gateway + Cognito Authorizer + Lambda関数でeventから得られるjsonのメモ
- ---本記事---
- [2022年4月13日] RAK7246にBasic Stationを入れてAWS LoRaWAN NetworkServerに接続
- [2022年1月18日] 2022年1月18日 DyanmoDB、メタバース、アキネータ
- [2021年8月23日] AWS SAMでDynamoDBテーブルを作成する時のテンプレート
- [2021年6月12日] DynamoDBの多対多で隣接リストやった時の冗長性対策どうしよう
- [2021年5月13日] Lambda関数でDeadLetterQueue(DLQ)を試す
スポンサーリンク