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

government-cloud-ecs-iac-cicd

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
Avatar for kenicazu kenicazu
May 09, 2026
3

 government-cloud-ecs-iac-cicd

Avatar for kenicazu

kenicazu

May 09, 2026

More Decks by kenicazu

Transcript

  1. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. Amazon Confidential and Trademark. ガバメントクラウドで始める CI/CDパイプライン : 明⽇からの実践ガイド 後半パート 2024/11/5 アマゾン ウェブ サービス ジャパン株式会社 パブリックセクター 東 健⼀ 1
  2. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. 東 健⼀ (Kenichi Azuma) <職務内容> • 中央省庁のお客様を担当する ソリューションアーキテクト § デジタル庁、経産省、厚⽣労働省・⽀払基⾦、こども家庭庁、関連外郭団体 の案件を中⼼にご担当させていただいております。 • コンテナ利⽤に関わる案件のご⽀援(EKS、App Runner、ECS) § EKS / Istio によるサービスメッシュ ワークショップ <趣味> • 散歩、家でゆっくりすること、銭湯 是⾮みなさまの知⾒を私も学ばせてください。 本⽇はよろしくお願いいたします︕
  3. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. はじめに
  4. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. はじめに • 今年9⽉に開催された AWS Innovate でお話しした内容をベースにお話しいたします • ⽐較的抽象的な内容となりますが、もし興味がある⽅はご覧いただけますと幸いです。 © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. Kenichi Azuma アマゾン ウェブ サービス ジャパン合同会社 ソリューションアーキテクト ステップバイステップで考える Amazon ECS の CI/CD と IaC T 5 - 4
  5. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. はじめに 本パートでは⾚枠の部分にフォーカスし、ECS/CDKを中⼼に説明 Infrastructure as Code (IaC) Step3 Step2 テスト⾃動化 CI/CD Step1 マネージドサービス (コンテナ) マネージドサービス (サーバレス) セキュリティの シフトレフト オブザーバビリティ Git リポジトリ インフラストラクチャ アプリケーション CI/CD パイプライン 設定と Observability IaC を中⼼として チームがコラボレーションする IaC は ガバメントクラウド移⾏ に求められるモダン化の⼟台
  6. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon ECS の IaC と CI/CD について
  7. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon VPC Private subnet Public subnet Amazon ECS でコンテナを動かすまでのステップ Amazon ECS で Web アプリケーションをデプロイする場合・・・ Application Load Balancer Amazon ECR Amazon ECS Image Task Definition Service ② AWS Fargate Amazon RDS ① ③ ④ IAM Role インフラ 担当 アプリ担当 インフラ 担当 ① 関連するリソースの作成 • ECS クラスター、ECR • VPC、RDS 等 アプリ 担当 ② コンテナイメージ Push ③ タスク定義の作成 ④ サービスの作成(デプロイ)
  8. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. ECS で アプリケーションをデプロイするときの選択肢 アプリケーション Task Definition, Service インフラストラクチャ ECS クラスター VPC, ALB, ECR など • ecspresso ( on AWS CodeBuild ) • AWS CodePipeline ECS デプロイ • AWS CodeDeploy ( B/G デプロイ ) • AWS CDK ( on AWS CodeBuild ) • Terraform ( on AWS CodeBuild ) • AWS CodePipeline CloudFormation デプロイ • Amazon CodeCatalyst 管理のスコープをどうするか、デプロイツールで対応しているデプロイ⽅式 (ローリングアップデート、B/G デプロイ等)も踏まえ、ツールを選定 アプリケーション ( ECS サービス ) の 柔軟なデプロイ インフラも含めた 包括的なデプロイ
  9. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. ローリングアップデートと B/G デプロイについて AWS Dev Day 2022 Blue / Green デプロイと安全性と複雑性と まずはローリングアップデート(例︓CodePipeline ECS Deploy アクション)で要件を満たせるか 検証しつつ、プロジェクトやチームの特性を踏まえて判断 -> 特定ユーザ向け(省内利⽤等)の場合は B/G デプロイを選択せずに シンプルな構成を取ることも可能なケースが多いと推察
  10. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. ECS の 環境を CDK で ⼀括管理する CDK Template Amazon ECS • Docker Image Assets コンストラクトなどを使⽤し 、コンテナのビルドも CDK のライフサイクル に含めて実装することが可能 • 必須適⽤テンプレートやその他のインフラストラクチャと同じ様に CDK で管理したいケースや 同⼀のソースコード / リポジトリ で管理したいケースに適⽤可能 v1.0.0 v1.0.0 Task Definition Service Application Load Balancer Amazon RDS Amazon VPC AWS CDK ・・・ Amazon ECR Image GitHub
  11. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. (参考) BLEA の ECS App サンプル BLEA におけるECSアプリケーションのサンプルについても全て CDK で管理 ※ コンテナイメージは Docker Hubから取得して利⽤している
  12. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. Amazon VPC Private subnet Public subnet 全て CDK で 管理する場合の注意事項(1/2) • ECS におけるタスク定義やサービス、コンテナイメージ等は VPC や RDS、ECS クラスター といったリソースとはライフサイクル、デプロイの頻度が異なるケースが多い • ⼀⽅で担当チームが分かれている場合は、別チームのデプロイの際にパイプラインが⼀緒に実⾏さ れてしまうため、管理が難しい。(スタックを分ける等で解決可能な場合もある) -> 現場ではインフラチームとアプリチームが分かれていることが多い Application Load Balancer Amazon ECR Amazon ECS Image Task Definition Service Amazon RDS IAM Role 責務︓アプリチーム デプロイ頻度︓⾼ 責務︓インフラチーム デプロイ頻度︓低
  13. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. 全て CDK で 管理する場合の注意事項(2/2) • Docker Image Assets の 仕様に依存したデプロイとなる • ECS の デプロイはローリングアップデートのみ対応 • ⼀時的にPushされるECRリポジトリが作成される / 任意のリポジトリやタグを利⽤できない • cdklabs にある cdk-docker-image-deployment を⽤いることで 任意の ECRリポジトリの利⽤や タグの付与は可能となるが、2024/11時点ではCDKの正式なコンストラクトではない • また、各レイヤーのテスト等をパイプラインに⼊れるとパイプライン全体の実⾏時間が⻑期化する
  14. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. (参考)GCAS におけるリファレンスアーキテクチャ CodeBuildで各種テスト・ コンテナイメージビルド / ブランチごとにデプロイ先を変更 CodeBuildで各種テスト・ cdk deployコマンドの実⾏ / ブランチごとにデプロイ先を変更
  15. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. (参考)GCAS におけるリファレンスアーキテクチャ CodeBuildで各種テスト・ コンテナイメージビルド / ブランチごとにデプロイ先を変更 CodeBuildで各種テスト・ cdk deployコマンドの実⾏ / ブランチごとにデプロイ先を変更 インフラストラクチャとアプリケーションのデプロイを 別のパイプラインとして管理することで柔軟なデプロイを実現
  16. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. (参考)GCAS におけるリファレンスアーキテクチャ CodeBuildで各種テスト・ コンテナイメージビルド / ブランチごとにデプロイ先を変更 CodeBuildで各種テスト・ cdk deployコマンドの実⾏ / ブランチごとにデプロイ先を変更 インフラストラクチャとアプリケーションのデプロイを 別のパイプラインとして管理することで柔軟なデプロイを実現 ↓ いざチャレンジ︕する前に少し整理・注意が必要
  17. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. ECS リソースを管理する際の注意事項 Template v1.0.0 AWS CodeDeploy v1.0.0 IaC による インフラデプロイ 別のデプロイツールによる ECS サービスのデプロイ • CodeDeploy 等の別サービス経由で コンテナイメージや ECS サービスを更新した場合、 タスク定義・サービスの設定が IaC の記述内容と乖離が⽣じる • ECS の設定更新を IaC から実施する際に、 意図せぬ状態となる恐れがある AWS CDK Task Count : 2 Task Def Revision : 1 Application Task Count : 2 Task Def Revision : 2 ↓ Task Def Revision : 4 Task Count : 4 Task Def Revision : 1 Template v1.1.0 v1.1.0 AWS CDK v1.0.1 v1.0.2 v1.0.3 ① ECS サービスを含めた 各リソースのデプロイ ② アプリケーションの変更等に伴い、 コンテナイメージを更新 タスク定義、サービスも併せて更新 ③ 負荷増⼤に伴い、 ECS サービスのタスク数を更新 ④ CDK の⽅ではタスク定義が リビジョン 1 のままとなっており、 デグレーションが発⽣ Infra
  18. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. 対策案 1 サービス、タスク定義は別管理とする AWS Account VPC・Subnet IAM ECS Cluster ECS Service A Task Task ECS Service B Task Task Container Image Container Image インフラストラクチャの IaC で管理するスコープ RDS Security Service ECR Repository Service B Application Infra Repository Service B アプリチーム インフラチーム ② ① Service A Application Service A アプリチーム ② • インフラストラクチャを管理する IaC と ECS サービス、タスク定義は別の管理とする • チームやプロジェクトの特性に応じて ECS サービス毎に異なるデプロイツールを使うことも可能 ecspresso CDK
  19. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodePipeline(インフラ) Amazon ECS ・・・ ECS Service ECS Task GitHub (インフラ) AWS CodeBuild AWS CDK AWS CodePipeline(アプリ) AWS CodeBuild Amazon ECR Image アプリ チーム インフラ チーム ①インフラチームが あらかじめ VPC や ECS クラスター、 ECR等を IaC(CDK等)作成 ②-2 アプリチームは開発からテスト、 ECS サービスのデプロイまで⾃分たちで実施 (インフラチームが作成したクラスターや VPC 等を利⽤) ②-1 インフラチームは インフラチームのスコープリソースを 適宜リリース・変更 Application Load Balancer Amazon RDS Amazon VPC GitHub (アプリ) 対策案 1 実装イメージ
  20. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. 対策案 2 コンテナイメージのみ別管理とする AWS Account VPC・Subnet IAM ECS Cluster Task Task Task Task Container Image Container Image インフラストラクチャの IaC で管理するスコープ RDS Security Service ECR Repository Service B Application Infra Repository アプリチーム インフラチーム • コンテナイメージのみ別管理とし、アプリチームはコンテナイメージビルドまで責務を持つ • ECS サービスや新しいイメージを⽤いた タスク定義の更新は インフラストラクチャの IaC で管理 ECS Service A ECS Service B Service A Application ① ② ② ③
  21. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. AWS CodePipeline(インフラ) Amazon ECS ・・・ ECS Service ECS Task AWS CodeBuild AWS CDK AWS CodePipeline(アプリ) AWS CodeBuild Amazon ECR Image アプリ チーム インフラ チーム ①インフラチームが あらかじめ VPC や ECS クラスター、 ECR 等を IaC(CDK 等)作成 ②アプリチームがコードを Push し コンテナイメージを ビルドして ECR に Push イメージタグをインフラチームに連携 GitHub (インフラ) GitHub (アプリ) Application Load Balancer Amazon RDS Amazon VPC ③アプリチームから連携された イメージタグをセットし、 ECS サービスをデプロイ 対策案 2 実装イメージ
  22. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. それぞれの管理⽅法の⽐較 • インフラストラクチャと ECS サービスの設定を含むアプリ ケーションは別のコードベース で管理 • 各チーム、担当が個別にパイプ ラインを管理し、デプロイ • アプリチームはアプリケーショ ンと ECS サービスを管理 • コンテナイメージ(アプリケー ション)以外の ECS サービスを含 めた全リソースを1つのコード ベースで管理 • アプリチームはアプリケーション を管理のみ、コンテナを PUSH す るまでが責務 • インフラチームが ECS サービスを 管理 IaC で全て管理 サービス、タスク定義は別管理 コンテナイメージのみ別管理 管理⽅法はあくまで⼀例。組織やプロジェクトの特性に合わせて導⼊の形式を検討 • IaC でコンテナイメージを 含め、全リソースを1つの コードベースで管理 • 1 チームで デプロイ • インフラ、アプリケーション、 ECS の設定を全て管理 コードの 管理 チームの 責務 ツールの 選定 • ツール選定の Ownership を チームに持たせることも可能 • ツール選定の Ownership をチーム に持たせることも可能 • 全て同⼀のツールで管理
  23. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. このあと実際にワークショップで体験しましょう
  24. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. このあと実際にワークショップで体験しましょう アプリチーム (プロジェクト個別) インフラチーム (プロジェクト個別) インフラチーム (プロジェクト共通) ステージング環境 インフラチーム (プロジェクト共通)
  25. © 2024, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. © 2024, Amazon Web Services, Inc. or its affiliates. All rights reserved. ありがとうございました