Slide 21
Slide 21 text
ONE PROGRAMMING LANGUAGE FROM THE FLOOR TO THE CEILING
© 2023, Amazon Web Services, Inc. or its affiliates.
AWS CDK Pipelines
25
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as pipelines from 'aws-cdk-lib/pipelines’;
import { MyPipelineAppStage } from './my-pipeline-app-stage';
export class MyPipelineStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const pipeline = new pipelines.CodePipeline(this, 'Pipeline', {
pipelineName: 'MyPipeline',
synth: new pipelines.ShellStep('Synth', {
input: pipelines.CodePipelineSource.gitHub('OWNER/REPO', 'main'),
commands: ['npm ci', 'npm run build', 'npx cdk synth']
})
});
const test = pipeline.addStage(new MyPipelineAppStage(this, "test", {
env: { account: ”222222222222", region: "eu-west-1" }
}));
const prod = pipeline.addStage(new MyPipelineAppStage(this, "prod", {
env: { account: ”333333333333", region: "eu-west-1" }
}));
prod.addPre(new pipelines.ManualApprovalStep('Approve'));
}
}
#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import { MyPipelineStack } from '../lib/my-pipeline-stack';
const app = new cdk.App();
new MyPipelineStack(app, 'MyPipelineStack', {
env: {
account: ‘111111111111',
region: 'eu-west-1',
}
});
import * as cdk from 'aws-cdk-lib';
import { Construct } from "constructs";
import { MyStack } from './my-stack';
export class MyPipelineAppStage extends cdk.Stage {
constructor(scope: Construct, id: string, props?: cdk.StageProps) {
super(scope, id, props);
const myStack = new MyStack(this, 'MyStackWithResources');
}
}
bin/my-pipeline.ts
lib/my-pipeline-stack.ts
lib/my-pipeline-app-stage.ts