LoginSignup
1
0

Codepipeline クロスアカウント & クロスリージョン 対応 Ch.2

Posted at

これは何?

Codepipeline クロスアカウント 対応 Ch.1の続きになります。

前回はクロスアカウント対応ということで以下のようなクロスアカウント構成を作成しました。
image.png

今回は、前回プラスマルチリージョンにも適用できるような構成にしたいと考えます。
image.png

設定内容

各種アカウントの設定は以下の通りになります。
前回からの変更部分だけを記載します。

  • 開発者向けアカウント(Developer Account)
リソース 役割
CodeCommit なし
アーティファクト格納用IAMロール Region YのKMSキーやS3バケットへのアクセス権限を付与する
  • サービス用アカウント(Account A)
リソース 役割
Codepipeline CLIを更新(後述).
Codebuild Codebuild プロジェクトをRegion Y上にも作成
S3バケット Region Yにもアーティファクト用バケットを作成
KMSキー KMSキー. キーポリシーでDeveloper Accountからのアクセスを許可.
Codepipeline用IAMロール Region YのKMSへのアクセス権限.
CodeBuild用IAMロール KMSへのアクセス権限.

構築テンプレート

前回からの変更点としては、Jsonファイルの更新は結構簡単で、追記する内容としては、「artifactStores」と「Build」ステージで、Region Y(今回はus-east-1を想定)のS3やKMSキー、Buildプロジェクトを指定。
json内の「<< 〇〇 >>」で始まる部分をそれぞれ設定したパイプライン名に置き換えてください。

pipeline.json
 {
     "pipeline": {
         "name": "<<Codepipeline名>>",
         "roleArn": "<<Codepipeline用IAMロール>>",
         "artifactStores": {
             "ap-northeast-1": {
                 "type": "S3",
                 "location": "<<S3バケット>>",
                 "encryptionKey": {
                     "id": "<<KMSキーArn>>", 
                     "type": "KMS"
                 }
             },
             "us-east-1": {
                 "type": "S3",
                 "location": "<<S3バケット>>",
                 "encryptionKey": {
                     "id": "<<KMSキーArn>>", 
                     "type": "KMS"
                 }
             }
         },
         "stages": [
             {
                 "name": "Source",
                 "actions": [
                     {
                         "name": "Source",
                         "actionTypeId": {
                             "category": "Source",
                             "owner": "AWS",
                             "provider": "CodeCommit",
                             "version": "1"
                         },
                         "runOrder": 1,
                         "configuration": {
                             "OutputArtifactFormat": "CODE_ZIP",
                             "PollForSourceChanges": "true",
                             "RepositoryName": "<<CodeCommitリポジトリ名>>"
                         },
                         "outputArtifacts": [
                             {
                                 "name": "SourceArtifact"
                             }
                         ],
                         "inputArtifacts": [],
                         "roleArn": "<<アーティファクト格納用IAMロール>>",
                         "region": "ap-northeast-1",
                         "namespace": "SourceVariables"
                     }
                 ]
             },
             {
                 "name": "Build",
                 "actions": [
                     {
                         "name": "BuildTokyo",
                         "actionTypeId": {
                             "category": "Build",
                             "owner": "AWS",
                             "provider": "CodeBuild",
                             "version": "1"
                         },
                         "runOrder": 1,
                         "configuration": {
                             "PrimarySource": "SourceArtifact",
                             "ProjectName": "<<Codebuild名>>",
                             "EnvironmentVariables": "[]" 
                         },
                         "outputArtifacts": [
                             {
                                 "name": "BuildArtifactTokyo"
                             }
                         ],
                         "inputArtifacts": [
                             {
                                 "name": "SourceArtifact"
                             }
                         ],
                         "region": "ap-northeast-1",
                         "namespace": "BuildVariablesTokyo"
                     },
                    {
                         "name": "BuildVirginia",
                         "actionTypeId": {
                             "category": "Build",
                             "owner": "AWS",
                             "provider": "CodeBuild",
                             "version": "1"
                         },
                         "runOrder": 1,
                         "configuration": {
                             "PrimarySource": "SourceArtifact",
                             "ProjectName": "<<Codebuild名>>",
                             "EnvironmentVariables": "[]" 
                         },
                         "outputArtifacts": [
                             {
                                 "name": "BuildArtifactVirginia"
                             }
                         ],
                         "inputArtifacts": [
                             {
                                 "name": "SourceArtifact"
                             }
                         ],
                         "region": "us-east-1",
                         "namespace": "BuildVariablesVirginia"
                     }

                 ]
             }
         ]
     }
 }

修正が完了したらCLIで以下のコマンドを実行します。

aws codepipeline create-pipeline --pipeline file://pipeline.json

終わりに

これでマルチアカウント & マルチリージョンでCI/CDパイプラインを実行することができます。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0