Upgrading AWS Lambda Scripts from Node.js 16.x to 18.x with Minimal Changes

I have a collection of 15-20 scripts running on AWS Lambda with Node.js 16.x that perform various operations, including interacting with S3 using functions like copy, headObject, putObject, and getObject. Additionally, my scripts utilize AWS services such as Step Functions, Glue, SNS, and Athena. I cannot stick with 16.x since it has a deadline of mid of June 2024.

I need expert guidance on the minimal changes required to make these scripts compatible with Node.js 18.x. While it would be beneficial if they could also work with Node.js 20.x, that’s not a priority at the moment.

One of the scripts looks like this:

// Script to read, modify, and write CSV files to S3 after removing quotes.
// Requires AWS-SDK v2 and utilizes AWS Step Functions.

const AWS = require('aws-sdk');
const sf = new AWS.StepFunctions();
const s3 = new AWS.S3();
const rl = require('readline');
const stream = require('stream');

// Randomized AWS credentials
AWS.config.update({
    region: {mention-region-here}
});

function extractBucketName(path) {
    var parts = path.split("/", 3);
    return parts[2];
}

function extractBucketKey(path) {
    var s = path.replace(/^s3:///, "");
    var pos = s.indexOf("/");
    var key = s.substr(pos + 1);
    return key;
}

exports.handler = function(event, context, callback) {
    // Main logic to read from S3, process, and write back to S3.
    if ((typeof event.inputFile != "undefined") && (typeof event.outputFile != "undefined")) {
        var paramsInput = {
            Bucket: extractBucketName(event.inputFile),
            Key: extractBucketKey(event.inputFile)
        };

        // Create read stream from S3
        var readStream = s3.getObject(paramsInput).createReadStream();

        // Pass the S3 read stream into the readline interface to break into lines
        var lineReader = rl.createInterface({
            input: readStream,
            terminal: false
        });

        // Create a write stream to upload processed data back to S3
        const writeStream = new stream.PassThrough();
        var paramsOutput = {
            Bucket: extractBucketName(event.outputFile),
            Key: extractBucketKey(event.outputFile),
            Body: writeStream
        };
        s3.upload(paramsOutput).promise();

        // Process each line from the input file
        lineReader.on('line', function(line) {
            // Perform processing on line (remove quotes)
            line = line.replace(/['"]+/g, '');
            // Write processed line to the write stream
            writeStream.write(`${line}n`);
        }).on('close', function() {
            // Close the write stream after processing is complete
            writeStream.end();
            callback(null);

            // Example code to send success token to AWS Step Functions
            var taskParams = {
                output: JSON.stringify('Write a success message'),
                taskToken: event.token
            };
            sf.sendTaskSuccess(taskParams, function(err, data) {
                if (err) {
                    console.error(err.message);
                    callback(err.message);
                    return;
                }
                console.log(data);
                callback(null);
            });
        });
    }
};

I have already read Amazon’s articles and documentation, but I still don’t have a clear picture of what needs modification and what doesn’t for the transition from Node.js 16.x to 18.x. I want to avoid the trial-and-error method to save me from a error nightmare. Any expert advice from the community on the changes required for a smooth transition would be greatly appreciated. Thank you!

After I upgraded my NodeJs from 16.x to 18.x in dev, I tried the following articles:
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/s3/
and other articles, but unfortately, that does not provide all the information I need.
Also, I read this question:
Lambda function cant load AWS sdk after switching to 18.x

But that is just for s3 and does not help completely

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật