7

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?

1
  • 2
    You didn't specific the .zip extension, so CDK is looking for a directory instead of your zip file Commented Jul 25, 2022 at 3:21

1 Answer 1

4

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"))
)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.