Pipeline

AWSTemplateFormatVersion: "2010-09-09" Description: CodePipeline triggered by changes to training/test.py file in CodeCommit repository Resources: CodeCommitRepo: Type: AWS::CodeCommit::Repository Properties: RepositoryName: pl_training_poc RepositoryDescription: "CodeCommit repo for training POC" PipelineRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Principal: Service: codepipeline.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: CodePipelinePolicy PolicyDocument: Version: "2012-10-17" Statement: - Effect: Allow Action: - codecommit:* - codebuild:* - s3:* Resource: "*" CodePipeline: Type: AWS::CodePipeline::Pipeline Properties: RoleArn: !GetAtt PipelineRole.Arn ArtifactStore: Type: S3 Location: !Ref ArtifactBucket Stages: - Name: Source Actions: - Name: SourceAction ActionTypeId: Category: Source Owner: AWS Provider: CodeCommit Version: 1 OutputArtifacts: - Name: SourceArtifact Configuration: RepositoryName: !Ref CodeCommitRepo BranchName: dev RunOrder: 1 - Name: Build Actions: - Name: BuildAction ActionTypeId: Category: Build Owner: AWS Provider: CodeBuild Version: 1 InputArtifacts: - Name: SourceArtifact Configuration: ProjectName: !Ref CodeBuildProject RunOrder: 1 CodeBuildProject: Type: AWS::CodeBuild::Project Properties: Name: pl-training-poc-build Source: Type: CODEPIPELINE Artifacts: Type: CODEPIPELINE Environment: Type: LINUX_CONTAINER ComputeType: BUILD_GENERAL1_SMALL Image: aws/codebuild/standard:5.0 EventBridgeRule: Type: AWS::Events::Rule Properties: Name: TriggerPipelineOnTestPyChange EventPattern: source: - aws.codecommit detail-type: - CodeCommit Repository State Change resources: - !GetAtt CodeCommitRepo.Arn detail: event: - referenceUpdated referenceName: - dev files: - "training/test.py" # Only triggers when this file is changed Targets: - Arn: !Ref CodePipeline Id: CodePipelineTarget ArtifactBucket: Type: AWS::S3::Bucket

Apr 3, 2025 - 10:03
 0
Pipeline



AWSTemplateFormatVersion: "2010-09-09"
Description: CodePipeline triggered by changes to training/test.py file in CodeCommit repository

Resources:

  CodeCommitRepo:
    Type: AWS::CodeCommit::Repository
    Properties:
      RepositoryName: pl_training_poc
      RepositoryDescription: "CodeCommit repo for training POC"

  PipelineRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service: codepipeline.amazonaws.com
            Action: sts:AssumeRole
      Policies:
        - PolicyName: CodePipelinePolicy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action:
                  - codecommit:*
                  - codebuild:*
                  - s3:*
                Resource: "*"

  CodePipeline:
    Type: AWS::CodePipeline::Pipeline
    Properties:
      RoleArn: !GetAtt PipelineRole.Arn
      ArtifactStore:
        Type: S3
        Location: !Ref ArtifactBucket
      Stages:
        - Name: Source
          Actions:
            - Name: SourceAction
              ActionTypeId:
                Category: Source
                Owner: AWS
                Provider: CodeCommit
                Version: 1
              OutputArtifacts:
                - Name: SourceArtifact
              Configuration:
                RepositoryName: !Ref CodeCommitRepo
                BranchName: dev
              RunOrder: 1

        - Name: Build
          Actions:
            - Name: BuildAction
              ActionTypeId:
                Category: Build
                Owner: AWS
                Provider: CodeBuild
                Version: 1
              InputArtifacts:
                - Name: SourceArtifact
              Configuration:
                ProjectName: !Ref CodeBuildProject
              RunOrder: 1

  CodeBuildProject:
    Type: AWS::CodeBuild::Project
    Properties:
      Name: pl-training-poc-build
      Source:
        Type: CODEPIPELINE
      Artifacts:
        Type: CODEPIPELINE
      Environment:
        Type: LINUX_CONTAINER
        ComputeType: BUILD_GENERAL1_SMALL
        Image: aws/codebuild/standard:5.0

  EventBridgeRule:
    Type: AWS::Events::Rule
    Properties:
      Name: TriggerPipelineOnTestPyChange
      EventPattern:
        source:
          - aws.codecommit
        detail-type:
          - CodeCommit Repository State Change
        resources:
          - !GetAtt CodeCommitRepo.Arn
        detail:
          event:
            - referenceUpdated
          referenceName:
            - dev
          files:
            - "training/test.py"  # Only triggers when this file is changed
      Targets:
        - Arn: !Ref CodePipeline
          Id: CodePipelineTarget

  ArtifactBucket:
    Type: AWS::S3::Bucket