Search code examples
javascriptnode.jsamazon-web-servicesaws-sdkserverless

AWS SDK V2 to V3 migration with minium code changes in Node JS apis


We have API built using AWS serverless framework. Here, we have used lot of aws services in our functions which are currently using aws-sdk v2. Now, I want to migrate it to use aws-sdk V3 with minium code change.

In most of the aws documentation/available docs on internet below steps are mentioned if we want to continue using v2 commands in v3.

  1. Replace your V2 SDK imports with the specific AWS Service packages you need.
  2. Create and use V3 service clients, replacing global values, such as region, with configuration values passed in as arguments to the client.
  3. Continue to use the callback and promise pattern used in V2.

If I follow this for .getObject() method, there is change in the way response is send. Previously it was buffer and now it is ReadableStream. So, my code breaks here.

Is it expected that if I want to use v2 commands in v3, I will need code change in the way response is handled?


Solution

  • WHen you upgrade to AWS SDK for JavaScript V3, its a new API. Do not attempt to use V2 calls when you are using V3 API in your project. If you do, your code will not be accurate and may break as you have seen.

    Instead update your code to use V3 logic and calls. Refer to the new API Reference to learn the V3 API:

    https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/preview/

    Here is a migration guide that will help you.

    https://github.com/aws/aws-sdk-js-v3/blob/main/UPGRADING.md