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

~Everything as Codeを諦めない~ 後からCDK

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

~Everything as Codeを諦めない~ 後からCDK

JAWS-UG 茨城 #11 CDK支部コラボ回

https://jawsug-ibaraki.connpass.com/event/379428/

Avatar for mu7889yoon / Yuta Nakamura

mu7889yoon / Yuta Nakamura

February 01, 2026
Tweet

More Decks by mu7889yoon / Yuta Nakamura

Other Decks in Technology

Transcript

  1. #jawsugibaraki #jawsug_cdk 今からお話しすること • (ざっくり)Everything as Codeとは • 後からCDKの恩恵を知っていただく ◦

    サンプル構成について軽く説明 ◦ 後からCDKで取り込む ▪ L1からL2へのリファクタリング ◦ AIにトラブルシュートしてもらう ▪ CDKがない時😢 ▪ CDKがある時(L1 Construct)🤣 ▪ CDKがある時(L2 Construct)🤣
  2. #jawsugibaraki #jawsug_cdk cdk migrate --stack-name sample-dev --from-path \ ./sample-dev.yaml --language

    typescript テンプレートを CDKに取り込む (CDK migrate) https://docs.aws.amazon.com/ja_jp/cdk/v2/guide/ref-cli-cdk-migrate.htm
  3. #jawsugibaraki #jawsug_cdk L1 constructからL2 constructへ (CloudFront Distributionの例) const distribution =

    new cloudfront.CfnDistribution(this, 'CloudFrontDistribution', { distributionConfig: { enabled: true, comment: '??? official website ????', defaultRootObject: 'index.html', httpVersion: 'http2', ipv6Enabled: true, priceClass: 'PriceClass_All', webAclId: webAcl.attrArn, origins: [ { id: config.originId, domainName: bucket.attrRegionalDomainName, originAccessControlId: originAccessControl.attrId, connectionAttempts: 3, connectionTimeout: 10, originCustomHeaders: [], originPath: '', originShield: { enabled: false, }, s3OriginConfig: { originAccessIdentity: '', }, }, ], defaultCacheBehavior: { targetOriginId: config.originId, viewerProtocolPolicy: 'redirect-to-https', cachePolicyId: MANAGED_CACHING_OPTIMIZED, compress: true, allowedMethods: ['HEAD', 'GET'], cachedMethods: ['HEAD', 'GET'], smoothStreaming: false, functionAssociations: [], lambdaFunctionAssociations: [], trustedSigners: [], trustedKeyGroups: [], fieldLevelEncryptionId: '', }, viewerCertificate: { cloudFrontDefaultCertificate: true, minimumProtocolVersion: 'TLSv1', }, restrictions: { geoRestriction: { restrictionType: 'none', locations: [], }, }, logging: { bucket: '', includeCookies: false, prefix: '', }, aliases: [], cacheBehaviors: [], customErrorResponses: [], originGroups: { quantity: 0, items: [], }, staging: false, continuousDeploymentPolicyId: '', }, }); const distribution = new cloudfront.Distribution(this, 'CloudFrontDistribution', { comment: '??? official website ????', defaultRootObject: 'index.html', httpVersion: cloudfront.HttpVersion.HTTP2, enableIpv6: true, priceClass: cloudfront.PriceClass.PRICE_CLASS_ALL, webAclId: webAcl.attrArn, enabled: true, defaultBehavior: { origin: s3Origin, viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.REDIRECT_TO_HTTPS, cachePolicy: cloudfront.CachePolicy.CACHING_OPTIMIZED, compress: true, allowedMethods: cloudfront.AllowedMethods.ALLOW_GET_HEAD, cachedMethods: cloudfront.CachedMethods.CACHE_GET_HEAD, smoothStreaming: false, }, minimumProtocolVersion: cloudfront.SecurityPolicyProtocol.TLS_V1, });
  4. #jawsugibaraki #jawsug_cdk Resources [~] AWS::CloudFront::Distribution CloudFrontDistribution CloudFrontDistribution └─ [~] DistributionConfig

    ├─ [-] Removed: .Aliases ├─ [-] Removed: .CacheBehaviors ├─ [-] Removed: .ContinuousDeploymentPolicyId ├─ [-] Removed: .CustomErrorResponses ├─ [~] .DefaultCacheBehavior: │ ├─ [~] .AllowedMethods: L1 constructからL2 constructへ
  5. #jawsugibaraki #jawsug_cdk Resources [~] AWS::CloudFront::Distribution CloudFrontDistribution CloudFrontDistribution └─ [~] DistributionConfig

    ├─ [-] Removed: .Aliases ├─ [-] Removed: .CacheBehaviors ├─ [-] Removed: .ContinuousDeploymentPolicyId ├─ [-] Removed: .CustomErrorResponses ├─ [~] .DefaultCacheBehavior: │ ├─ [~] .AllowedMethods: L1 constructからL2 constructへ 立ちはだかる大量の diff
  6. #jawsugibaraki #jawsug_cdk AIにトラブルシュートしてもらう - 検証条件 新人のフロントエンドエンジニアさん • developmentやmainにマージしたらgithub actionsが走ることは知ってる。 •

    AWSは全く知らないとする。 • ネットワーク関連の知識についても全く知らない。 • AIに指示されたことはできるとする。 ◦ Chromeの開発者モードを見る。 ◦ GitHub Actionsが成功しているか見る。 ◦ ただし、AWSのマネージドコンソールにはアクセスできない。
  7. #jawsugibaraki #jawsug_cdk AIにトラブルシュートしてもらう - 検証条件 新人のフロントエンドエンジニアさん • developmentやmainにマージしたらgithub actionsが走ることは知ってる。 •

    AWSは全く知らないとする。 • ネットワーク関連の知識についても全く知らない。 • AIに指示されたことはできるとする。 ◦ Chromeの開発者モードを見る。 ◦ GitHub Actionsが成功しているか見る。 ◦ ただし、AWSのマネージドコンソールにはアクセスできない。 この条件でよ〜んがロールプレイします
  8. #jawsugibaraki #jawsug_cdk AIにトラブルシュートしてもらう - 各条件 IaCがない時 CDKがある時(L2) CDKがある時(L1) . ├──

    .github │ └── workflows │ └── deploy-to-s3.yml ├── iac │ └── sample-l1 │ ├── bin │ ├── cdk.json │ ├── lib │ ├── migrate.json │ ├── package-lock.json │ ├── package.json │ ├── README.md │ ├── test │ └── tsconfig.json └── src └── index.html . ├── .github │ └── workflows │ └── deploy-to-s3.yml ├── iac │ └── sample-l2 │ ├── bin │ ├── cdk.json │ ├── lib │ ├── migrate.json │ ├── package-lock.json │ ├── package.json │ ├── README.md │ ├── test │ └── tsconfig.json └── src └── index.html . ├── .github │ └── workflows │ └── deploy-to-s3.yml └── src └── index.html
  9. #jawsugibaraki #jawsug_cdk AIにトラブルシュートしてもらう - 結果まとめ IaCがある時 CDKがある時(L2) CDKがある時(L1) やり取り回数 10↑

    1 1 トークン消費率 23% 12% 13% 解決できたか 未解決❌ 解決✅ 解決✅ 今回の条件下では L1とL2に有意差はなかった
  10. #jawsugibaraki #jawsug_cdk まとめ • 手段を問わずIaCすることが重要 ◦ L2 Constructで記述した方が、人間もわかりやすい 。 ▪

    機能追加があった時、インフラに手を加えやすい(はず) • 既存の環境をCDKの管理下におく作業 ◦ 答え合わせがしやすい。 ▪ cdk diffして、変更がなければOKのため • AIにやらせる。 ◦ 手放しで走らせるためにポリシーの設定だけやる
  11. #jawsugibaraki #jawsug_cdk まとめ • 手段を問わずIaCすることが重要 ◦ L2 Constructで記述した方が、人間もわかりやすい 。 ▪

    機能追加があった時、インフラに手を加えやすい(はず) • 既存の環境をCDKの管理下におく作業 ◦ 答え合わせがしやすい。 ▪ cdk diffして、変更がなければOKのため • AIにやらせる。 ◦ 手放しで走らせるためにポリシーの設定だけやる 後からCDK(IaC)アリ、むしろやるべき
  12. #jawsugibaraki #jawsug_cdk 参考 AI Agent 時代のソフトウェア開発の型 〜 Everything as Code

    で叡智を伝える 〜 https://pages.awscloud.com/rs/112-TZM-766/images/AWS-57_Development_AWS- Summit-JP-2025.pdf Everything as code - DevOps Guidance https://docs.aws.amazon.com/ja_jp/wellarchitected/latest/devops-guidance/everythi ng-as-code.html cdk migrate - AWS クラウド開発キット (AWS CDK) v2 https://docs.aws.amazon.com/ja_jp/cdk/v2/guide/ref-cli-cdk-migrate.html
  13. #jawsugibaraki #jawsug_cdk ありがとうございました • 後からCDKに対するモチベーション • Everything as Code •

    後からCDKによる恩恵 ◦ サンプル構成について ◦ サンプル構成をCDK管理下に ◦ L1 ConstructからL2 Constructへ ◦ トラブルシュートのシミュレーション • まとめ