Pipeline vs CodePipeline in Development

by Loya Altangerel, Founder / Tech Lead

Overview

In the context of the AWS Cloud Development Kit (CDK), the difference between CodePipeline from aws-cdk-lib/pipelines and Pipeline from aws-cdk-lib/aws-codepipeline is primarily about the level of abstraction and functionality that each one provides when defining your CI/CD workflows.

Pipeline from aws-cdk-lib/aws-codepipeline

  • Low-Level Construct: This module provides a direct, low-level construct for creating pipelines with AWS CodePipeline using CDK. It offers fine-grained control over the details of the pipeline, such as stages and actions.
  • Detailed Configuration: You have to explicitly define every step of the pipeline, including source, build, test, and deploy actions. This means that developers have to manage the connections between different AWS services manually.
  • Customization: Since it is a lower-level construct, it offers more flexibility and customization options, allowing you to tailor your pipeline to your exact requirements.
  • Manual Updates: If you make changes to the pipeline's structure or stages, you typically have to update the pipeline manually or ensure the CDK stack update will modify the pipeline accordingly.

Here's a simplified example of how you might define a pipeline using this construct:

import * as codepipeline from 'aws-cdk-lib/aws-codepipeline';
import * as codepipeline_actions from 'aws-cdk-lib/aws-codepipeline-actions';

const sourceArtifact = new codepipeline.Artifact();
const buildArtifact = new codepipeline.Artifact();

const pipeline = new codepipeline.Pipeline(this, 'MyPipeline', {
  pipelineName: 'MyPipeline',
  stages: [
    {
      stageName: 'Source',
      actions: [/* ... */],
    },
    {
      stageName: 'Build',
      actions: [/* ... */],
    },
    // Add more stages as needed
  ],
});

CodePipeline from aws-cdk-lib/pipelines

  • High-Level Construct: This module provides a higher-level construct specifically designed for creating CDK pipelines (CI/CD for your infrastructure as code). It abstracts away many of the details involved in setting up a CodePipeline.
  • Easier to Set Up: It is designed to simplify the setup process by providing a more opinionated approach, which includes default stages and actions that cover typical use cases.
  • Self-Mutating: A CDK pipeline is often self-mutating, which means it can automatically update its own definition when the CDK application code changes.
  • Integrated with CDK Deployments: It is optimized for deploying CDK applications and can handle complex workflows involving multiple AWS accounts and/or regions.

Here's a simplified example of how you might define a CDK pipeline using this construct:

import * as pipelines from 'aws-cdk-lib/pipelines';

const pipeline = new pipelines.CodePipeline(this, 'MyCDKPipeline', {
  // The pipeline name
  pipelineName: 'MyCDKPipeline',
  // The synth step defines how to synthesize the CDK app
  synth: new pipelines.ShellStep('Synth', {
    input: pipelines.CodePipelineSource.gitHub('my-org/my-app', 'branch'),
    commands: ['npm ci', 'npm run build', 'npx cdk synth'],
  }),
});

In conclusion, Pipeline from aws-cdk-lib/aws-codepipeline is a more hands-on, detailed approach for defining a pipeline with AWS CodePipeline in CDK, offering maximum control. In contrast, CodePipeline from aws-cdk-lib/pipelines is a higher-level abstraction intended to simplify the creation and management of CDK application deployment pipelines, with several convenience features such as self-mutation.

More articles

A tip to organize an Agile team

As a team leader, the most important aspect of your job is organizing a team most efficiently.

Read more

The Well-Architected Framework

The Well-Architected Framework is a collection of best practices and guidelines for designing and running cloud-based systems and applications.

Read more

Trust Uudam Technology to power up your business and pave the way for unparalleled success.

Our offices

  • Seattle
    Seattle, WA 98119
  • Ulaanbaatar
    Ulaanbaatar, Mongolia