How to use the aws-sdk.DynamoDB function in aws-sdk

To help you get started, we’ve selected a few aws-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github devonfw / my-thai-star / serverless (deprecated) / database / deleteTables.ts View on Github external
creds = new AWS.Credentials('akid', 'secret', 'session');
        conf = {
            credentials: creds,
            endpoint: databaseURL,
            region: 'us-west-2',
        };
    } else {
        creds = new AWS.Credentials('akid2', 'secret2', 'session2');
        conf = {
            credentials: creds,
            endpoint: databaseURL,
            region: 'us-west-2',
        };
    }

    const dynamodb = new AWS.DynamoDB(conf);

    dynamodb.listTables().eachPage((err, data) => {
        if (err) {
            console.error(err); // an error occurred
            return false;
        } else if (data && data.TableNames) {
            data.TableNames.map((elem) => {
                return {
                    TableName: elem,
                };
            }).forEach((params) => {
                dynamodb.deleteTable(params, (err2: Error, data2: any) => {
                    if (err2) {
                        console.error('Unable to delete table. Error JSON:', JSON.stringify(err2, null, 2));
                    }
                });
github repo-analytics / repo-analytics.github.io / backend / db / dynamodb.js View on Github external
config = require('../secret.json');
} catch (error) {
  console.log('no secret json, on github action')
}

const awsConfig = {
  region: 'us-east-1',
  // process.env.awsAccessKeyId in action secret
  accessKeyId: process.env.awsAccessKeyId ? process.env.awsAccessKeyId : config.aws.accessKeyId,
  secretAccessKey: process.env.awsSecretAccessKey ? process.env.awsSecretAccessKey : config.aws.secretAccessKey,
  signatureVersion: 'v4',
};

AWS.config.update(awsConfig);

const dynamodb = new AWS.DynamoDB();

module.exports = dynamodb;
github danilop / LambdAuth / LambdAuthLostPassword / index.js View on Github external
console.log('Loading function');

// dependencies
var AWS = require('aws-sdk');
var crypto = require('crypto');
var config = require('./config.json');

// Get reference to AWS clients
var dynamodb = new AWS.DynamoDB();
var ses = new AWS.SES();

function getUser(email, fn) {
	dynamodb.getItem({
		TableName: config.DDB_TABLE,
		Key: {
			email: {
				S: email
			}
		}
	}, function(err, data) {
		if (err) return fn(err);
		else {
			if ('Item' in data) {
				fn(null, email);
			} else {
github Dynatrace / AWSDevOpsTutorial / lambdas / utils / buildvalidationtable.js View on Github external
exports.markBuildValidationEntryAsUpdated = function(dynamoDbItem, callback) {
    var ddb = new AWS.DynamoDB();
    
    var params = {
        Key:{
            "RequestID": { N: dynamoDbItem.RequestID.N } 
        },
        ExpressionAttributeValues: {
            ':resultsUploaded' : {S: "1"}
        },
        UpdateExpression: "set ResultsUploaded=:resultsUploaded",
        TableName: DYNAMODBTABLE,
        ReturnValues : 'UPDATED_NEW'
    };
    
    // now we update the item in DynamoDB
    ddb.updateItem(params, function(err, data) {
        if (err) {
github laardee / serverless-authentication-boilerplate / test / dynamo.js View on Github external
const endpoint = process.env.LOCAL_DDB_ENDPOINT;
const project = process.env.PROJECT;
const stage = process.env.STAGE;
const region = process.env.REGION;
const table = [stage, project, 'cache'].join('-');

const fs = require('fs');
const YAML = require('js-yaml');

const env = YAML.load(fs.readFileSync('./authentication/serverless.yml').toString());
const resources = env.resources.Resources;

const async = require('async');
const { DynamoDB } = require('aws-sdk');

const db = new DynamoDB({ endpoint, region });

let ready = false;

function init(cb) {
  resources.CacheTable.Properties.TableName = table;
  async.waterfall([
    (callback) => {
      db.listTables({}, callback);
    },
    (data, callback) => {
      const tables = data.TableNames;
      if (tables.indexOf(table) < 0) {
        db.createTable(resources.CacheTable.Properties, (err, created) => {
          if (!err) {
            callback(null, `table ${created.TableDescription.TableName} created`);
          } else {
github awslabs / ai-powered-speech-analytics-for-amazon-connect / source / ws_realtime_transcribe_OnMessage / index.js View on Github external
*                                                                                                                    *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated      *
 *  documentation files (the "Software"), to deal in the Software without restriction, including without limitation   *
 *  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and  *
 *  to permit persons to whom the Software is furnished to do so.                                                     *
 *                                                                                                                    *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO  *
 *  THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE    *
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF         *
 *  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS *
 *  IN THE SOFTWARE.                                                                                                  *
 **********************************************************************************************************************/

var AWS = require('aws-sdk');
AWS.config.update({ region: process.env.AWS_REGION });
var DDB = new AWS.DynamoDB({ apiVersion: "2012-10-08" });

exports.handler = function (event, context, callback) {
	var ddb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
	var message = JSON.parse(event.body).data;
	console.log(message);
	var a = message.split("|");
	console.log(a[0]);
	var connId = a[0].split("@")[1];
	var contactID = a[1].split("@")[1];
  if(connId.length !== 16) {
    console.log("Input validation error on connId ("+connId+") or contactID ("+contactID+")");
    const response = {
        statusCode: 502,
        body: 'Input validation error for Connection ID or Contact ID '
    };
    callback(null, response);
github legalthings / lambda-pdf-thumbnail / lambda-pdf-thumbnail.spec.js View on Github external
dynaliteServer.listen(10002, function(err){
      if (err) {
        callback(err);
        return;
      }

      var config = {
        s3ForcePathStyle: true,
        accessKeyId: 'ACCESS_KEY_ID',
        secretAccessKey: 'SECRET_ACCESS_KEY',
        region: 'us-west-1',
        endpoint: new AWS.Endpoint('http://localhost:10002')
      };

      var dynamodb = new AWS.DynamoDB(config);
      callback(null, dynamodb);
    });
  }
github rrahul963 / serverless-create-global-dynamodb-table / src / helper.js View on Github external
await Promise.all(regionsToUpdate.map(r => {
      const ddb = new AWS.DynamoDB({
        credentials: creds,
        region: r,
      });
      const aas = new AWS.ApplicationAutoScaling({
        credentials: creds,
        region: r,
      });
      return module.exports.createNewTableAndSetScalingPolicy(
        aas, ddb, createTableParams, describeScalingPoliciesResp.ScalingPolicies, tableName, r, cli
      );
    }));
  }
github vbudilov / cognito-to-dynamodb-lambda / cognitoToDDB.js View on Github external
const aws = require('aws-sdk');
const ddb = new aws.DynamoDB({apiVersion: '2012-10-08'});

/**
 * @author Vladimir Budilov
 * 
 * Upon Cognito SignUp, a user is added to the DDB table
 *
 * Cognito event:
 * https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-lambda-trigger-examples.html#aws-lambda-triggers-post-confirmation-example
 *
 * Writing to DDB:
 * https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/dynamodb-example-table-read-write.html
 *
 * Sample input:
 *
 {
    version:'1',
github rrahul963 / serverless-create-global-dynamodb-table / index.js View on Github external
const createAndTagTable = async function createAndTagTable(region, tableName, setting, tags, cli, creds) {
  cli.consoleLog(`CreateGlobalTable: ${chalk.yellow(`Creating new table ${tableName} in ${region} region...`)}`)
  const dynamodb = new AWS.DynamoDB({
    credentials: creds,
    region,
  })
  try {
    const createResp = await dynamodb.createTable(setting).promise()
    cli.consoleLog(`CreateGlobalTable: ${chalk.yellow(`Created new table ${tableName} in ${region} region...`)}`)
    const { TableArn } = createResp.TableDescription
    if (tags) {
      cli.consoleLog(`CreateGlobalTable: ${chalk.yellow(`CAdding tags to table ${tableName} in ${region} region...`)}`)
      await dynamodb.tagResource({ ResourceArn: TableArn, Tags: tags })
    }
  } catch (error) {
    if (error.code === 'ResourceInUseException') {
      cli.consoleLog(`CreateGlobalTable: ${chalk.yellow(`Table ${tableName} already exists in the region ${region}`)}`)
    }
    throw error