如何为 AWS V3 Dynamo 客户端设置超时 [英] How do I set a timeout for AWS V3 Dynamo Clients

查看:34
本文介绍了如何为 AWS V3 Dynamo 客户端设置超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已开始将新的 AWS 版本 3 sdk 用于我的一些服务.不幸的是,并不总是清楚如何使用模块化版本 3 代码中的一些功能,这些功能在版本 2 sdk 中可用.

I have started using the new AWS Version 3 sdk for some of my services. Unfortunately it is not always clear how to use some features in the modular version 3 code that are available in the Version 2 sdk.

要为非模块化 sdk 设置超时,您可以执行以下操作:

To set timeouts for the non-modular sdk, you can do the following:

AWS.config.update({
     httpOptions: {
        connectTimeout: 10000,
        timeout: 10000
    }
 });

但是,当我想使用版本 3 sdk 并使用 Dynamo 客户端时,我明确尝试不使用全局 AWS 对象.据我所知,DynamoDBClient 的配置输入不接受 httpOptions,这是通常设置超时的地方.

However, when I want to use the Version 3 sdk and use the Dynamo client, I am explicitly trying not to use the global AWS object. As far as I can tell the configuration input to DynamoDBClient does not accept httpOptions, which is where a timeout would normally get set.

import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
const REGION = process.env.AWS_REGION;
const v3DynamoClient: DynamoDBClient = new DynamoDBClient({ region: REGION });

如何在 AWS V3 sdk 中为 DynamoDBClient 设置超时?

How do I set a timeout for the DynamoDBClient in the AWS V3 sdk?

推荐答案

以下是设置 TLS v1.2 选项的示例,应该会有所帮助:

Here's an example of setting TLS v1.2 options that should help:

const https = require("https");
const {NodeHttpHandler} = require("@aws-sdk/node-http-handler");
const {DynamoDBClient} = require("@aws-sdk/client-dynamodb");
const client = new DynamoDBClient({
  region: "us-west-2",
  requestHandler: new NodeHttpHandler({
    httpsAgent: new https.Agent({secureProtocol: 'TLSv1_2_method'})
  })
});

您应该能够在选项中将 connectionTimeoutsocketTimeout 设置为 NodeHttpHandler.

You should be able to set connectionTimeout or socketTimeout in the options to NodeHttpHandler.

另外,值得一读 SDK v3 开发者指南.

这篇关于如何为 AWS V3 Dynamo 客户端设置超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