Receive error in Lambda: Unable to import module 'functions': No module named 'functions' Traceback



I receive the error in Lambda: Receive error in Lambda: Unable to import module 'functions': No module named 'functions' Traceback

I have researched the issue and from what I understand it's a problem bundling some of python depencies and libraries. The issue I'm having, is I'm trying to find a fix for this issue via CDK. We deploy our resources via CDK and I would like to add the fix to the CDK stack.

How do I implement a deployment package with my lambda in CDK? Are there resources I can find for these steps?


1 Answer

Yes, it is possible to include your deployment package with your Lambda function in your CDK stack. Here's an example of how you can achieve this:

First, make sure you have the necessary dependencies installed to build and deploy your CDK stack. You can follow the instructions here to set up your environment:

Create a new directory for your CDK project and initialize a new CDK app:

mkdir my-cdk-project
cd my-cdk-project
cdk init app --language python

Create a new directory inside your project directory for your Lambda function and add a Python file with your function code:

mkdir functions
touch functions/

Add your Lambda function code to

Add the necessary CDK modules to your project:

pip install
pip install

In your file, create a new Lambda function using the aws_lambda.Function class and specify the path to your deployment package using the code parameter. Here's an example:

from aws_cdk import (

class MyCdkStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # Create a new Lambda function
        my_function = aws_lambda.Function(
            self, "MyFunction",

Make sure to replace "path/to/your/deployment/package" with the actual path to your deployment package.

Deploy your CDK stack using the cdk deploy command.

cdk deploy

This will create your Lambda function and deploy your deployment package to AWS.

I hope this helps!

profile pictureAWS
answered a year ago
  • Thanks for help,

    I actually havae this already. I'm using Jenkins to deploy it.

    I think it's important to note that I have the stack written in TypeSCript. But the lambda is in python.

    However, I do have the code=Code.fromAsset("<my_path">).

    Which now confuses me more why my lambda doesn't work.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions