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

aws_cdk.aws_lambda.Function: Python's Function uses Node.js' __dirname #29099

Open
garysassano opened this issue Feb 14, 2024 · 2 comments
Open
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. documentation This is a problem with documentation. jsii This issue originates in jsii, or this feature must be implemented in jsii. needs-review p2

Comments

@garysassano
Copy link

garysassano commented Feb 14, 2024

Describe the issue

Example

import aws_cdk.aws_signer as signer


signing_profile = signer.SigningProfile(self, "SigningProfile",
    platform=signer.Platform.AWS_LAMBDA_SHA384_ECDSA
)

code_signing_config = lambda_.CodeSigningConfig(self, "CodeSigningConfig",
    signing_profiles=[signing_profile]
)

lambda_.Function(self, "Function",
    code_signing_config=code_signing_config,
    runtime=lambda_.Runtime.NODEJS_18_X,
    handler="index.handler",
    code=lambda_.Code.from_asset(path.join(__dirname, "lambda-handler"))
)

The JSII's autogenerated code uses Node.js' __dirname, which isn't valid in Python.

Ideally, you should want to use pathlib as best practice:

code=lambda_.Code.from_asset(
  str(Path(__file__).parent / "lambda-handler")
)

Also, the default Lambda function's handler in Python is:

handler="lambda_function.lambda_handler"

Links

https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_lambda/Function.html

@garysassano garysassano added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2024
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Feb 14, 2024
@pahud
Copy link
Contributor

pahud commented Feb 14, 2024

I guess this might be a bug from JSII as the sample is auto generated from the one in TypeScript. Thank you for the report.

@pahud pahud added p2 jsii This issue originates in jsii, or this feature must be implemented in jsii. needs-review and removed needs-triage This issue or PR still needs to be triaged. labels Feb 14, 2024
@gshpychka
Copy link
Contributor

jsii-rosetta, rather

@ashishdhingra ashishdhingra added the bug This issue is a bug. label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda bug This issue is a bug. documentation This is a problem with documentation. jsii This issue originates in jsii, or this feature must be implemented in jsii. needs-review p2
Projects
None yet
Development

No branches or pull requests

4 participants