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
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?