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

Updating lambda functions to nodejs 20 #222

Closed mettke closed 6 months ago

mettke commented 6 months ago

Fixes: #221

This PR switches NodeJS Version from v16 to v20. Two additional changes came from me using an Editor which adds a newline on save.

alexcasalboni commented 6 months ago

Amazing, thanks 🙏 🎉

This looks great and all the unit tests run smoothly as expected 👌 Don't worry about the failing integration tests for now, it's just an auth issue.

I'll do some more testing in the next few days and then merge!

mettke commented 6 months ago

It looks like lambda's starting with nodejs 18 do not ship aws sdk v2 1. Currently the code still uses const AWS = require('aws-sdk'); so we may have to do a bit more then this to get it up and running 2. This should have been an issue with the nodejs 18 build already, but I guess the build does not explicitly check that.

I suggest that we add a test which tries to run the code on a given aws lambda container 3. This way we should be able to detect whether its going to work in given nodejs environment.

mettke commented 6 months ago

Ok I think I should be done now. What I changed:

This should do it. I guess it was a bit more difficult then changing 16 to 20 😆

alexcasalboni commented 6 months ago

Hey @mettke 👋 apologies for the long wait :)

I don't fully understand why we need all of this, since we can control the available SDK with the ad-hoc layer. Wouldn't that work with Node v20?

mettke commented 6 months ago

It would work yes. But aws sdk v2 will enter maintaince mode "soon":

We are formalizing our plans to make the Maintenance Announcement (Phase 2) for AWS SDK for JavaScript v2 in early 2024. Please refer to the AWS SDKs and Tools maintenance policy for further details. [1]

So the question is, do we want to use the layer now and once sdk v2 is deprecated we migrate to v3, or do we want to use this code now and remove the v2 stuff once its deprecated.

Decision is up to you and I'm happy to revert. Of course we can also turn the question around. Instead of using the layer for v2 we could also use the layer for v3 and get nodejs 16 to support sdk v3. This way we can migrate already without having to support both.

[1] https://github.com/aws/aws-sdk-js

alexcasalboni commented 6 months ago

I see, you're right.

Then I would:

  1. keep this PR focused on Node v20
  2. open a new PR to migrate to SDKv3
  3. use the existing layer for SDKv3

The reason is that I don't think supporting both SDKs will be that useful in the long term and since you've already mapped all the API calls, it makes sense to just migrate and forget about SDKv2 (big thanks for that, I had been thinking about SDKv3 migration for a while!).

mettke commented 6 months ago

Sounds reasonable. I removed the last two commits and now only the migration to nodejs20 is in. I will also create a new PR regarding moving to sdkv3 removing sdkv2.