pmmarq
10/4/2017 - 2:26 PM

create-and-tag-dynamo-table-spec

const chai = require('chai')
const should = chai.should()
const _ = require('underscore')
const {survey,surveyResponse,contacts} = require('./table_schemas')
/* Needs creds to work and Uses the default credentials for running the script */
const AWS = require('aws-sdk')
const dynamodb = new AWS.DynamoDB({region:'us-east-1'})

describe('sets up a new table', function () {
  const tags = {
    "Tags": [
        {
            "Value": "non-prod",
            "Key": "mon:env"
        },
        {
            "Value": "pmmarq/rrseka",
            "Key": "mon:owner"
        },
        {
            "Value": "internal",
            "Key": "mon:data-classification"
        },
        {
            "Value": "<bb>",
            "Key": "mon:cost-center"
        },
        {
            "Value": "no",
            "Key": "mon:regulated"
        },
        {
            "Value": "program-pulse-survey",
            "Key": "mon:project"
        }
    ]
}
  console.error('Creating table and tags for',surveyResponse.TableName)  
  xit('creates a table', (done) => {
      const params = surveyResponse
      const created = dynamodb.createTable(params).promise()
      created.then((res) => {
        console.log('Created', res)
        done()
      }).catch((err) => {
        console.error('Error',err)
        done()
      })
  })

  xit('adds tag to the table previously created', (done) => {
    const tableName = contacts
    var params = {
        ResourceArn: `arn:aws:dynamodb:us-east-1:285453578300:table/${surveyResponse.TableName}`   
    }
    const created = dynamodb.tagResource(_.extend(params,tags)).promise()
    created.then((res) => {
        console.log('Created', res)
        done()
      }).catch((err) => {
        console.error('Error',err)
        done()
      })
  })
})