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

(lambda-python): add local bundling to PythonFunction #18290

Open
2 tasks
relm923 opened this issue Jan 6, 2022 · 11 comments
Open
2 tasks

(lambda-python): add local bundling to PythonFunction #18290

relm923 opened this issue Jan 6, 2022 · 11 comments
Labels
@aws-cdk/aws-lambda-python effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@relm923
Copy link
Contributor

relm923 commented Jan 6, 2022

Description

Similar to the NodeJs Lambda, Python Lambda packaging should allow for local bundling

Use Case

Docker bundling of lambdas is slow and resource intensive. Its valuable to be able to run bundling locally, without Docker.

Proposed Solution

Add a local bundling option similar to NodeJs.

Other information

No response

Acknowledge

  • I may be able to implement this feature request
  • This feature might incur a breaking change
@relm923 relm923 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jan 6, 2022
@corymhall
Copy link
Contributor

As of the latest CDK version (2.4.0/1.38.0) this behavior in PythonFunction is the same as it is for NodejsFunction. You should no longer see bundling for a stack if bundling is skipped. Before 2.4.0 the bundling for PythonFunction actually occurred during the docker build (as part of DockerImage.fromBuild()) which is why bundling was never skipped.

You will still see the docker image being built every time, but it should be much faster than before since bundling is not occurring as part of the build. This is also the current behavior for all of the constructs that use Docker bundling.

I think it would be great if we could skip the docker build as well. We can repurpose this issue to track that if you want.

@corymhall corymhall added p2 and removed needs-triage This issue or PR still needs to be triaged. labels Jan 7, 2022
@relm923
Copy link
Contributor Author

relm923 commented Jan 7, 2022

Thanks for the clarification @corymhall. We are in fact seeing what you described. We leverage NodeJsFunction option for local/non-docker builds which allows us to fully skip bundling there.

Having the ability to fully skip the docker build using BUNDLING_STACKS and/or supporting building completely outside of Docker would be great

@corymhall
Copy link
Contributor

OK maybe I'll repurpose this issue to track allowing local bundling for PythonFunction and I'll use #14747 to track skipping the docker build altogether.

@relm923
Copy link
Contributor Author

relm923 commented Jan 7, 2022

Sounds good!

@corymhall corymhall changed the title (aws-lambda-python): respect BUNDLING_STACKS config to skip python bundling (lambda-python): add local bundling to PythonFunction Jan 7, 2022
@relm923
Copy link
Contributor Author

relm923 commented Jan 7, 2022

@corymhall just to clarify - even with aws-cdk-lib v2.4.0 and @aws-cdk/aws-lambda-python-alpha v2.4.0-alpha.0 we're still seeing the Docker image being pulled, pipenv being installed and all the lambda dependencies when running:

CDK_CONTEXT_JSON='{\"aws:cdk:bundling-stacks\":[\"NONE\"]}' cdk synth

Is this expected?

@corymhall
Copy link
Contributor

The aws:cdk:bundling-stacks is internal context that cannot be set by the user. This value is calculated based on the stacks that are provided with the --exclusively option. So if I have 2 stacks StackA and StackB and I run

cdk synth --exclusively StackA

Then aws:cdk:bundling-stacks will be ['StackA'] and bundling will be skipped for StackB

It is currently not possible to skip bundling for a stack that you are synthesizing.

@corymhall corymhall added effort/large Large work item – several weeks of effort effort/medium Medium work item – several days of effort and removed effort/large Large work item – several weeks of effort labels Jan 26, 2022
@corymhall corymhall removed their assignment Mar 4, 2022
@athewsey
Copy link

+1 and is anybody aware of a nice workaround for containerless PythonFunction builds at the moment? I'm trying to get CDK working in an Azure Pipelines environment where the runtime is Linux but DinD is not available (but explicit Docker task steps could be?)... Our stack doesn't have any other need for container building: Just a few Python Lambda functions.

@kirnberger1980
Copy link

+1 for this issue

@github-actions github-actions bot added p1 and removed p2 labels Feb 4, 2024
Copy link

github-actions bot commented Feb 4, 2024

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

@CoreOxide
Copy link

As @evgenyka mentioned, I will open a PR for my RFC (aws/aws-cdk-rfcs#609) under this issue.

@evgenyka
Copy link
Contributor

@CoreOxide please note that #26062 was a previous trial to achieve that, but was abandoned. Pls see the comments there.

@pahud pahud added p2 and removed p1 labels Jun 11, 2024
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/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

7 participants