Last active
March 2, 2022 17:06
-
-
Save cagingulsen/bb04498b383946e24ab2997d8ad6aea9 to your computer and use it in GitHub Desktop.
for Production-Ready CDK - CDK Pipelines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Stack, StackProps, Stage } from 'aws-cdk-lib'; | |
| import { CodePipeline, CodePipelineSource, ShellStep } from 'aws-cdk-lib/pipelines'; | |
| import { Construct } from 'constructs'; | |
| import { LambdaStack } from './lambda-stack'; | |
| // 3a. We define a Lambda Stage that deploys the Lambda Stack. | |
| export class LambdaStage extends Stage { | |
| constructor(scope: Construct, id: string) { | |
| super(scope, id); | |
| new LambdaStack(this, 'LambdaStack'); | |
| } | |
| } | |
| export class CdkPipelineStack extends Stack { | |
| constructor(scope: Construct, id: string, props?: StackProps) { | |
| super(scope, id, props); | |
| // 1. We import the CodeStar Connection for Github-CDK Pipeline integration. Therefore, | |
| // you only need to provide the ARN of the Connection. | |
| const codePipelineSource = CodePipelineSource.connection('cagingulsen/prod-ready-cdk','main', { | |
| connectionArn: 'arn:aws:codestar-connections:eu-west-1:YOUR_ACCOUNTI_D:connection/YOUR_CONNECTION_ID' | |
| }, | |
| ); | |
| // 2. We define the CDK Pipeline using the source from the first step and | |
| // use three commands for the synth step. We install dependencies from the yarn.lock file | |
| // with yarn install --frozen-lockfile command to have deterministic, fast, and repeatable builds. | |
| // The following two lines, we already know. | |
| const cdkPipeline = new CodePipeline(this, 'CdkPipeline', { | |
| pipelineName: 'lambda-stack-cdk-pipeline', | |
| synth: new ShellStep('Synth', { | |
| input: codePipelineSource, | |
| commands: [ | |
| 'yarn install --frozen-lockfile', | |
| 'npx projen build', | |
| 'npx projen synth', | |
| ], | |
| }), | |
| }); | |
| // 3b. Then we add this to the CDK Pipeline as a pipeline stage. | |
| cdkPipeline.addStage(new LambdaStage(this, 'dev')); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment