CloudFormation で CodePipeline を実行
CloudFormation で CodePipeline を実行
リソースタイプ
リソースタイプ: AWS::CodePipeline::Pipeline
ref. AWS::CodePipeline::Pipeline
AWS::CodePipeline::Pipeline
Yaml
Type: AWS::CodePipeline::Pipeline
Properties:
ArtifactStore:
ArtifactStore
ArtifactStores:
- ArtifactStoreMap
DisableInboundStageTransitions:
- StageTransition
Name: String
RestartExecutionOnUpdate: Boolean
RoleArn: String
Stages:
- StageDeclaration
Tags:
- Tag
例
ActionTypeId の Category は Deploy 、 Provider は CloudFormation で ActionMode はCHANGE_SET_REPLACE の例です。
CHANGE_SET_REPLACE は変更セッのみを作成します。
DeployPipeline:
Type: "AWS::CodePipeline::Pipeline"
Properties:
# ...
Stages:
# ... -
- Name: ChangeSet
Actions:
-
Name: Foo
# ...
ActionTypeId:
Category: Deploy
Owner: AWS
Version: '1'
Provider: CloudFormation
# ...
Configuration:
ActionMode: CHANGE_SET_REPLACE # 変更セットを作成 CHANGE_SET_EXECUTEは実行
ChangeSetName: FooChangeSet
AWS::CodePipeline::Pipeline ActionDeclaration
ActionTypeId:
ActionTypeId
Configuration: Json
InputArtifacts:
- InputArtifact
Name: String
Namespace: String
OutputArtifacts:
- OutputArtifact
Region: String
RoleArn: String
RunOrder: Integer
ref. https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-properties-codepipeline-pipeline-stages-actions.html#cfn-codepipeline-pipeline-stages-actions-actiontypeid
AWS::CodePipeline::Pipeline ActionTypeId
アクションタイプは、アクションカテゴリとアクションプロバイダタイプの組み合わせで構成されます。
https://docs.aws.amazon.com/ja_jp/codepipeline/latest/userguide/reference-pipeline-structure.html
Category: String
Owner: String
Provider: String
Version: String
Category
Category A category defines what kind of action can be taken in the stage, and constrains the provider type for the action. Valid categories are limited to one of the values below.
- Source
- Build
- Test
- Deploy
- Invoke
- Approval
本ページで説明しているユースケースでは Source 、 Deploy 、Approval を使用します。
順序は以下のとおりです。
- Category Source: GitHub からソース取得
- Category Deploy:
ActionMode ActionMode: CHANGE_SET_REPLACE変更セット作成 - Category Approval: Deploy
承認 - Category Deploy:
ActionMode: CHANGE_SET_EXECUTE変更セット適用
Provider
各 Catergory ごとに使用できる Provider は以下を参照してください。
ref. https://docs.aws.amazon.com/ja_jp/codepipeline/latest/userguide/reference-pipeline-structure.html#actions-valid-providers
AWS::CodePipeline::Pipeline Configuration
ステージのアクションで CloudFormation をプロバイダーとして指定する場合は、Configuration プロパティ内で次のプロパティを定義します。
configuration:
ActionMode: CHANGE_SET_REPLACE
Capabilities: CAPABILITY_IAM,CAPABILITY_AUTO_EXPAND
ChangeSetName: pipeline-changeset
RoleArn: CloudFormation_Role_ARN
StackName: my-pipeline-stack
TemplateConfiguration: 'my-pipeline-stack::template-configuration.json'
TemplatePath: 'my-pipeline-stack::template-export.yml'
ref. AWS CloudFormation 設定プロパティのリファレンス
AWS::CodePipeline::Pipeline RunOrder
For example, if you want three actions to run in sequence in a stage, you would give the first action the runOrder value of 1, the second action the runOrder value of 2, and the third the runOrder value of 3. However, if you want the second and third actions to run in parallel, you would give the first action the runOrder value of 1 and both the second and third actions the runOrder value of 2.
https://docs.aws.amazon.com/codepipeline/latest/userguide/reference-pipeline-structure.html#pipeline-requirements
Workflow
前提:CodePipeline の Source はGitHubのブランチ
- 初めて
AWS::CodePipeline::Pipelineを実行 =>CodePipelineにパイプラインを作成 - 監視ブランチを更新
パイプラインが更新がリリースされてCodePipelineが実行(変更セット作成 -> 承認 -> デプロイ) - 変更セットを作成 =>
パイプラインが更新がリリースされてCodePipeline変更セット作成 -> 承認 -> デプロイ)
トラブルシューティング
ParameterOverrides
JSONでないとParameterOverrides property is not validが発生- 末尾プロパティのカンマ削除忘れ注意
CodePipelineを削除しないときの挙動
スタックを削除しても新たに CodePipeline が走って作成されてします。
スタックに紐付いた CodePipeline を削除してとき
パイプラインを削除後に同じスタックに対して、aws cloudformation create-change-setを実行した場合は以下エラーが発生する。
The account with id '' does not include a pipeline with the name '; Proxy: null)
Ref.
トラブルシューティング
2回承認した場合。
ChangeSet [ECS-ServiceChangeset] does not exist (Service: AmazonCloudFormation; Status Code: 404; Error Code: ChangeSetNotFound; Request ID: f567e16c-d9cc-418d-91ea-4d3c486ff27e; Proxy: null)
ref. https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_ExecuteChangeSet.html