Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Next.js × AWS App Runner × AWS AppSyncで進めるクライアン...
Search
Haruna Oka
September 23, 2023
Programming
7
6.2k
Next.js × AWS App Runner × AWS AppSyncで進めるクライアントファーストのWEB開発
2023/09/23に開催されたServerlessDays Tokyo 2023で登壇した資料です
Haruna Oka
September 23, 2023
Tweet
Share
More Decks by Haruna Oka
See All by Haruna Oka
AWS AppSyncと仲良くするためのTips
okaharuna
1
180
re:Growth 2020 Serverless
okaharuna
2
1.4k
EventBridgeでAWSとShopifyの統合
okaharuna
2
6.2k
Serverless SPA development starting with Angular
okaharuna
0
3.4k
serverlessdaysfukuoka_oka.pdf
okaharuna
1
2.2k
SPA×Auth0
okaharuna
5
2.1k
Fargate_Super_Introduction.pdf
okaharuna
2
3.2k
Other Decks in Programming
See All in Programming
OCaml 5でモダンな並列プログラミングを Enjoyしよう!
haochenx
0
160
CSC307 Lecture 11
javiergs
PRO
0
580
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
180
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
1.7k
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
170
NOT A HOTEL - 建築や人と融合し、自由を創り出すソフトウェア
not_a_hokuts
2
360
Apache Iceberg V3 and migration to V3
tomtanaka
0
210
CSC307 Lecture 09
javiergs
PRO
1
850
Amazon Bedrockを活用したRAGの品質管理パイプライン構築
tosuri13
5
870
Rails Girls Tokyo 18th GMO Pepabo Sponsor Talk
yutokyokutyo
0
140
Metaprogramming isn't real, it can't hurt you
okuramasafumi
0
120
株式会社 Sun terras カンパニーデック
sunterras
0
1.8k
Featured
See All Featured
HDC tutorial
michielstock
1
430
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
260
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
1
1.4k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
59
50k
Automating Front-end Workflow
addyosmani
1371
200k
Ruling the World: When Life Gets Gamed
codingconduct
0
150
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.4k
What does AI have to do with Human Rights?
axbom
PRO
0
2k
We Are The Robots
honzajavorek
0
180
How STYLIGHT went responsive
nonsquared
100
6k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4k
Prompt Engineering for Job Search
mfonobong
0
170
Transcript
Next.js × AWS App Runner × AWS AppSync で進める クライアントファーストのWEB
開発 岡 春奈
自己紹介 名前: 岡 春奈 Twitter: @OkaHaruna 職業: フリーランスエンジニア 趣味:
猫とラーメン
今入っている案件のアーキテクチャをベースに話します バックエンド周り(AppSync) の話がメインです 本日の内容について
アーキテクチャー図
CDN はクローリング対策のためCloudflare を選択 Auth0 は高すぎて断念 Workers, R2 も検討対象になったが冒険になってしま うため断念 技術スタックの選定理由
Amplify に頼らないAppSync 構築 リゾルバー実装 GraphQL Code Generator の活用 AppSync Topic
Amplify に頼らないAppSync 構築 IaC はCDK を利用 とは言いつつ実は当初はAmplify CLI で構築されていた (
初期構築時フロントメンバーしかいなかった為) カスタマイズ性と長期運用を見越してCDK に移行
2022/11 にJavaScript リゾルバーがリリース CDK のカスタムコンストラクタを利用してデプロイ時 にコンパイル 利用するリゾルバは3 種類 ユニットリゾルバー パイプラインリゾルバー
Lambda リゾルバー リゾルバー実装
リゾルバー実装 https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html 公式でesbuild を使う方法を 紹介してるのでこれに倣う
リゾルバー実装(ビルド用のutility )
リゾルバー実装(ユニットリゾルバー)
リゾルバー実装(パイプラインリゾルバー)
リゾルバー実装(Lambda リゾルバー)
@aws-appsync/utils/dynamodb がアップデート リゾルバー実装 - DynamoDB にアクセス -
@aws-appsync/utils/dynamodb がアップデート リゾルバー実装 - DynamoDB にアクセス -
@aws-appsync/eslint-plugin でリゾルバーのチェック (esbuild-plugin-eslint でビルド時に実行も可) リゾルバー実装 - Lint -
基本的にはユニットリゾルバーで済ませる 認証の処理を挟むときはパイプラインリゾルバー Lambda リゾルバーも必要になった時のみ 例) 署名付きURL の発行、等 管理コストを下げるため 同時実行数を気にしたくないため リゾルバーの使い分け
util.autoUlid() を使ってID はULID に統一 ID で時系列のソートが可能 TransactWriteItems 等、1 つの関数内で複数のデータソ ースにアクセスしたい時は
dataSource.grantPrincipal.addToPrincipalPolicy() リゾルバーのTips
urql を利用 Apollo よりもシンプルに実装できるため エンドポイント毎の認証切り替えには @urql/exchange-auth を使う GraphQL クライアント
operation ファイルはAmplify で生成 (query GetContent($id: ID!)... の定義ファイル) plugin を使ってurql のhook
まで自動生成 typescript typescript-operations typescript-urql CodegenConfig.hooks.afterAllFileWrite で整形 GraphQL Code Generator の活用
デフォルトで構造化ログが出力される →CloudWatch Insight で検索可能 開発環境はfieldLogLevel をALL にしておく xrayEnabled でxray を有効化しておく
他Tips
開発プロセスについて
Next.js, CDK, API 全てTypescript の為モノレポに 管理ツールにTurborepo を選択した理由 Nx はオーバースペックだった 必要以上に設定を共通化せず開発に支障が出ないのを
第一に Prettier はルートで共通化( 分けたかったらoverrides) ESLint は各パッケージで実行、等 Turborepo でのモノレポ管理
AWS のリソースは全てCDK に集約 Cloudflare のリソースはTerraform で実装中 IaC - CDK とTerraform
-
環境毎のアカウントにOIDC でアクセスしてデプロイ CI/CD
速度重視のためトランクベースを採用 AWS の公式Doc でも「Gitflow はレガシー」と書か れているため https://docs.aws.amazon.com/prescriptive- guidance/latest/strategy-cicd-litmus/fully- cicd-process-differences.html CI/CD
もう少しCloudflare 使っていきたい テストやエミュレートがしづらい npm workspace 辛い(pnpm かbun に移行したい) 頻繁な仕様変更に伴うDynamoDB の設計が難しい
課題感
MVP 開発とサーバーレスは相性抜群 Amplify はライブラリだけ局所的に使うのがおすすめ GraphQL とREST は今後も使い分けていく まとめ