#
ドキュメント

Document

自分のための備忘録です。

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

ActionTypeIdCategoryDeployProviderCloudFormationActionModeCHANGE_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
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 プロパティ内で次のプロパティを定義します。A

AWS CloudFormation 設定プロパティのリファレンス

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

前提:CodePipelineSourceは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 '{{アカウントID}}' does not include a pipeline with the name '{{パイプライン名}}' (Service: AWSCodePipeline; Status Code: 400; Error Code: ResourceNotFoundException; Request ID: {{リクエストID}}; 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