Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lambda-python): incorrect handler name when the handler is in a subdirectory #15981

Conversation

vincent-turato
Copy link
Contributor

If a handler function is located in a subdirectory of the lambda code package, the aws_lambda.Function handler property would be set to an incorrect value.

Copied from: #15391


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Aug 11, 2021

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: f11200f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@peterwoodworth peterwoodworth added @aws-cdk/aws-lambda-python effort/small Small work item – less than a day of effort labels Aug 11, 2021
@nija-at nija-at changed the title fix(lambda-python): python function index/handler logic broken if handler in subdirectory fix(lambda-python): incorrect handler name when the handler is in a subdirectory Aug 12, 2021
Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this PR. I just have one main comment.

I can't find any docs on how the handler name should be specified when it is in the inner directory - https://docs.aws.amazon.com/lambda/latest/dg/python-handler.html

Can you supply how you tested and confirmed that this is the correct solution, or point me to some docs?

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the status to 'request changes' to address the comment above.

@nija-at nija-at added the p2 label Aug 24, 2021
@vincent-turato
Copy link
Contributor Author

vincent-turato commented Aug 25, 2021

@nija-at
Please see: #15391 (comment)

His explanation aligns with my understanding. The problem is that the Lambda function handler is imported with slashes, when dot notation is what is needed for Python imports.

Copy link
Contributor

@nija-at nija-at left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vincent-turato -

Looks good generally. Just one comment.

@@ -113,7 +113,7 @@ export class PythonFunction extends lambda.Function {
assetHashType: props.assetHashType,
assetHash: props.assetHash,
}),
handler: `${index.slice(0, -3)}.${handler}`,
handler: `${index.replace(/\.py$/i, '').replace('/', '.')}.${handler}`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a little comment with a small example explaining this string replace?

@nija-at
Copy link
Contributor

nija-at commented Nov 25, 2021

Closing this PR since there has been no traction in a while.

@nija-at nija-at closed this Nov 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-python effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants