AWS QLDB [ERROR] [Node.js QLDB Sample Code] Unable to create the ledger: ConfigError: Missing region in config

AWS QLDB [ERROR] [Node.js QLDB Sample Code] Unable to create the ledger: ConfigError: Missing region in config

AWS QLDB CreateLedger.js 抛出错误。

~repo/amazon-qldb-dmv-sample-nodejs$ node dist/CreateLedger.js 
[LOG][Node.js QLDB Sample Code] Creating a ledger named: vehicle-registration...
[AWS qldb undefined 0.005s 0 retries] createLedger({ Name: 'vehicle-registration', PermissionsMode: 'ALLOW_ALL' })
[ERROR][Node.js QLDB Sample Code] Unable to create the ledger: ConfigError: Missing region in config.

如何在 CreateLedger.js

中的 nodejs Typescript 代码中更新区域

https://docs.aws.amazon.com/qldb/latest/developerguide/getting-started.nodejs.step-1.html

我想在 CreateLeger.TS 文件中添加区域

import { QLDB } from "aws-sdk";

import {
    CreateLedgerRequest,
    CreateLedgerResponse,
    DescribeLedgerRequest,
    DescribeLedgerResponse,
 } from "aws-sdk/clients/qldb";

import { LEDGER_NAME } from "./qldb/Constants";
import { error, log } from "./qldb/LogUtil";
import { sleep } from "./qldb/Util";

const LEDGER_CREATION_POLL_PERIOD_MS = 10000; const ACTIVE_STATE = 
"ACTIVE";

export async function createLedger(ledgerName: string, qldbClient: 
QLDB): Promise<CreateLedgerResponse> {
log(`Creating a ledger named: ${ledgerName}...`);
const request: CreateLedgerRequest = {
    Name: ledgerName,
    PermissionsMode: "ALLOW_ALL"
}
const result: CreateLedgerResponse = await 
qldbClient.createLedger(request).promise();`enter code here`
log(`Success. Ledger state: ${result.State}.`);
return result; }

In which section I can add the region. So generated 
dist/createLedger.js file have the changes

您可以使用全局配置对象在 JavaScript 代码中设置区域。更新 AWS.Config 全局配置对象,如下所示:

AWS.config.update({region: 'us-east-1'});

或者,您可以在 shell:

中设置一个环境变量
export AWS_REGION=us-east-1

您可以在 Setting the AWS Region 中找到所有选项。

经过一番尝试,我得到了答案。 您可以在此文件中更新配置 ~src/qldb/logutil.ts

   import { config } from "aws-sdk";

   config.logger = console;
   config.update({region: 'us-east-1'});

关于此的一个注意事项: node.js SDK 默认情况下不会加载存储您的区域配置等的共享配置文件。我有时会发现这令人困惑,因为其他一些 SDK,例如boto3 默认情况下这样做。

您必须设置环境变量 AWS_SDK_LOAD_CONFIG=1 才能加载它。

此共享配置文件创建于例如当您完成 aws-cli.

中的 aws configure 步骤时

相关帖子: