alexcasalboni / aws-lambda-power-tuning

AWS Lambda Power Tuning is an open-source tool that can help you visualize and fine-tune the memory/power configuration of Lambda functions. It runs in your own AWS account - powered by AWS Step Functions - and it supports three optimization strategies: cost, speed, and balanced.
Apache License 2.0
5.27k stars 362 forks source link

feat: remove unnecessary lambda layer as SDK v3 is provided per default #245

Closed tknisch closed 2 months ago

tknisch commented 2 months ago

The usage of the own lambda layer is not necessary, because the AWS Javascript v3 SDK is provided to all Lambda NodeJS Runtimes >18 per default. See https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html#nodejs-sdk-included

Therefore the Lambda Layer hasn't to be build on every terraform apply.

alexcasalboni commented 2 months ago

Hey @tknisch 👋 thanks for sharing this!

Can you please share more about your thinking here? Is the SDK layer slowing down the deployment considerably?

The main reason why we have an SDK layer is because often you want to pin down the exact version of the SDK (sometimes to an older version because the latest version might have some issues, and sometimes to a newer version because the default SDK in the Lambda runtime doesn't have the super-latest features you need). As documented here, the best practice AWS recommends is to use the default runtime SDK to move fast while developing/prototyping, and then using a Lambda layer with a specific version of the SDK, in order to lock that version and make it immutable.

I understand this might sound like an overkill, but ultimately it's meant to reduce the chances that stuff breaks without notice. Using the layer, we can test the latest SDK version, run unit/integration tests, and then upgrade it for everyone without facing unexpected bugs.

I hope that makes sense - let me know what you think :)

tknisch commented 2 months ago

Hi @alexcasalboni ,

the idea behind this was, that when using the project as a submodule in a large terraform project, with the current approach the layer will be build on every terraform apply. Even if nothing changes.

In addition you will need npm installed and have access to either the npm registry or something else.

But I also got your points, which are also quite reasonable.

So your decision as the owner of the project :)

alexcasalboni commented 2 months ago

with the current approach the layer will be build on every terraform apply. Even if nothing changes.

I see. Is there a way to reduce the impact of this?

My thinking was that if you're integrating Lambda Power Tuning with your larger project, it's probably a CI/CD stack or a dev/staging environment (I wouldn't recommend deploying Lambda Power Tuning with your production stuff), so it shouldn't be such a big deal.

It's true that you don't need npm for anything else in this project. And I understand it might be annoying if the rest of the project is using Go or Rust, but it still seems like a reasonable dependency to have, given the benefits.

alexcasalboni commented 2 months ago

Closing this for now.

Happy to continue discussing, in case we can identify a way to reduce the impact of building the SDK layer on terraform apply.