Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CDK Lambda Function Cannot Find Asset at Path

I'm trying to make a Lambda function using the AWS CDK They make it seem simple enough, but when I use cdk synth, it's giving me an error that the asset doesn't exist (even though it does exist). Here's my code:

cwd = os.getcwd()
aws_lambda.Function(self, "lambda_function",
     runtime=aws_lambda.Runtime.PYTHON_3_9,
     handler="index.handler",
     code=aws_lambda.Code.from_asset(os.path.join(cwd, "lambda_functions/lambda"))
)

CDK Directory

The file exists, and the error message prints the directory I expect it to, so what's the issue here?

like image 648
john4ster Avatar asked Aug 10 '26 10:08

john4ster


1 Answers

From documentation
The Code.from_asset(...) requires you to specify a directory or a .zip file. From your code you're referencing a directory which is not true. Change the path to add .zip extension.

cwd = os.getcwd()
aws_lambda.Function(self, "lambda_function",
     runtime=aws_lambda.Runtime.PYTHON_3_9,
     handler="index.handler",
     code=aws_lambda.Code.from_asset(os.path.join(cwd, "lambda_functions/lambda.zip"))
)
like image 92
Manav Chhibber Avatar answered Aug 11 '26 23:08

Manav Chhibber