0
0

Lambda 予約語について注意

Posted at

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の中で使用する。

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