Lambdaに記述する関数の中ではAWS内での予約語に注意して記述する。
たとえば”name”のようなDBのキーとなっていそうなものは、ExpressionAttributeNames={"#name": "name"},
上のように、この"name"はカラム名として使用しますよ、宣言することで使用可能となる。
DynamoDBにputする場合の関数の例。
demo.py
def post_users(requestJSON):
table.update_item(
Key={"id": requestJSON["id"]},
UpdateExpression="SET #name = :newName, age = :newAge, address = :newAddress, tel = :newTel",
ExpressionAttributeNames={"#name": "name"},
ExpressionAttributeValues={
":newName": requestJSON["name"],
":newAge": requestJSON["age"],
":newAddress": requestJSON["address"],
":newTel": requestJSON["tel"],
},
)
他の変数名と異なり、“name”は、#nameとして、UpdateExpressionの中で使用する。