AWS LambdaでDynamoDBからレコードを削除するサンプルを紹介します。
言語はpythonになります。
DynamoDBからレコードを削除するサンプル(python)
import boto3
from boto3.dynamodb.conditions import Key
dynamoClient = boto3.client('dynamodb')
def delete_record():
# 削除対象のレコードのキー
param_patitionKey = 'partitionKey'
param_sortKey = 'sortKey'
# 削除を実施
try:
response = dynamoClient.delete_item(
TableName='tableName',
Key={
'KeyName_PartitionKey': { 'S': param_patitionKey },
'KeyName_SortKey': { 'S': param_sortKey }
}
)
except Exception as e:
print('DynamoDBアイテム削除中に想定外のエラーが発生しました。')
print(e)
return False
print('Dynamoアイテムの削除完了。response = ' + str(response))
return True