Skip to content

(lambda-python): PythonFunction index/handler logic broken if handler in subdirectory #15391

@ewahl-al

Description

@ewahl-al

If a handler function is located in a subdirectory of the lambda code package, the aws_lambda.Function handler property is set to an incorrect value by this line of code in aws-lambda-python/lib/function.ts:

      handler: `${index.slice(0, -3)}.${handler}`,

Reproduction Steps

  1. Create a python lambda code package where a handler function is not in the root directory of the package. Example
root/
--- main_file.py
--- handlers/
------ __init__.py
------ my_handler.py
--- lib/
------ __init__.py
------ other_python_code.py
  1. Then deploy a CDK stack containing a PythonFunction construct using this handler. Example:
from aws_cdk import aws_lambda_python as lambda_python

lambda_python.PythonFunction(
    self, 'ExampleFunction',
    entry="../root",
    handler="handle_lambda",
    index="handlers/my_handler.py")

What did you expect to happen?

A lambda function should be deployed with the handler property set to handlers.my_handler.handle_lambda

What actually happened?

A lambda function was deployed with the handler property set to handlers/my_handler.handle_lambda

Environment

  • **CDK CLI Version : 1.107.00
  • **Framework Version: 1.107.0
  • **Node.js Version: v12.8.3
  • **OS : macos
  • **Language (Version): Python 3.8.5

Other

The index.slice string substitution should replace / characters with . characters.


This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions