Skip to content
New issue

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

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

Already on GitHub? # to your account

aws-lambda-python-alpha: dependencies are skipped when using a custom bundler #30540

Closed
trondhindenes opened this issue Jun 13, 2024 · 3 comments
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@trondhindenes
Copy link

Describe the bug

I'm trying to use a custom docker image based on the SAM sam/build-python3 image to install a specific set of dependencies in my python-based lambda function. The default bundling functionality is far to coarse, so I need to use my own image.

My image ends with:

WORKDIR /var/dependencies
COPY pyproject* poetry*  ./
RUN \
  # Only install the lambda_function dependency group, skip the default "cdk" group
  poetry export --with lambda_function --without cdk --with-credentials --format requirements.txt --output requirements.txt &&\
  pip install -r requirements.txt -t .

CMD [ "python" ]

so, all dependencies are packaged in the folder /var/dependencies when the image build completes, which is also the current WORKDIR of the image.

However, there's no way for me to understand or control how bundling actually happens based on this image - which folders are picked up and used for constructing the uploaded zip file etc.

My cdk app snippet looks like this:

        log_shipper_function = python_alpha.PythonFunction(
            self, 'logShipperFunction',
            entry=log_shipper_function_folder,
            index='handler.py',
            runtime=aws_lambda.Runtime.PYTHON_3_12,
            log_retention=aws_logs.RetentionDays.FIVE_DAYS,
            bundling=python_alpha.BundlingOptions(
                image=cdk.DockerImage.from_build(
                    '.',
                    file='Dockerfile',
                    build_args={
                        'POETRY_HTTP_BASIC_PRIVATE_USERNAME': 'aws',
                        'POETRY_HTTP_BASIC_PRIVATE_PASSWORD': os.getenv('POETRY_HTTP_BASIC_PRIVATE_PASSWORD')
                    }
                )
            )
        )

The resulting function consists only of the source code files present in log_shipper_function_folder, not any dependencies in the build image.

My question is: How can I control/understand what folders are being picked up when building the zip?

Expected Behavior

a zip is built containing the source code files along with the dependencies in the image

Current Behavior

dependencies are skipped

Reproduction Steps

see above

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.127.0 (build 6c90efc)

Framework Version

No response

Node.js Version

20

OS

ubuntu 24

Language

Python

Language Version

Python 3.12

Other information

No response

@trondhindenes trondhindenes added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 13, 2024
@khushail
Copy link
Contributor

Hey @trondhindenes , thanks for reaching out. this document about custom bundling in python CDK might be able to help explain how custom bundling happens. Please feel free to let me know if its helpful in resolving the issue

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p3 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. effort/small Small work item – less than a day of effort labels Jun 25, 2024
Copy link

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 28, 2024
@github-actions github-actions bot added closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jul 3, 2024
@github-actions github-actions bot closed this as completed Jul 3, 2024
@aws-cdk-automation
Copy link
Collaborator

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

@aws aws locked as resolved and limited conversation to collaborators Jul 25, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. p3 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

3 participants