LoginSignup
0
0

More than 1 year has passed since last update.

AppSyncのリゾルバーでUUIDの発行

Last updated at Posted at 2022-12-07

概要

この記事では、AppSyncのリゾルバーでUUIDを発行しDynamoDBに登録する方法を紹介します。

前提条件

  • AppSyncのスキーマができていること
  • DynamoDBが用意されていること

リゾルバー

リクエストマッピングテンプレート

{
  "version": "2017-02-28",
  "operation": "PutItem",
  "key": {
    "id": $util.dynamodb.toDynamoDBJson($util.autoId())
  },
  "attributeValues": $util.dynamodb.toMapValuesJson($ctx.args.input),
    "condition": {
    "expression": "attribute_not_exists(#id)",
    "expressionNames": {
      "#id": "id"
    }
  }
}

$util.autoId()でUUIDを発行できます。

レスポンスマッピングテンプレート

$util.toJson($ctx.result)

実行

  • クエリを実行する
    • 画面左が実行クエリ、画面右が実行結果
      クエリ
  • DynamoDBにデータが登録されていることの確認
    DynamoDB
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