LoginSignup
0
0

More than 1 year has passed since last update.

~Codepipline~ CodeCommit変更の検出方法

Posted at

概要

CodePiplineでは、ソースコードリポジトリへの変更を検出することでCodePiplineが実行される。
この検出方法にはポーリング型とプッシュ型が存在する

Poll型

ソースコードリポジトリが変更されたかどうかをポーリングによって検出する
ポーリングとは、複数のクライアント端末の状態を管理・制御する方式で、ホスト端末が接続されているクライアント端末の状態を決められた順番で問い合わせる
ポーリングとは

Push型(イベント駆動)

AWSリソースは状態の変更が発生するとイベントを生成する
このイベントをCloudWatch Eventsに発行することでCodePiplineの実行を促す

メリット

  • Polling型では順番がくるまで状態変更を発行できなかったが、Push型では即時にイベントを発行できる
  • 制限の引き上げ。変更をポーリングするパイプラインに比べて、CodePipeline は、より多くのイベントベースのパイプラインをサポートできます。
  • 多数のパイプラインでのエクスペリエンスの向上。お客様によっては、多数のパイプラインでのコードの変更を調べるためにリポジトリを継続的にポーリングすることで、スロットリングまたはコストの増加が発生する場合があります。これらの問題はイベントを使用することで回避できます。

CloudWatch eventsについて

CloudFormationでの設定

CloudWatchEvent
  AmazonCloudWatchEventRule:
    Type: AWS::Events::Rule
    Properties:
      EventPattern:
        source:
          - aws.codecommit
        detail-type:
          - CodeCommit Repository State Change
        resources:
          - Fn::Join:
              - ''
              - - 'arn:aws:codecommit:'
                - !Ref 'AWS::Region'
                - ':'
                - !Ref 'AWS::AccountId'
                - ':'
                - !Ref CodeCommitRepositoryName
        detail:
          event:
            - referenceCreated
            - referenceUpdated
          referenceType:
            - branch
          referenceName:
            - main
      Targets:
        - Arn: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${Pipeline}
          RoleArn: !GetAtt CloudwatchEventRole.Arn
          Id: codepipeline-AppPipeline

CloudWatch Eventsを使う場合PollForSourceChanges propertyをfalseにしておかないとイベント検出が2回発生してしまう

Codepipeline
      Stages:
        - Name: Source
          Actions:
            - Name: SourceAction
              ActionTypeId:
                Category: Source
                Owner: AWS
                Version: '1'
                Provider: CodeCommit
              Configuration:
                RepositoryName: !Ref CodeCommitRepositoryName
                PollForSourceChanges: false
                BranchName: main
              RunOrder: 1
              OutputArtifacts:
                - Name: App
0
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
0
0