Home  >  Q&A  >  body text

AWS SDK V2 to V3 migration with minimal code changes in the Node JS api

We have an API built using the AWS serverless framework. Here we are using a lot of aws services in our functions and currently using aws-sdk v2. Now I want to migrate it to use aws-sdk V3 with minimal code changes.

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

  1. Replace your V2 SDK import with the specific AWS service pack you require.
  2. Create and use V3 service client, replacing global values, for example Region, configuration value passed as parameter to client.
  3. Continue to use the callback and Promise patterns used in V2.

If I do this as per the .getObject() method, the way the response is sent changes. It used to be buffer, now it's ReadableStream. So, my code breaks here.

If I want to use v2 commands in v3, do I need to change the code that handles the response?

P粉156415696P粉156415696177 days ago415

reply all(1)I'll reply

  • P粉769045426

    P粉7690454262024-03-28 13:39:23

    When you upgrade to AWS SDK V3 for JavaScript, it is a new API. When you use the V3 API in your project, do not attempt to use V2 calls. If you do this, your code will be inaccurate and may be broken like you are seeing.

    Instead update your code to use V3 logic and calls. See the new API reference to learn about the V3 API:

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

    Here is a migration guide to help you.

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

    reply
    0
  • Cancelreply