AWSTemplateFormatVersion: 2010-09-09 Parameters: CodeBuildRole: Description: Code Build Role Type: String ClusterName: Description: ECS Cluster Name Type: String ServiceName: Description: ECS Service Name Type: String FileName: Description: ECS file name Type: String Default: file.json OauthToken: Description: Github oauth token Type: String BranchName: Description: GitHub branch name Type: String Default: master RepositoryName: Description: GitHub repository name Type: String GitHubOwner: Type: String Resources: CodePipelineArtifactStoreBucket: Type: 'AWS::S3::Bucket' AppPipelineWebhook: Type: 'AWS::CodePipeline::Webhook' Properties: Authentication: GITHUB_HMAC AuthenticationConfiguration: SecretToken: !Ref OauthToken Filters: - JsonPath: $.ref MatchEquals: 'refs/heads/{Branch}' TargetPipeline: !Ref AppPipeline TargetAction: SourceAction Name: AppPipelineWebhook TargetPipelineVersion: !GetAtt - AppPipeline - Version RegisterWithThirdParty: true CodePipelineServiceRole: Type: 'AWS::IAM::Role' Properties: AssumeRolePolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Principal: Service: - codepipeline.amazonaws.com Action: 'sts:AssumeRole' Path: / Policies: - PolicyName: AWS-CodePipeline-Service-3 PolicyDocument: Version: 2012-10-17 Statement: - Effect: Allow Action: - 'codecommit:CancelUploadArchive' - 'codecommit:GetBranch' - 'codecommit:GetCommit' - 'codecommit:GetUploadArchiveStatus' - 'codecommit:UploadArchive' Resource: '*' - Effect: Allow Action: - 'codedeploy:CreateDeployment' - 'codedeploy:GetApplicationRevision' - 'codedeploy:GetDeployment' - 'codedeploy:GetDeploymentConfig' - 'codedeploy:RegisterApplicationRevision' Resource: '*' - Effect: Allow Action: - 'codebuild:BatchGetBuilds' - 'codebuild:StartBuild' Resource: '*' - Effect: Allow Action: - 'devicefarm:ListProjects' - 'devicefarm:ListDevicePools' - 'devicefarm:GetRun' - 'devicefarm:GetUpload' - 'devicefarm:CreateUpload' - 'devicefarm:ScheduleRun' Resource: '*' - Effect: Allow Action: - 'lambda:InvokeFunction' - 'lambda:ListFunctions' Resource: '*' - Effect: Allow Action: - 'iam:PassRole' Resource: '*' - Effect: Allow Action: - 'elasticbeanstalk:*' - 'ec2:*' - 'elasticloadbalancing:*' - 'autoscaling:*' - 'cloudwatch:*' - 's3:*' - 'sns:*' - 'cloudformation:*' - 'rds:*' - 'sqs:*' - 'ecs:*' Resource: '*' AppPipeline: Type: 'AWS::CodePipeline::Pipeline' Properties: RoleArn: !GetAtt - CodePipelineServiceRole - Arn ArtifactStore: Type: S3 Location: !Ref CodePipelineArtifactStoreBucket Stages: - Name: Source Actions: - Name: SourceAction ActionTypeId: Category: Source Owner: ThirdParty Version: '1' Provider: GitHub OutputArtifacts: - Name: SourceOutput Configuration: Owner: !Ref GitHubOwner Repo: !Ref RepositoryName PollForSourceChanges: 'false' Branch: master OAuthToken: !Ref OauthToken RunOrder: 1 - Name: Build Actions: - Name: BuildCode InputArtifacts: - Name: SourceOutput OutputArtifacts: - Name: BuildOutput ActionTypeId: Category: Build Owner: AWS Version: '1' Provider: CodeBuild Configuration: ProjectName: !Ref Project - Name: Deploy Actions: - Name: DeployonECS InputArtifacts: - Name: BuildOutput ActionTypeId: Category: Deploy Owner: AWS Version: '1' Provider: ECS Configuration: ClusterName: !Ref ClusterName ServiceName: !Ref ServiceName FileName: !Ref FileName RunOrder: 1 Project: Type: 'AWS::CodeBuild::Project' Properties: Name: ECSCloudFormation Description: Auto deployment from GitHub to ECS Cluster ServiceRole: !Ref CodeBuildRole Artifacts: Type: no_artifacts Environment: Type: LINUX_CONTAINER ComputeType: BUILD_GENERAL1_SMALL Image: 'aws/codebuild/docker:17.09.0' Source: Location: 'https://github.com/vinycoolguy2015/cda-2018-flask-app.git' Type: GITHUB TimeoutInMinutes: 10