(AWS CDK) set up pipeline

0

I have used aws cdk to create a lambda function and now I want to set up a code pipeline for CICD. but I have not clue how to make it works since my lambda has use a 3rd party dependency.

The is my lambda stack

import { Duration, Stack, StackProps } from 'aws-cdk-lib';
import * as cdk from 'aws-cdk-lib';
import { Code, LayerVersion, Runtime } from 'aws-cdk-lib/aws-lambda';
import { NodejsFunction } from 'aws-cdk-lib/aws-lambda-nodejs';
import { Construct } from 'constructs';

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

    const axiosLayer = new LayerVersion(this, 'axios', {
      code: Code.fromAsset('./resources/layers/axios'),
      compatibleRuntimes: [Runtime.NODEJS_16_X],
      description: 'axios'
    })


    const db = new NodejsFunction(this, 'axiosLambda', {
      memorySize: 1024,
      timeout: Duration.seconds(300),
      runtime: Runtime.NODEJS_16_X,
      entry: `./resources/lambdas/index.ts`,
      handler: 'handler',
      bundling: {
        minify: false,
        externalModules: ['axios'],
        preCompilation: true
      },
      layers: [axiosLayer]
    })


    new cdk.CfnOutput(this, 'phpcall', {
      value: db.functionName,
    })



  }
}

This is my lambda folder structrue Enter image description here

After I adding below 2 stack and change the bin folder which the cdk entry point to the pipeline stack it will not work... I am not sure why

My pipeline stack

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

        // Creates a CodeCommit repository called 'WorkshopRepo'
        const repo = new codecommut.Repository(this, 'phpcall-repo', {
            repositoryName: "Php-call-repo"
        })
        const pipeline = new CodePipeline(this, 'Pipeline', {
            pipelineName: 'php-call-pipeline',
            synth: new CodeBuildStep('SynthStep', {
                input: CodePipelineSource.codeCommit(repo, 'main'),
                installCommands: [
                    'npm install -g aws-cdk',
                    'npm install axios'
                ],
                commands: [
                    'npm ci',
                    'npm run build',
                    'npx cdk synth'
                ]
            }
            )
        });
        const deploy = new PipelineStage(this, 'Deploy');
        const deplyStage = pipeline.addStage(deploy)

    }

}


my stage stack

import { Stage, StageProps } from 'aws-cdk-lib'
import { Test3Stack } from './test3-stack'
import { Construct } from 'constructs'


export class PipelineStage extends Stage {
    constructor(scope: Construct, id: string, props?: StageProps) {
        super(scope, id, props);

        new Test3Stack(this, 'php-call-service')
    }
}

  • Do you have any logs? The only error I see is your CodeCommit instance, it says codecommut.

  • Can you please share the results of running npm run build and cdk synth?

1 Answer
0

To identify the root cause of your error please run npm run build to identify any syntax errors or other build errors, and cdk synth to identify any CDK synth errors. From reviewing your code in an interpreter it looks like your creation of the codecommit repository has a syntax error:

// Creates a CodeCommit repository called 'WorkshopRepo'
        const repo = new codecommut.Repository(this, 'phpcall-repo', {
            repositoryName: "Php-call-repo"
        })

new codecommut.Repository should be new codecommit.Repository unless you also imported it with that spelling. Please ensure your import of codecommit looks like this:

import { aws_codecommit as codecommit } from 'aws-cdk-lib';

This will likely resolve your error, but if it it does not running build and synth should give you the information you need.

AWS
answered 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions