|
| 1 | +AWSTemplateFormatVersion: "2010-09-09" |
| 2 | +Transform: AWS::Serverless-2016-10-31 |
| 3 | +Description: > |
| 4 | + codebuild |
| 5 | +
|
| 6 | + Sample SAM Template for codebuild |
| 7 | +
|
| 8 | +Parameters: |
| 9 | + RepoName: |
| 10 | + Type: String |
| 11 | + Description: Name of the CodeCommit repository to build nightly. Must be in the same region. |
| 12 | + |
| 13 | +Resources: |
| 14 | + UpdateDependencies: |
| 15 | + Type: AWS::Serverless::StateMachine # More info about State Machine Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html |
| 16 | + Properties: |
| 17 | + DefinitionUri: statemachine/updateDependencies.asl.json |
| 18 | + DefinitionSubstitutions: |
| 19 | + UpdateDependenciesBuildJob: !GetAtt UpdateDependenciesProject.Arn |
| 20 | + BuildStatusTopic: !Ref BuildResultsTopic |
| 21 | + Events: |
| 22 | + Nightly: |
| 23 | + Type: Schedule # More info about Schedule Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-schedule.html |
| 24 | + Properties: |
| 25 | + Description: Schedule to run the UpdateDependencies state machine every night |
| 26 | + Schedule: "cron(0 0 * * ? *)" # Run at midnight (UTC) every day. Format is cron(minutes hours day_of_month month day_of_week year) |
| 27 | + Role: !GetAtt StepFunctionsRole.Arn |
| 28 | + |
| 29 | + BuildResultsTopic: |
| 30 | + Type: AWS::SNS::Topic |
| 31 | + |
| 32 | + UpdateDependenciesProject: |
| 33 | + Type: AWS::CodeBuild::Project |
| 34 | + Properties: |
| 35 | + ServiceRole: !Ref CodeBuildRole |
| 36 | + Artifacts: |
| 37 | + Type: NO_ARTIFACTS |
| 38 | + Environment: |
| 39 | + Type: LINUX_CONTAINER |
| 40 | + ComputeType: BUILD_GENERAL1_SMALL |
| 41 | + Image: aws/codebuild/standard:2.0 |
| 42 | + Source: |
| 43 | + Type: CODECOMMIT |
| 44 | + Location: !Sub https://git-codecommit.${AWS::Region}.amazonaws.com/v1/repos/${RepoName} |
| 45 | + |
| 46 | + StepFunctionsRole: |
| 47 | + Type: AWS::IAM::Role |
| 48 | + Properties: |
| 49 | + AssumeRolePolicyDocument: |
| 50 | + Version: "2012-10-17" |
| 51 | + Statement: |
| 52 | + - Effect: Allow |
| 53 | + Action: "sts:AssumeRole" |
| 54 | + Principal: |
| 55 | + Service: states.amazonaws.com |
| 56 | + Path: "/" |
| 57 | + Policies: |
| 58 | + - PolicyName: CodeBuildExecutionRolePolicy |
| 59 | + PolicyDocument: |
| 60 | + Version: "2012-10-17" |
| 61 | + Statement: |
| 62 | + - Effect: Allow |
| 63 | + Action: |
| 64 | + - "sns:Publish" |
| 65 | + Resource: |
| 66 | + - !Ref BuildResultsTopic |
| 67 | + - Effect: Allow |
| 68 | + Action: |
| 69 | + - "codebuild:StartBuild" |
| 70 | + - "codebuild:StopBuild" |
| 71 | + - "codebuild:BatchGetBuilds" |
| 72 | + - "codebuild:BatchGetReports" |
| 73 | + Resource: "*" |
| 74 | + - Effect: Allow |
| 75 | + Action: |
| 76 | + - "events:PutTargets" |
| 77 | + - "events:PutRule" |
| 78 | + - "events:DescribeRule" |
| 79 | + Resource: |
| 80 | + - !Sub "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventForCodeBuildStartBuildRule" |
| 81 | + |
| 82 | + CodeBuildRole: |
| 83 | + Type: AWS::IAM::Role |
| 84 | + Properties: |
| 85 | + AssumeRolePolicyDocument: |
| 86 | + Version: "2012-10-17" |
| 87 | + Statement: |
| 88 | + - Effect: Allow |
| 89 | + Action: "sts:AssumeRole" |
| 90 | + Principal: |
| 91 | + Service: codebuild.amazonaws.com |
| 92 | + Path: / |
| 93 | + Policies: |
| 94 | + - PolicyName: CodeBuildServiceRolePolicy |
| 95 | + PolicyDocument: |
| 96 | + Version: "2012-10-17" |
| 97 | + Statement: |
| 98 | + - Effect: Allow |
| 99 | + Action: |
| 100 | + - "logs:CreateLogGroup" |
| 101 | + - "logs:CreateLogStream" |
| 102 | + - "logs:PutLogEvents" |
| 103 | + - "codebuild:CreateReportGroup" |
| 104 | + - "codebuild:CreateReport" |
| 105 | + - "codebuild:UpdateReport" |
| 106 | + - "codebuild:BatchPutTestCases" |
| 107 | + Resource: "*" |
| 108 | + - Effect: Allow |
| 109 | + Action: |
| 110 | + - "codecommit:GitPull" |
| 111 | + Resource: !Sub arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${RepoName} |
| 112 | + |
| 113 | +Outputs: |
| 114 | + # StockTradingStateMachineHourlyTradingSchedule is an implicit Schedule event rule created out of Events key under Serverless::StateMachine |
| 115 | + # Find out more about other implicit resources you can reference within SAM |
| 116 | + # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html |
| 117 | + UpdateDependenciesArn: |
| 118 | + Description: "Update Dependencies state machine ARN" |
| 119 | + Value: !Ref UpdateDependencies |
| 120 | + BuildResultsTopicName: |
| 121 | + Description: "Build Results SNS Topic name" |
| 122 | + Value: !GetAtt BuildResultsTopic.TopicName |
0 commit comments