• DevOps
    Case Study

    How we built a resilient multi-account, multi-cloud solution for a Health Tech service provider!

    READ CASESTUDY
    icon

    24/7 DevOps as a Service

    Round-the-clock DevOps for uninterrupted efficiency.

    icon

    Infrastructure as a Code

    Crafting infrastructure with ingenious code.

    icon

    CI/CD Pipeline

    Automated CI/CD pipeline for seamless deployments.

    icon

    DevSecOps

    Integrated security in continuous DevOps practices.

    icon

    Hire DevOps Engineers

    Level up your team with DevOps visionaries.

    icon

    Consulting Services

    Navigate success with expert DevOps consulting.

  • TechOps
    Case Study

    How we built a scalable Odoo solution for a Travel Tech service provider!

    READ CASESTUDY

    WEB HOSTING SUPPORT

    icon

    HelpDesk Support

    Highly skilled 24/7 HelpDesk Support

    icon

    Product Support

    Boost your product support with our expertise.

    MANAGED SERVICES

    icon

    Server Management

    Don’t let server issues slow you down. Let us manage them for you.

    icon

    Server Monitoring

    Safeguard your server health with our comprehensive monitoring solutions.

    STAFF AUGMENTATION

    icon

    Hire an Admin

    Transform your business operations with our expert administrative support.

    icon

    Hire a Team

    Augment your workforce with highly skilled professionals from our diverse talent pool.

  • CloudOps
    Case Study

    How we helped a Private Deemed University in India, save US $3500/m on hosting charges!

    READ CASESTUDY
    icon

    AWS Well Architected Review

    Round-the-clock for uninterrupted efficiency

    icon

    Optimize

    Efficient CloudOps mastery for seamless cloud management

    icon

    Manage

    Automated CI/CD pipeline for seamless deployments

    icon

    Migrate

    Upgrade the journey, Migrate & Modernize seamlessly

    icon

    Modernize

    Simplify compliance complexities with our dedicated services

    icon

    FinOps as a Service

    FinOps as a Service

  • SecOps
    Case Study

    How we built a scalable Odoo solution for TravelTech service provider!

    READ CASESTUDY
    icon

    VAPT

    Vulnerability Assessment and Penetration Testing

    icon

    Source Code Review

    Ensuring source code security ans safe practices to reduce risks

    icon

    Security Consultation

    On demand services for improving server security

    icon

    System Hardening

    Reduced vulnerability and proactive protection

    icon

    Managed SoC

    Monitors and maintains system security. Quick response on incidents.

    icon

    Compliance as a Service

    Regulatory compliance, reduced risk

  • Insights
    Case Study

    How we helped a Private Deemed University in India, save US $3,500/m on hosting charges!

    READ CASESTUDY
    icon

    Blog

    Explore our latest articles and insights

    icon

    Case Studies

    Read about our client success stories

    icon

    Flipbook

    Explore our latest Flipbook

    icon

    Events

    Join us at upcoming events and conferences

    icon

    Webinars

    Watch our educational webinar series

  • Our Story
  • Contact Us

Interested to collaborate?

Get in touch with us!

Ready to elevate your business with certified cloud expertise? Contact us today to learn how our team can help you leverage cloud technology to drive growth, streamline operations, and enhance security.

  • AWSAWS
  • Azure CloudAzure Cloud
  • Google CloudGoogle Cloud
  • Akamai CloudAkamai Cloud
  • OVHOVH
  • Digital OceanDigital Ocean
  • HetznerHetzner
  • Kubernetes Consultancy Services
  • K8s & Cloud native Solutions
  • 24/7 Infrastructure Monitoring
  • DevOps as a Service
  • Cloud CI/CD Solutions
  • White Labeled MSP Support
  • Our story
  • Life@SupportSages
  • Insights
  • Careers
  • Events
  • Contact Us

Connect with us!


LinkedInFacebookXInstagramYouTube

aws partneraws advanced partner
SupportSages

Copyright © 2008 – 2026 SupportSages Pvt Ltd. All Rights Reserved.
Privacy PolicyLegal TermsData ProtectionCookie Policy
Automating AWS CodePipeline Creation with CloudFormation

