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

318 Views Asked by At

AWS QLDB CreateLedger.js throwing error.

~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.

How to update region in nodejs Typescript code in CreateLedger.js

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

I want to add region in CreateLeger.TS file

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
3

There are 3 best solutions below

0
On BEST ANSWER

After some try I got the answer. you can update config in this file ~src/qldb/logutil.ts

   import { config } from "aws-sdk";

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

One note on this: The node.js SDK doesn't by default load the shared config file which stores your region configuration among other things. I've found this confusing at times since some of the other SDKs e.g. boto3 do that by default.

You have to set the environment variable AWS_SDK_LOAD_CONFIG=1 to load it.

This shared config file is created e.g. when you go through the aws configure steps in the aws-cli.

Related posts: How to Load config from ~/.aws/config

1
On

You can set the region in your JavaScript code using the Global Configuration Object. Update the AWS.Config global configuration object as shown here:

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

Alternatively, you could set an environment variable in your shell:

export AWS_REGION=us-east-1

You can find all options in Setting the AWS Region.