{
  "Resources": {
    "MyRepoF4F48043": {
      "Type": "AWS::CodeCommit::Repository",
      "Properties": {
        "RepositoryName": "aws-cdk-codebuild-events",
        "Triggers": []
      }
    },
    "MyRepoOnCommit0E80B304": {
      "Type": "AWS::Events::Rule",
      "Properties": {
        "EventPattern": {
          "source": [
            "aws.codecommit"
          ],
          "resources": [
            {
              "Fn::GetAtt": [
                "MyRepoF4F48043",
                "Arn"
              ]
            }
          ],
          "detail-type": [
            "CodeCommit Repository State Change"
          ],
          "detail": {
            "event": [
              "referenceUpdated"
            ],
            "referenceName": [
              "master"
            ]
          }
        },
        "State": "ENABLED",
        "Targets": [
          {
            "Arn": {
              "Fn::GetAtt": [
                "MyProject39F7B0AE",
                "Arn"
              ]
            },
            "Id": "MyProject",
            "RoleArn": {
              "Fn::GetAtt": [
                "MyProjectEventsRole5B7D93F5",
                "Arn"
              ]
            }
          },
          {
            "Arn": {
              "Ref": "MyTopic86869434"
            },
            "Id": "MyTopic",
            "InputTransformer": {
              "InputPathsMap": {
                "branch": "$.detail.referenceName",
                "repo": "$.detail.repositoryName"
              },
              "InputTemplate": "\"A commit was pushed to the repository <repo> on branch <branch>\""
            }
          }
        ]
      }
    },
    "MyProjectRole9BBE5233": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": "codebuild.amazonaws.com"
              }
            }
          ],
          "Version": "2012-10-17"
        }
      }
    },
    "MyProjectRoleDefaultPolicyB19B7C29": {
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyDocument": {
          "Statement": [
            {
              "Action": "codecommit:GitPull",
              "Effect": "Allow",
              "Resource": {
                "Fn::GetAtt": [
                  "MyRepoF4F48043",
                  "Arn"
                ]
              }
            },
            {
              "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents"
              ],
              "Effect": "Allow",
              "Resource": [
                {
                  "Fn::Join": [
                    "",
                    [
                      "arn",
                      ":",
                      {
                        "Ref": "AWS::Partition"
                      },
                      ":",
                      "logs",
                      ":",
                      {
                        "Ref": "AWS::Region"
                      },
                      ":",
                      {
                        "Ref": "AWS::AccountId"
                      },
                      ":",
                      "log-group",
                      ":",
                      "/aws/codebuild/",
                      {
                        "Ref": "MyProject39F7B0AE"
                      }
                    ]
                  ]
                },
                {
                  "Fn::Join": [
                    "",
                    [
                      {
                        "Fn::Join": [
                          "",
                          [
                            "arn",
                            ":",
                            {
                              "Ref": "AWS::Partition"
                            },
                            ":",
                            "logs",
                            ":",
                            {
                              "Ref": "AWS::Region"
                            },
                            ":",
                            {
                              "Ref": "AWS::AccountId"
                            },
                            ":",
                            "log-group",
                            ":",
                            "/aws/codebuild/",
                            {
                              "Ref": "MyProject39F7B0AE"
                            }
                          ]
                        ]
                      },
                      ":*"
                    ]
                  ]
                }
              ]
            }
          ],
          "Version": "2012-10-17"
        },
        "PolicyName": "MyProjectRoleDefaultPolicyB19B7C29",
        "Roles": [
          {
            "Ref": "MyProjectRole9BBE5233"
          }
        ]
      }
    },
    "MyProject39F7B0AE": {
      "Type": "AWS::CodeBuild::Project",
      "Properties": {
        "Artifacts": {
          "Type": "NO_ARTIFACTS"
        },
        "Environment": {
          "ComputeType": "BUILD_GENERAL1_SMALL",
          "Image": "aws/codebuild/ubuntu-base:14.04",
          "PrivilegedMode": false,
          "Type": "LINUX_CONTAINER"
        },
        "ServiceRole": {
          "Fn::GetAtt": [
            "MyProjectRole9BBE5233",
            "Arn"
          ]
        },
        "Source": {
          "Location": {
            "Fn::GetAtt": [
              "MyRepoF4F48043",
              "CloneUrlHttp"
            ]
          },
          "Type": "CODECOMMIT"
        }
      }
    },
    "MyProjectStateChange2DAB75B7": {
      "Type": "AWS::Events::Rule",
      "Properties": {
        "EventPattern": {
          "source": [
            "aws.codebuild"
          ],
          "detail-type": [
            "CodeBuild Build State Change"
          ],
          "detail": {
            "project-name": [
              {
                "Ref": "MyProject39F7B0AE"
              }
            ]
          }
        },
        "State": "ENABLED",
        "Targets": [
          {
            "Arn": {
              "Ref": "MyTopic86869434"
            },
            "Id": "MyTopic"
          }
        ]
      }
    },
    "MyProjectPhaseChangeCE6728A3": {
      "Type": "AWS::Events::Rule",
      "Properties": {
        "EventPattern": {
          "source": [
            "aws.codebuild"
          ],
          "detail-type": [
            "CodeBuild Build Phase Change"
          ],
          "detail": {
            "project-name": [
              {
                "Ref": "MyProject39F7B0AE"
              }
            ]
          }
        },
        "State": "ENABLED",
        "Targets": [
          {
            "Arn": {
              "Ref": "MyTopic86869434"
            },
            "Id": "MyTopic",
            "InputTransformer": {
              "InputPathsMap": {
                "phase": "$.detail.completed-phase"
              },
              "InputTemplate": "\"Build phase changed to <phase>\""
            }
          }
        ]
      }
    },
    "MyProjectEventsRole5B7D93F5": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "AssumeRolePolicyDocument": {
          "Statement": [
            {
              "Action": "sts:AssumeRole",
              "Effect": "Allow",
              "Principal": {
                "Service": "events.amazonaws.com"
              }
            }
          ],
          "Version": "2012-10-17"
        }
      }
    },
    "MyProjectEventsRoleDefaultPolicy397DCBF8": {
      "Type": "AWS::IAM::Policy",
      "Properties": {
        "PolicyDocument": {
          "Statement": [
            {
              "Action": "codebuild:StartBuild",
              "Effect": "Allow",
              "Resource": {
                "Fn::GetAtt": [
                  "MyProject39F7B0AE",
                  "Arn"
                ]
              }
            }
          ],
          "Version": "2012-10-17"
        },
        "PolicyName": "MyProjectEventsRoleDefaultPolicy397DCBF8",
        "Roles": [
          {
            "Ref": "MyProjectEventsRole5B7D93F5"
          }
        ]
      }
    },
    "MyTopic86869434": {
      "Type": "AWS::SNS::Topic"
    },
    "MyTopicPersonal828A6935": {
      "Type": "AWS::SNS::Subscription",
      "Properties": {
        "Endpoint": "benisrae@amazon.com",
        "Protocol": "email",
        "TopicArn": {
          "Ref": "MyTopic86869434"
        }
      }
    },
    "MyTopicPolicy12A5EC17": {
      "Type": "AWS::SNS::TopicPolicy",
      "Properties": {
        "PolicyDocument": {
          "Statement": [
            {
              "Action": "sns:Publish",
              "Effect": "Allow",
              "Principal": {
                "Service": "events.amazonaws.com"
              },
              "Resource": {
                "Ref": "MyTopic86869434"
              },
              "Sid": "0"
            }
          ],
          "Version": "2012-10-17"
        },
        "Topics": [
          {
            "Ref": "MyTopic86869434"
          }
        ]
      }
    }
  }
}