AWS SDK V2 到 V3 迁移,最小化 Node.js API 代码更改。

huangapple go评论91阅读模式
英文:

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

问题

我们使用AWS无服务器框架构建了API。在这里,我们在我们的函数中使用了许多AWS服务,这些服务目前正在使用aws-sdk v2。现在,我想迁移到使用aws-sdk V3,只需最少的代码更改。

在大多数AWS文档/互联网上可用的文档中,如果我们要继续在v3中使用v2命令,通常会提到以下步骤:

  1. 用特定的AWS服务包替换您的V2 SDK导入。
  2. 创建并使用V3服务客户端,将全局值(如区域)替换为作为参数传递给客户端的配置值。
  3. 继续使用V2中使用的回调和Promise模式。

如果我按照这个方法来处理.getObject()方法,响应发送的方式会发生变化。以前是缓冲区,现在是ReadableStream。所以,我的代码在这里出现了问题。

如果我想在v3中使用v2命令,是否预期需要更改处理响应的方式?

英文:

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?

答案1

得分: 1

当您升级到 AWS SDK for JavaScript V3 时,它是一个全新的 API。在项目中使用 V3 API 时,请不要尝试使用 V2 调用。如果这样做,您的代码将不准确,并且可能会出现错误,就像您所看到的那样。

而是更新您的代码以使用 V3 的逻辑和调用。请参考新的 API 参考文档来了解 V3 API:

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

这里有一个迁移指南可以帮助您:

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

英文:

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

huangapple
  • 本文由 发表于 2023年6月27日 17:12:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76563342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定