Parameters: BranchName: Type: String BranchNameNorm: Type: String ModelName: Type: String RepositoryName: Type: String CodePipelineArtifactBucket: Type: String CodePipelineRoleArn: Type: String CodePipelineSourceActionRoleArn: Type: String CodePipelineBuildActionRoleArn: Type: String EventStartPipelineRoleArn: Type: String CodeBuildProjectName: Type: String Resources: ModelTrainCodePipeline: Type: 'AWS::CodePipeline::Pipeline' Properties: Name: !Sub 'model-${ModelName}-train-${BranchNameNorm}' RoleArn: !Ref CodePipelineRoleArn ArtifactStore: Type: S3 Location: !Ref CodePipelineArtifactBucket Stages: - Name: Source Actions: - Name: SourceAction ActionTypeId: Category: Source Owner: AWS Version: 1 Provider: CodeCommit OutputArtifacts: - Name: SourceOutput Configuration: BranchName: !Ref BranchName RepositoryName: !Ref RepositoryName PollForSourceChanges: false RunOrder: 1 RoleArn: !Ref CodePipelineSourceActionRoleArn - Name: Train Actions: - Name: TrainAction ActionTypeId: Category: Build Owner: AWS Version: 1 Provider: CodeBuild InputArtifacts: - Name: SourceOutput OutputArtifacts: - Name: TrainOutput Configuration: ProjectName: !Ref CodeBuildProjectName EnvironmentVariables: !Sub '[{"name":"BRANCH_NAME","value":"${BranchName}","type":"PLAINTEXT"}]' RoleArn: !Ref CodePipelineBuildActionRoleArn StartPipelineRule: Type: 'AWS::Events::Rule' Properties: EventPattern: source: - aws.codecommit detail-type: - 'CodeCommit Repository State Change' resources: - !Join - ':' - - 'arn' - !Ref AWS::Partition - 'codecommit' - !Ref AWS::Region - !Ref AWS::AccountId - !Ref RepositoryName detail: referenceName: - !Ref BranchName referenceType: - branch State: ENABLED Targets: - Arn: !Join - ':' - - 'arn' - !Ref AWS::Partition - 'codepipeline' - !Ref AWS::Region - !Ref AWS::AccountId - !Ref ModelTrainCodePipeline Id: ModelTrainCodePipeline RoleArn: !Ref EventStartPipelineRoleArn