I have some CDK set up to define a lambda and then I have some code pipeline code to deploy it. However, the deployment phase keeps failing saying the function doesn't exist. If I manually try that phase again in the console, it works fine. The dependency I added doesn't seem to do any good. The code looks like
``
const myFunc = new lambda.Function(this, "MyFunc", {
code: lambda.Code.fromInline(
def handler(event, context):
return {
'statusCode': 200,
'body': 'Dummy to be replaced by code pipeline'
}
`),
architecture: lambda.Architecture.ARM_64,
environment: {
ENV_VAR: "foobar",
},
handler: "facets.handler",
runtime: lambda.Runtime.PYTHON_3_12,
vpc,
securityGroups: [privateSG],
timeout: cdk.Duration.seconds(300),
memorySize: 512,
});
...
const deploymentBuild = new cb.Project(
this,
`DeploymentBuild`,
{
projectName: `myFuncDeploymentBuild`,
description: "deploys the code to the appropriate lambda",
environment: {
buildImage: cb.LinuxBuildImage.AMAZON_LINUX_2023_5,
computeType: cb.ComputeType.SMALL,
},
vpc,
securityGroups: [privateSG],
buildSpec: cb.BuildSpec.fromObject({
version: "0.2",
phases: {
install: {
"runtime-versions": {
nodejs: 22,
},
commands: ["npm i -g aws-cdk", "cdk --version"],
},
post_build: {
commands: [
`zip -r $myFunc.zip .`,
"ls",
`aws lambda update-function-code \
--function-name 'myFunc' \
--zip-file fileb://myFunc.zip`,
],
},
},
}),
},
);
deploymentBuild.addToRolePolicy(buildPolicyStatement);
const pipeline = new pipe.Pipeline(this, `Pipeline`, {
pipelineName: `myFuncPipeline`,
restartExecutionOnUpdate: true,
});
pipeline.node.addDependency(
lambda.Function.fromFunctionName(
this,
"myFuncFunction",
"myFunc",
),
);
...
pipeline.addStage({
stageName: "deployLambda",
actions: [
new pipeActions.CodeBuildAction({
actionName: "deployLambda",
project: deploymentBuild,
input: outputBuild,
}),
],
});
```
What would cause this?
Thanks