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"))
)

The file exists, and the error message prints the directory I expect it to, so what's the issue here?
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"))
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With