Pipelines

Continuous integration and delivery (CI/CD) using CDK Pipelines - AWS Cloud Development Kit (AWS CDK) v2
Provides a conceptual overview and practical examples to help you understand the features provided by the AWS CDK and how to use them.
https://docs.aws.amazon.com/cdk/v2/guide/cdk_pipeline.html

Step-up

  1. Create a new entry point. Call this bin/pipeline.ts.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';

export class PipelineStack extends cdk.Stack {
    constructor(scope: Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        // Pipeline code goes here
    }
}
  1. Create a new stack. Because it is separate from the prod application, it needs to be in its own stack. lib/pipeline-stack.ts
import * as cdk from 'aws-cdk-lib';
import { PipelineStack } from '../lib/pipeline-stack'

const app = new cdk.App();
new PipelineStack(app, 'CdkPipelineStack');
  1. Next we need to start creating the pipeline

Pipeline

  1. Create a pipeline and add the first stage.
    The synth prop, should install the dependencies, build, synth the CDK application fromthe source. The last command should always be npx cdk synth.
  1. The input step specifies where the code comes from #obvs
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CodeBuildStep, CodePipeline, CodePipelineSource } from "aws-cdk-lib/pipelines";

export class PipelineStack extends cdk.Stack {
    constructor(scope: Construct, id: string, props?: cdk.StackProps) {
        super(scope, id, props);

        const pipeline = new CodePipeline(this, 'Pipeline', {
            pipelineName: 'TestPipeline',
            synth: new CodeBuildStep('SynthStep', {
/// I grabbed the source from the url for the GITHUB bit
                input: CodePipelineSource.gitHub('Benjamintlj/aws-cdk-workshop-ts', 'main'),
                installCommands: [
                    'npm install -g aws-cdk' // need to install stuff
                ],
                commands: [
                    'npm ci',
                    'npm run build',
                    'npx cdk synth'
                ]
            })
        })
    }
}