1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AWS AppSyncでAPIを作ってみたAdvent Calendar 2022

Day 2

AppSync×DynamoDB(READ編)

Last updated at Posted at 2022-12-01

概要

AppSyncとDynamoDBを使用した簡易的なAPIの作成方法を紹介します。

この記事では、DBのデータを取得する処理を紹介します。

前提条件

  • DynamoDBが用意されていること

AppSync

スキーマ

#登録処理(前の記事で作成済み)
input CreateRadioInput {
  id: ID!
  program_name: String
  cast: [String!]
  weekday: Int
  time: String
  favorite: Boolean
}

type Mutation {
  createRadio(input: CreateRadioInput!): Radio #登録処理(前の記事で作成済み)
}

type Query {
  getRadio(id: ID!): Radio
}

type Radio {
  id: ID!
  program_name: String
  cast: [String!]
  weekday: Int
  time: String
  favorite: Boolean
}

リゾルバー

  • リゾルバーのQueryからgetRadio(...): Radioアタッチを選択

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

{
  "version": "2017-02-28",
  "operation": "GetItem",
  "key": {
  "id": $util.dynamodb.toDynamoDBJson($ctx.args.id)
  }
}

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

$util.toJson($ctx.result)

実行

  • クエリを実行する
    • 画面左が実行クエリ、画面右が実行結果
      クエリ
1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?