[レポート] DEV308: DevOpsの黒帯化 – AWS CloudFormationによるデプロイシナリオ #reinvent

2018.11.27

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

Earn Your DevOps Black Belt: Deployment Scenarios with AWS CloudFormation

re:Invent 2018にてセッション「Earn Your DevOps Black Belt: Deployment Scenarios with AWS CloudFormation」を聴講したのでレポートします。

AWS CloudFormation, in combination with other tools for continuous integration and delivery pipelines, can help automate and standardize frequent deployments for many types of applications, from traditional compute and autoscaling groups to serverless applications. In this session, we will present several use cases combining CloudFormation with build and pipeline automation tools to achieve repeatable, consistent and compliant deployments without sacrificing agility.

Agenda

  • CI/CD for Infrastructure
  • Building as infrastructure pipeline
  • Testing and Validation
  • Full Stack deployment examples
  • Serverless deployment

CloudFormationのGlance

  • Infrastructure as Code
    • YAML or JSON
    • Upload local files to S3 Bucket
    • Create Stack

CI/CD Infrastructure

  • Source -> Build -> Test -> Promote
  • この過程で 継続的インテグレーション / 継続的デプロイ / 継続的デリバリ

Infrastructure as is Code!

  • Source: 全てをバージョンコントロール
  • Build: 静的解析とユニットテスト
  • Test: 結合テストのためのインフラのクリーン
  • Promote: 実際の環境へのデプロイ

Version Control Everything

  • Template
  • Parameter files
  • Helper scripts
  • Configuration files

Static Analytics

  • Build tools or even a Lambda Function
  • シンタックスバリデート : cfn-lint
  • ガバナンス、ビジネスロジックのバリデート : cfn_nag
  • 失敗したらエラーを通知

Integration Testing

  • Catch problems that are'nt obious in a single template/stack
  • TaskCatでマルチリージョンでのStack構築をシミュレート
  • レポートを各リージョンで生成

Deploy to all environments

  • 各環境ごとにビルド、バリデート、CI/CD
  • BGかIn-placeか決める
  • オーケストレーションツールの利用
  • マルチアカウント&マルチリージョンのデプロイのためのスタックセット
  • 必要に応じて承認フローの導入

Infrastructure CI/CD - SaaS Tools

上記までに説明した内容でインフラストラクチャがAWSサービスで構築可能。

Infrastructure CI/CD - DIY Tools

同様の内容をTravisCIやJenkinsを利用しながら自作した場合のパターン。

Demo - Infrastructure testing

以下のリポジトリのインフラテストをデモ。

TravisCI上でcfnlintで落ちていることが分かります。

該当コードを修正することでJobが通るようになります。

Full stack deployment

  • Application: Application code/artifacts
  • Platform: App servers/LB/DBs
  • Infrastructure: Network, Compute, Storage

以下はツールの例。

Full stack deployment - Containers

Platform部分がContainerに置き換わる。

Full stack deployment - Serverless

Applicationの割合が増え、マネージドな部分が増える。

Full stack deployment - ストラテジー

  • ライフサイクルによってリソースをグルーピング
  • リソースを短期利用か長期利用かで分ける
  • ステートフルなリソースを独立させる

Example (EC2)

Architecture

  • Infrastructure (Monthly)
  • Application (Daily)

Example (Container)

ContainerPipeline

  • Environment
    • VPC / ASG / ALB / Cluster
  • Service
    • Service
    • Target
    • Task def
    • Listener

Container based microservice Management

  • MuというOSSが便利
  • マイクロサービスを管理
  • パイプラインの構築、サービスのデプロイ、環境の管理
  • ネイティブサービス(AWS CodePipeline / AWS CodeBuild / AWS CloudFormation)の利用

Demo - Full stack development

以下のリポジトリを元にしたデモが披露されました。

Muを利用したパイプライン。承認フローも組み込まれています。

AWS Serverless Application Model (SAM)

  • CloudFormationの拡張
  • Serverlessの新しいリソースタイプ: Function, API, Table
  • AWS CloudFormationのサポート
  • SAM Translatorがオープンソース化

Serverless Development CI/CD with SAM

Takeaways(これだけは持ち帰ってね)

  • インフラ定義をコードに
  • 全てをバージョンコントロール下に
  • 全てをテスト
  • ライフサイクルでリソースをグルーピング
  • デプロイ全体をパイプラインで

まとめ

EC2、コンテナ、サーバーレスと各構成のDevOpsについて包括的にまとめられており、次々と増え続けるサービスの全容が頭の中で整理できました。Muは便利そうなので使ってみたいと思います。