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

chore: minify lambda function code and add source maps #1695

Merged
merged 6 commits into from
Jul 2, 2024
Merged

Conversation

Amplifiyer
Copy link
Contributor

@Amplifiyer Amplifiyer commented Jun 28, 2024

Problem

Issue number, if available:

Changes

Enable minifying and adding sourcemaps to underlying lambda functions bundled code.

Validation

Existing e2e passes and manually validated the minified and source maps in source code.

PS: I couldn't find a way to "inspect" the cdk assets so that I can observe the actual minification and source maps.

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

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

@Amplifiyer Amplifiyer added the run-e2e Label that will include e2e tests in PR checks workflow label Jun 28, 2024
Copy link

changeset-bot bot commented Jun 28, 2024

🦋 Changeset detected

Latest commit: 151fe05

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/backend-function Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Amplifiyer Amplifiyer marked this pull request as ready for review June 28, 2024 14:38
@Amplifiyer Amplifiyer requested review from a team as code owners June 28, 2024 14:38
.split(new RegExp(`${EOL}|\n|\r`, 'g'))
.map((line) => line.replace(/\/\/.*$/, '')) // strip out inline comments because the banner is going to be flattened into a single line
.join('');
const bannerCode = uglifyJs.minify(
Copy link
Member

Choose a reason for hiding this comment

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

couple of questions here:

  1. The banner isn't big, is it worth obscuring it?
  2. Is minify knob below using same tool under the hood? If not, should we try to align that?

I'm asking because we're introducing new dependency and I'm not sure it's worth it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. cc: @josefaidt as I got this as product req.
  2. cdk uses esbuild's minification and I couldn't find if esbuild is using any external library for minification.

Copy link
Contributor

Choose a reason for hiding this comment

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

now that we're bundling the AWS SDK should we run this through esbuild with similar settings?

Copy link
Member

@sobolk sobolk Jun 28, 2024

Choose a reason for hiding this comment

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

We could but it seems to be an overkill.

The SSM snippet weighs around 1877 bytes.
The Bundled AWS SDK for S3 with dependencies weighs around 1390882 bytes (this is from SDK bundling prototype).

Copy link
Member

Choose a reason for hiding this comment

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

I recommend to descope SSM snippet for now and seek esbuild based solution for it separately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wouldn't the aws-sdk be bundled and hence minified by the esbuild ran by aws-cdk?

Copy link
Contributor

@josefaidt josefaidt Jul 1, 2024

Choose a reason for hiding this comment

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

that seems fair

to @Amplifiyer 's note, it should bundle the SSM client and any dependencies it needs, but shouldn't be too heavy

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

discussed offline with @Amplifiyer and decided to think about bundling/minifying the banner code separately. it'll have other implications where we'd have to think about avoiding duplication of dependency code in the resulting bundle

@Amplifiyer Amplifiyer merged commit 90ac407 into main Jul 2, 2024
52 checks passed
@Amplifiyer Amplifiyer deleted the minification branch July 2, 2024 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-e2e Label that will include e2e tests in PR checks workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants