
【VPC外リージョンサービス】
CodePipeline は、フルマネージド型の CI/CD(継続的インテグレーション/継続的デリバリー)オーケストレーションサービス です。
ソース取得(CodeCommit/GitHub/S3)から、ビルド(CodeBuild)、テスト、承認、デプロイ(CodeDeploy/ECS/EKS/Lambda/CloudFormation など)までのプロセスをStage(ステージ) として定義し、自動で実行することができます。
各ステージは、複数の Action(アクション) で構成され、Transition(トランジション) によって次のステージへと遷移します。ステージ内のアクションは直列・並列実行の両方に対応しており、柔軟なパイプライン設計が可能です。また、リリース前の品質保証を目的として Manual Approval(手動承認) ステップを挿入したり、Canary Deployment(カナリアデプロイ) や Blue/Green Deployment(ブルーグリーンデプロイ) といった高度なデプロイ戦略を組み込むこともできます。
パイプラインの実行トリガーは、コミットによる変更検知やスケジュールに基づいて行われます。この際、各ビルドやデプロイがどのソース変更に基づいて実行されたかを示す Source Revision を自動的に追跡できます。
Artifact(アーティファクト) は S3 に保存され、ステージ間で成果物として受け渡されます。機密情報や認証情報は AWS Secrets Manager や Systems Manager Parameter Store で安全に管理します。
さらに、Cross-Region Pipeline(クロスリージョンパイプライン) により複数リージョンにまたがるデプロイを行ったり、Cross-Account Deployment(クロスアカウントデプロイ) によって複数アカウント間で統一的なリリースを実施することも可能です。
重要用語
ユースケース
| 継続的インテグレーション/デリバリー(CI/CD)パイプライン | コードの変更をトリガーに、ビルド・テスト・承認・本番デプロイまでの一連のフローを自動化する。 |
| ステージングと本番の段階的リリース | dev → stg → prod のような複数ステージを定義し、テストや承認ステップを挟みながら順番にリリースしていく。 |
| マルチアカウント/マルチリージョンデプロイ | 別アカウントや別リージョンにまたがるデプロイステップをパイプラインに組み込み、大規模な環境のリリースを一元管理する。 |
ベストプラクティス
| ステージ分離と承認アクション | 本番リリース前に手動承認ステージを挟み、安全なデプロイフローを構築する。 |
| 小さなパイプラインの組み合わせ | マイクロサービスごとにパイプラインを分けて変更の影響範囲を限定する。 |
| CloudWatch Events連携 | パイプライン状態に応じて通知や自動アクションをトリガーする。 |
セキュリティ
| 関連サービス | 設定内容 |
|---|---|
| KMS(データの暗号化と鍵の安全管理) | - |
| Secrets Manager(機密情報の安全管理) | シークレット(秘密情報)の作成が推奨 Git認証情報・APIキー・環境設定パスワード |
| SSM Parameter Store(設定情報の一元管理) | パラメータ(Parameter)の作成が推奨 環境依存変数・リポジトリURL・APIキー |
| CloudTrail(操作履歴の記録・監査・追跡) | 【自動記録】 作成・更新・削除・設定変更は自動記録される。(コントロールプレーンAPI) データ操作は追跡できない(データプレーンAPI) |
| Config(リソースの構成状態・設定変更を記録) | 【Configが有効な場合】 パイプライン設定変更履歴・アーティファクト暗号化/ステージ設定の準拠評価 |
| GuardDuty(脅威を自動検出) | 【GuardDutyが有効な場合】 パイプライン改ざんのAPI異常検知 |
CodePipeline が実行ロールを引き受ける典型的な連携パターン
| 実行ロールを介して連携するサービス | 実行ロールにアタッチするポリシー |
|---|---|
| CloudWatch Logs | logs:CreateLogGroup logs:CreateLogStream logs:PutLogEvents |
| CloudWatch Metrics | cloudwatch:PutMetricData |
| ECR | ecr:DescribeImages ecr:GetAuthorizationToken ecr:BatchCheckLayerAvailability ecr:GetDownloadUrlForLayer ecr:BatchGetImage |
| S3 | s3:ListBucket s3:GetObject s3:PutObject s3:GetObjectVersion s3:GetBucketVersioning s3:PutObjectAcl |
| CodeCommit | codecommit:GetBranch codecommit:GetCommit codecommit:UploadArchive codecommit:GetUploadArchiveStatus codecommit:CancelUploadArchive |
| CodeBuild | codebuild:BatchGetBuilds codebuild:StartBuild |
| CodeDeploy | codedeploy:CreateDeployment codedeploy:GetApplication codedeploy:GetApplicationRevision codedeploy:GetDeployment codedeploy:GetDeploymentConfig codedeploy:RegisterApplicationRevision |
| CloudFormation | cloudformation:CreateStack cloudformation:DeleteStack cloudformation:DescribeStacks cloudformation:UpdateStack cloudformation:CreateChangeSet cloudformation:DeleteChangeSet cloudformation:DescribeChangeSet cloudformation:ExecuteChangeSet cloudformation:SetStackPolicy cloudformation:ValidateTemplate iam:PassRole |
| Lambda | lambda:InvokeFunction lambda:ListFunctions |
| ECS | ecs:DescribeServices ecs:DescribeTaskDefinition ecs:DescribeTasks ecs:ListTasks ecs:RegisterTaskDefinition ecs:UpdateService iam:PassRole |
| Step Functions | states:DescribeExecution states:DescribeStateMachine states:StartExecution |
| EventBridge | events:PutEvents |
| SNS | sns:Publish |
| Service Catalog | servicecatalog:ListProvisioningArtifacts servicecatalog:CreateProvisioningArtifact servicecatalog:DescribeProvisioningArtifact servicecatalog:DeleteProvisioningArtifact servicecatalog:UpdateProduct |
| AppConfig | appconfig:StartDeployment appconfig:GetDeployment appconfig:StopDeployment |
| Elastic Beanstalk | elasticbeanstalk:CreateApplicationVersion elasticbeanstalk:DescribeApplicationVersions elasticbeanstalk:DescribeEnvironments elasticbeanstalk:DescribeEvents elasticbeanstalk:UpdateEnvironment |
| Secrets Manager | secretsmanager:GetSecretValue |
| SSM Parameter Store | ssm:GetParameters |
| KMS | kms:Encrypt kms:Decrypt |
| GitHub (CodeStar Connections) | codestar-connections:UseConnection |
| Bitbucket (CodeStar Connections) | codestar-connections:UseConnection |
信頼ポリシー:CodePipeline
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "codepipeline.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
ログ・監視
| ログ出力先 | ログの種類 |
|---|---|
| CloudWatch Logs | ビルドログ |
標準メトリクス
| メトリクス名 | 説明 |
|---|---|
| ActionExecutionFailure | アクション失敗実行数 |
| ActionExecutionSuccess | アクション成功実行数 |
| PipelineExecutionFailure | パイプライン失敗実行数 |
| PipelineExecutionSuccess | パイプライン成功実行数 |
制限値(固定値/ハードリミット/ソフトリミット)
| ハードリミット | 制限値 |
|---|---|
| ステージ数/パイプライン | 50 |
| アクション数/ステージ | 50 |
| パイプラインあたりの合計アクション数 | 500 |
| ソフトリミット | 制限値 |
|---|---|
| パイプライン数/リージョン | 300 |
| Webhook数/リージョン | 300 |
| カスタムアクション数/リージョン | 50 |
AWS CLIのサンプルコード
| ステージ | プロバイダー | provider |
|---|---|---|
| Source | CodeCommit | CodeCommit |
| Source | GitHub (v2) | CodeStarSourceConnection |
| Source | S3 | S3 |
| Source | ECR | ECR |
| Build | CodeBuild | CodeBuild |
| Deploy | CloudFormation | CloudFormation |
| Deploy | ECS | ECS |
| Deploy | ECS (Blue/Green) | CodeDeployToECS |
| Deploy | Lambda | Lambda |
| Deploy | S3(静的ウェブサイト) | S3 |
| Deploy | CodeDeploy(EC2/オンプレミス) | CodeDeploy |
Source ステージのプロバイダー
CodeCommit
{
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "CodeCommit",
"version": "1"
},
"configuration": {
"RepositoryName": "my-repo",
"BranchName": "main"
}
}
GitHub (v2)
{
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "CodeStarSourceConnection",
"version": "1"
},
"configuration": {
"ConnectionArn": "arn:aws:codestar-connections:region:account:connection/xxxxx",
"FullRepositoryId": "owner/repo",
"BranchName": "main"
}
}
S3
{
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "S3",
"version": "1"
},
"configuration": {
"S3Bucket": "my-bucket",
"S3ObjectKey": "source.zip"
}
}
ECR
{
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "ECR",
"version": "1"
},
"configuration": {
"RepositoryName": "my-image",
"ImageTag": "latest"
}
}
Build ステージのプロバイダー
CodeBuild
{
"actionTypeId": {
"category": "Build",
"owner": "AWS",
"provider": "CodeBuild",
"version": "1"
},
"configuration": {
"ProjectName": "my-build-project"
},
"inputArtifacts": [{"name": "SourceOutput"}],
"outputArtifacts": [{"name": "BuildOutput"}]
}
Deploy ステージのプロバイダー
CloudFormation
{
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CloudFormation",
"version": "1"
},
"configuration": {
"ActionMode": "CREATE_UPDATE",
"StackName": "my-stack",
"TemplatePath": "BuildOutput::template.yaml",
"Capabilities": "CAPABILITY_IAM",
"RoleArn": "arn:aws:iam::account:role/CFNRole"
}
}
ECS
{
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "ECS",
"version": "1"
},
"configuration": {
"ClusterName": "my-cluster",
"ServiceName": "my-service",
"FileName": "imagedefinitions.json"
}
}
ECS (Blue/Green)
{
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CodeDeployToECS",
"version": "1"
},
"configuration": {
"ApplicationName": "my-app",
"DeploymentGroupName": "my-deployment-group",
"TaskDefinitionTemplateArtifact": "BuildOutput",
"TaskDefinitionTemplatePath": "taskdef.json",
"AppSpecTemplateArtifact": "BuildOutput",
"AppSpecTemplatePath": "appspec.yaml"
}
}
Lambda
{
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "Lambda",
"version": "1"
},
"configuration": {
"FunctionName": "my-function",
"UserParameters": "optional-parameters"
}
}
S3
{
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "S3",
"version": "1"
},
"configuration": {
"BucketName": "my-website-bucket",
"Extract": "true"
}
}
CodeDeploy
{
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "CodeDeploy",
"version": "1"
},
"configuration": {
"ApplicationName": "my-app",
"DeploymentGroupName": "my-deployment-group"
}
}
パイプラインを作成する(パライプライン設定ファイル 指定)
pipeline-config.json
{
"pipeline": {
"name": "MyPipeline",
"roleArn": "arn:aws:iam::123456789012:role/CodePipelineServiceRole",
"artifactStore": {
"type": "S3",
"location": "my-pipeline-artifact-bucket"
},
"stages": [
{
"name": "Source",
"actions": [
{
"name": "SourceAction",
"actionTypeId": {
"category": "Source",
"owner": "AWS",
"provider": "CodeCommit",
"version": "1"
},
"configuration": {
"RepositoryName": "my-repo",
"BranchName": "main"
},
"outputArtifacts": [
{
"name": "SourceOutput"
}
]
}
]
},
{
"name": "Build",
"actions": [
{
"name": "BuildAction",
"actionTypeId": {
"category": "Build",
"owner": "AWS",
"provider": "CodeBuild",
"version": "1"
},
"configuration": {
"ProjectName": "my-build-project"
},
"inputArtifacts": [
{
"name": "SourceOutput"
}
],
"outputArtifacts": [
{
"name": "BuildOutput"
}
]
}
]
},
{
"name": "Deploy",
"actions": [
{
"name": "DeployAction",
"actionTypeId": {
"category": "Deploy",
"owner": "AWS",
"provider": "ECS",
"version": "1"
},
"configuration": {
"ClusterName": "my-ecs-cluster",
"ServiceName": "my-service",
"FileName": "imagedefinitions.json"
},
"inputArtifacts": [
{
"name": "BuildOutput"
}
]
}
]
}
]
}
}
aws codepipeline create-pipeline \
--pipeline file://pipeline-config.json
パイプラインの一覧を表示する
aws codepipeline list-pipelines
パイプラインを表示する(パイプライン名 指定)
aws codepipeline get-pipeline \
--name MyPipeline
パイプラインを削除する(パイプライン名 指定)
aws codepipeline delete-pipeline \
--name MyPipeline
パイプラインを更新する(パライプライン設定ファイル 指定)
aws codepipeline update-pipeline \
--pipeline file://updated-pipeline-config.json
パイプラインを実行する(パイプライン名 指定)
aws codepipeline start-pipeline-execution \
--name MyPipeline
パイプライン実行状態を確認する(パイプライン名 指定)
aws codepipeline get-pipeline-state \
--name MyPipeline
CloudFormationのサンプルコード
Terraformのサンプルコード
料金計算
| 課金項目 | 説明 |
|---|---|
| アクティブパイプライン | 月あたりのアクティブなパイプライン数 |