Upgrade to Pro — share decks privately, control downloads, hide ads and more …

「AWS PDK」聞いたことありますか?

maki
February 02, 2024

「AWS PDK」聞いたことありますか?

第33回 JAWS-UG札幌 クラウド女子会コラボ 勉強会

maki

February 02, 2024
Tweet

More Decks by maki

Other Decks in Technology

Transcript

  1. About me { "Name": "Maki Fujiwara", "Location": "Hokkaido Sapporo", "BelongsTo":

    ["YUMEMI"], "Communities": [ "JAWS-UG Sapporo", "JAWS-UG CDK 支部", "Cloudflare Meetup CTS", "Cloudflare Meetup online", "AWS Carnival", "AWS Cafeteria" ] } 2
  2. AWS PDK AWS Project Development Kit The AWS Project Development

    Kit (PDK) provides building blocks for common patterns together with development tools to manage and build your projects. 8
  3. Getting started The AWS PDK lets you define your projects

    programmatically via the expressive power of type safe constructs available in one of 3 languages (typescript, python or java). This approach yields many benefits, including: 10
  4. Getting Start many benefits Ability to set up new projects

    within seconds, with all boilerplate already pre- configured. Receive updates to previously bootstrapped projects when new versions become available i.e: updated dependencies or lint configurations. Build polyglot monorepos, with build caching, cross-language build dependencies, dependency visualization and much more. Leverage codified patterns which vend project and infrastructure (CDK) code. 11
  5. Prerequisites Git Node.js 18 以上 (nvm, nodenv, docker など) Package

    Manager (npm, yarn, pnpm お好みで) Projen scaffolding ツール 日本では人気なさそう、海外だとCDK Daysで今でも発表ネタに awscdk-app-ts や awscdk-construct で使ったことがある方も ts, python, java, next.js, react などのテンプレートも増えている AWS CDK (TypeScript, Python, Java) 現状PDK側の対応がこの3言語 14
  6. 16

  7. Packageの種類 monorepo api website (Static website, React) infra (AWS CDK)

    Pipeline (CDKPipelines) Identity (Cognito) pdk-nag (cdk-nagよりマイルドな設定) Diagram (Drawio, Graphviz) 17
  8. Packages > API models libraries runtime Lambda handler documentation (OpenAPI,

    ) infrastructure (Diagram) Authorizations API Keys React Query Hooks Mocking Response (自動生成) 18
  9. プロジェクト開始時の作業 projenrc ファイルに必要最低限の設定だけ書いてビルドすると、 数秒でPackageが生成される mkdir my-project && cd my-project #

    プロジェクト作成 pdk new --package-manager=pnpm monorepo-ts # projenrc に追加したいパッケージの情報を追加 vim projenrc.ts # ビルド pdx build build | npx nx run-many --target=build --output-style=stream --nx-bail > NX Successfully ran target build for 0 projects 19
  10. projenrc.ts import { MonorepoTsProject } from "@aws/pdk/monorepo"; import { DocumentationFormat,

    Language, Library, ModelLanguage, TypeSafeApiProject, } from "@aws/pdk/type-safe-api"; import { javascript } from "projen"; // rename variable to monorepo for better readability const monorepo = new MonorepoTsProject({ name: "my-project", packageManager: javascript.NodePackageManager.PNPM, projenrcTs: true, }); 20
  11. const api = new TypeSafeApiProject({ parent: monorepo, outdir: "packages/api", name:

    "myapi", infrastructure: { language: Language.TYPESCRIPT, }, model: { language: ModelLanguage.SMITHY, options: { smithy: { serviceName: { namespace: "com.aws", serviceName: "MyApi", }, }, }, }, runtime: { languages: [Language.TYPESCRIPT], }, documentation: { formats: [DocumentationFormat.HTML_REDOC], }, library: { libraries: [Library.TYPESCRIPT_REACT_QUERY_HOOKS], }, handlers: { languages: [Language.TYPESCRIPT], }, }); 21
  12. // Web サイトを追加 const website = new CloudscapeReactTsWebsiteProject({ parent: monorepo,

    outdir: "packages/website", name: "website", typeSafeApi: api, }); // インフラを追加 const infra = new InfrastructureTsProject({ parent: monorepo, outdir: "packages/infra", name: "infra", cloudscapeReactTsWebsite: website, typeSafeApi: api, }); // 忘れないように注意 cdk.synth() のようなもの monorepo.synth(); 22
  13. |_ model/ - contains the Interface Definition Language (IDL) where

    you define your API. |_ handlers/ - contains the generated lambda stubs for your API operations |_ generated/ |_ runtime/ - generated types, client, and server code in the languages you specified |_ infrastructure/ - generated infrastructure |_ documentation/ - generated documentation in the formats you specified |_ library/ - generated libraries if specified |_ typescript-react-query-hooks - react hooks to call the API 23
  14. AWS PDK 導入メリット 1 Projenで一括管理 各Packageに生成される共通ファイル TSConfig (tsconfig.json, tsconfig.dev.json) pnpm

    (pnpm-lock.yaml, pnpm-workspace.yaml) Prettier (.prettierignore, .prettierrc.json) ESLint (.eslintrc.json) 各種.ignore (.gitignore, .npmignore) package.json 31
  15. AWS PDK 導入メリット 3 TypeSafe API TypeScript 前提にすると → WebもBackend

    APIもインフラも、全てTypeScriptに統一できるメリット◎ 他の言語(Python, Java)でも同様のメリットが得られる (未検証) → API Reference を見る限り、型を有効活用した開発体験ができそう → AWS CDK で対応済み言語は、今後対応される可能性? 33
  16. 所感 PoCやPrototype, ミニマムスタートのプロジェクト向き? まだ v0.23.2 (Stable ではない) 先に AWS CDK

    に入門して少し慣れてからがいいかも? 爆速で環境構築ができる Package間の依存関係の可視化ができる アーキテクチャ図の生成にも期待 AWS CDKベースで生まれ変わる Amplify Gen2 との使い分けは? 34
  17. 35