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

feat: Reduce aws-cdk-lib package size by not bundling awscli Lambda Layer #21799

Closed
wants to merge 15 commits into from

Conversation

madeline-k
Copy link
Contributor

This PR is in draft state, and is not ready to be merged yet. A couple of notes for the reader:

  • In a future PR, I plan to move most of the code in AwsClilLayer to a private base class that can be used by all of the other Layers.
  • I am still trying to figure out the ideal install location, currently this PR installs to the first path in the require.main.paths list. I tried to use a well-known "global" install location, but removed it in this commit because it didn't work.

Todos:

  • Remove console logging
  • CLI integration tests (multiple languages)
  • Create instructions for manually installing the dependency if you don't have it
  • Before this can be released, the corresponding CLI notice as described in the RFC needs be created.

All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

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

…ate flag in package.json so it can be published separately
…at I can write a different implementation for it in v2 (this is a temporary measure, we still need a 'real' way to do make them differnt
… @aws-cdk/lambda-layer-awscli. This currently only works if the dependency is present in node_modules
This does not work, because the subsequent `require()` call fails to load the installed module, because it can't find the aws-cdk-lib and constructs peer-dependencies. Installing both of those seems like a performance cost we do not want to pay.
@gitpod-io
Copy link

gitpod-io bot commented Aug 29, 2022

@github-actions github-actions bot added the p2 label Aug 29, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team August 29, 2022 07:06
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Aug 29, 2022
@madeline-k madeline-k marked this pull request as draft August 29, 2022 07:06
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 625fccd
  • Result: FAILED
  • Build Logs (available for 30 days)

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

@madeline-k madeline-k changed the title feat: stop bundling the awscli in aws-cdk-lib feat: reduce aws-cdk-lib package size by not bundling awscli Lambda Layer Aug 29, 2022
@madeline-k madeline-k changed the title feat: reduce aws-cdk-lib package size by not bundling awscli Lambda Layer feat: Reduce aws-cdk-lib package size by not bundling awscli Lambda Layer Aug 29, 2022
Comment on lines 26 to 31
const installParentDir = os.homedir() ?? os.tmpdir();
this.wellKnownInstallDir = path.join(installParentDir, '.awscdk/npm-cache');

const version = this.requireWrapper(path.join(__dirname, '../package.json')).devDependencies[this.packageName];
const pathOfModuleIfAlreadyInstalled = require.resolve(`${this.packageName}`);
const versionAlreadyInstalled = this.requireWrapper(path.join(pathOfModuleIfAlreadyInstalled, '../../package.json')).version;
Copy link
Contributor

Choose a reason for hiding this comment

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

This will ultimately all go into a reusable function/class later, right? (I suppose it could go into core)

"constructs": "^10.0.0",
"lambda-layer-awscli-v1": "0.0.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we get this in the @aws-cdk namespace?


private installNpmPackage(): any {
console.log(`Shelling out to run npm install ${this.packageName} --no-save --prefix ${this.wellKnownInstallDir}`);
const result = childproc.execSync(`pwd; npm prefix; npm install ${this.packageName} --silent --no-save --prefix ${this.wellKnownInstallDir}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug commands in here?

@madeline-k
Copy link
Contributor Author

Superseded by #21938

@madeline-k madeline-k closed this Sep 7, 2022
@madeline-k madeline-k deleted the madeline-k/reduce-package-size/lambda-layers branch October 25, 2022 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants