Until Now, if you wanted to run AWS CLI commands, third-party CLI commands, or simply invoke an API, you had to create a CodeBuild project, configure the project with the appropriate commands, and add a CodeBuild action to your pipeline to run the project.

Clearly Users had to deal with 2 components CodePipeline and CodeBuild and of course learn the internals for both in order to use the.

This blog explains about CodePipeline’s Command Action, a new update to Codepipeline, which enables you to easily run shell commands as part of your pipeline execution.

With the Commands action, you can run AWS CLI, third-party tools, or any shell commands.

In the end we will also discuss do we really don’t need codeBuild or where could be the situations we can use codeBuild where command action would not suffice.

Motivation

Prerequisites

Understanding CodePipeline Command Action

What happens behind the scenes of Command Action

Its just that whole process of creating codeBuild project first and then adding as action to CodePipeline has been abstracted by this action.

Some caveats for Command action:

logs:CreateLogGroup
logs:CreateLogStream
logs:PutLogEvents

Let’s see how Command Action works !!!

Upload terraform zip to s3 -> CodePipeline is triggered -> Command action runs terraform apply

Step 1: Create S3 bucket for storing terraform backend and source

Step 2: Create Pipeline

Step 3: Choose Source stage

Step 4: Add build stage / add commands

sudo dnf install -y yum-utils shadow-utils
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo dnf -y install terraform
terraform --version
terraform init -no-color -input=false
terraform apply -auto-approve -no-color -input=false
aws s3 ls

Note: Don’t add a white space between command other you will see an error for length constraint

Step 5: Skip deploy and Review

Voila, you just created a CD pipeline without even Knowing or involving Codebuild ( at least by your own)

Did it Actually work?


// optional step for backend
terraform {
  backend "s3" {
    bucket = "codepipeline-command-action-backend-jatin"
    region = "us-east-1"
    key    = "terraform-deployment.tfstate"
  }
}

resource "aws_s3_bucket" "deploy-bucket" {
  bucket = "codepipeline-command-action-backend-1-jatin"

  tags = {
    Project     = "For CI CD deploy test"
    Environment = "Dev"
  }
}

resource "aws_s3_bucket" "deploy-bucket-two" {
  bucket = "codepipeline-command-action-backend-2-jatin"

  tags = {
    Project     = "For CI CD deploy test"
    Environment = "Dev"
  }
}
zip -r tf.zip main.tf

Check the CodePipeline Logs and s3 bucket

From DevOps Architect Perspective

With Commands Action I don’t need to touch or deal with CodeBuild action, Just focus on building my CI/CD Pipeline. But does it actually suffice for the abstraction?

I am very curious how The community will use this update for their Pipelines and how do they think it’s going to help them with their efficiency?

Leave your questions, comments and let’s make our life easy for CI CD pipelines. You can always reach out to me on Linkedin, X.

このウェブサイトでは、よりよいユーザー体験のためにCookieを使用しています。詳細は、Cookieに関する方針をご参照ください。OK をクリックまたは本サイトの利用を続行することで、我々がCookieを使用することに同意したとみなされます。