UNPKG

duenamodb

Version:

Simple, strongly-typed helpers around the AWS SDK DynamoDB client.

49 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DDBClient = void 0; const client_dynamodb_1 = require("@aws-sdk/client-dynamodb"); const oidc_1 = require("@vercel/functions/oidc"); class DDBClient { static _client; static _params = {}; constructor() { } static get params() { if (!DDBClient._params.region) { DDBClient._params.region = process.env.AWS_REGION; } const isVercel = process.env.VERCEL || process.env.VERCEL_OIDC_TOKEN; if (!DDBClient._params.credentials && isVercel && process.env.AWS_ROLE_ARN) { DDBClient._params.credentials = (0, oidc_1.awsCredentialsProvider)({ roleArn: process.env.AWS_ROLE_ARN, }); } if (!DDBClient._params.credentials && process.env.AWS_ACCESS_KEY_ID && process.env.AWS_SECRET_ACCESS_KEY) { DDBClient._params.credentials = { accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, }; } return DDBClient._params; } static set params(value) { DDBClient._params = value; } static init() { if (!DDBClient._client) { DDBClient._client = new client_dynamodb_1.DynamoDBClient(DDBClient.params); } return DDBClient._client; } static get instance() { if (!DDBClient._client) { DDBClient.init(); } return DDBClient._client; } } exports.DDBClient = DDBClient; //# sourceMappingURL=client.js.map