Automating AWS CodePipeline Creation with CloudFormation

Arya P B

  • 4 min read
Automating AWS CodePipeline Creation with CloudFormation

Generating audio, please wait...

Introduction: In the domain of DevOps, automation reigns supreme. As software development pipelines grow more intricate, automating the establishment of continuous integration and continuous deployment (CI/CD) processes becomes imperative. AWS offers robust tools like CodePipeline for orchestrating these workflows and CloudFormation for automating infrastructure setup. In this tutorial, we’ll delve into automating the creation of an AWS CodePipeline using CloudFormation, with a specific emphasis on replicating an existing pipeline.

Prerequisites: Before diving in, make sure you have:

  • An AWS account with the necessary permissions to create IAM roles, CodeBuild projects, CodePipeline pipelines, and EventBridge rules.
  • Basic knowledge of AWS CodePipeline, CodeBuild, IAM roles, and CloudFormation.

Step 1: Understanding the CloudFormation Template: Let’s dissect the CloudFormation template provided below. This template sets up a CodePipeline that clones an existing repository, triggers builds with CodeBuild, and uses EventBridge for event-driven triggers.

AWSTemplateFormatVersion: 2010-09-09
Description: CloudFormation template to create an AWS CodeBuild project with no source
Parameters:
CodeBuildProjectName:
Type: String
Description: Name of CodeBuild project
Default: ss-auto-pipeline-build
CodePipelineName:
Type: String
Description: Name of CodePipeline
Default: ss-auto-pipeline
EventBridgeRuleName:
Type: String
Description: Name of EventBridgeRule
Default: ss-auto-pipeline-EventBridgeRule

Resources:
CodeBuildServiceRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: !Sub '${CodeBuildProjectName}-ServiceRole'
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: codebuild.amazonaws.com
Action: 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/AWSCodeBuildDeveloperAccess'
- 'arn:aws:iam::aws:policy/CloudWatchFullAccess'
- 'arn:aws:iam::aws:policy/AmazonS3FullAccess'
- 'arn:aws:iam::aws:policy/AmazonAPIGatewayAdministrator'
- 'arn:aws:iam::aws:policy/AWSCloudFormationFullAccess'
- 'arn:aws:iam::aws:policy/AWSLambda_FullAccess'

CodePipelineServiceRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: !Sub '${CodePipelineName}-Role'
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service: codepipeline.amazonaws.com
Action: 'sts:AssumeRole'
Path: '/'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/AmazonS3FullAccess'
- 'arn:aws:iam::aws:policy/AWSCodeCommitFullAccess'
- 'arn:aws:iam::aws:policy/AWSCodeBuildAdminAccess'
Policies:
- PolicyName: // provide PolicyName
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: VisualEditor0
Effect: Allow
Action:
- 'sts:AssumeRole'
Resource: #'arn:aws:iam::YOUR_ACCOUNT_ID:role/*'

CodeBuildProject:
Type: 'AWS::CodeBuild::Project'
Properties:
Name: !Ref CodeBuildProjectName
Description: CodeBuild project
Source:
Type: NO_SOURCE
BuildSpec: |
version: 0.2
phases:
build:
commands:
- echo 'This is a test'
- sleep 60
- echo 'completed'
Artifacts:
Type: NO_ARTIFACTS
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: 'aws/codebuild/amazonlinux2-x86_64-standard:3.0'
ServiceRole: !GetAtt CodeBuildServiceRole.Arn
TimeoutInMinutes: 5

CodePipeline:
Type: 'AWS::CodePipeline::Pipeline'
Properties:
Name: !Ref CodePipelineName
RoleArn: !GetAtt CodePipelineServiceRole.Arn
ArtifactStore:
Type: S3
Location: codepipeline-ap-south-1-675893268499 
ArtifactStoreEncryption:
EncryptionKey: // provide EncryptionKey
Type: KMS
Stages:
- Name: Source
Actions:
- Name: SourceAction
ActionTypeId:
Category: Source
Owner: AWS
Provider: CodeCommit
Version: '1'
Configuration:
RepositoryName: cft_test
BranchName: master
OutputArtifacts:
- Name: SourceOutput
- Name: Build
Actions:
- Name: BuildAction
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: '1'
Configuration:
ProjectName: !Ref CodeBuildProjectName
InputArtifacts:
- Name: SourceOutput
OutputArtifacts:
- Name: BuildOutput
DependsOn: CodeBuildProject

EventBridgeRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: !Sub '${CodePipelineName}-EventBridgeRole'
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- events.amazonaws.com
Action: 'sts:AssumeRole'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/AWSCodePipeline_FullAccess'
Policies:
- PolicyName: EventBridgePolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- 'codepipeline:StartPipelineExecution'
Resource:
- !Sub >-
arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${CodePipelineName}
DependsOn: CodePipeline 

EventBridgeRule:
Type: 'AWS::Events::Rule'
Properties:
Name: !Ref EventBridgeRuleName
Description: >-
This rule triggers the CodePipeline when the specified event pattern is
matched.
EventBusName: default
EventPattern:
detail:
pipeline_name:
- !Ref CodePipelineName
branch_name:
- master
repository:
- cft_test
Targets:
- Arn: !Sub >-
arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${CodePipelineName}
Id: CFTCodePipelineTarget
RoleArn: !GetAtt EventBridgeRole.Arn
DependsOn: CodePipeline

Step 2: Parameters Explanation:

  • The template defines parameters for customizing the CodeBuild project name, CodePipeline name, and EventBridge rule name, offering flexibility in naming conventions.

Step 3: Resource Setup:

  • CodeBuildServiceRole: Defines an IAM role for the CodeBuild project with necessary permissions for CodeBuild to access resources like S3, CloudWatch, and Lambda.
  • CodePipelineServiceRole: Establishes an IAM role for the CodePipeline with permissions to access resources like S3 and CodeBuild, crucial for pipeline orchestration.
  • CodeBuildProject: Sets up the CodeBuild project, specifying build commands, environment details, and linking to the CodeBuild service role.
  • CodePipeline: Creates the CodePipeline, specifying source (CodeCommit), build (CodeBuild), and linking to the CodePipeline service role. It depends on the CodeBuild project to ensure proper sequencing.
  • EventBridgeRole: Establishes an IAM role for EventBridge with permissions to start pipeline executions. It depends on the CodePipeline to ensure it’s created before the EventBridge rule.
  • EventBridgeRule: Defines an EventBridge rule to trigger the CodePipeline when specific events occur, such as repository changes. It depends on the CodePipeline to ensure its availability.

Step 4: Deploying the CloudFormation Stack: To deploy this CloudFormation stack:

  1. Save the CloudFormation template to a file, e.g., codepipeline-template.yaml.
  2. Open the AWS Management Console, navigate to CloudFormation, and click “Create stack”.
  3. Upload the template file, configure parameters as needed, and proceed with the stack creation.

Conclusion: In this tutorial, we’ve explored how to automate the setup of an AWS CodePipeline using CloudFormation. By defining infrastructure as code, you can efficiently manage, version, and reproduce your CI/CD pipelines. This approach fosters consistency, reliability, and scalability in your software delivery processes, ultimately enhancing your DevOps practices.

Dive into our comprehensive tutorial on automating AWS CodePipeline creation using CloudFormation. Streamline your deployment processes, foster consistency, and enhance your DevOps practices effortlessly. Get started now!

  • AWS
  • DevOps

Continue Your Journey With…

DevOps as a Service

DevOps as a Service

Let us do the heavy lifting for you

Promotional banner
Promotional banner

Analyzing AWS IAM Users: Access Key and Password Age

Analyzing AWS IAM Users: Access Key and Password Age
  • DevOps
logo

Analyzing AWS IAM Users: Access Key and Password Age

Analyzing AWS IAM Users: Access Key and Password Age
  • AWS
  • DevOps
logo

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide
  • DevOps
logo

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide

Auto-Restart EC2 Instances on Status Check Failure: Quick Setup Guide
  • AWS
  • DevOps
logo

Posts by Arya P B

Athena