Skip to content

Instantly share code, notes, and snippets.

@clasense4
Created July 20, 2017 17:32
Show Gist options
  • Save clasense4/6df5e78223b0d829c529ed7d9abdefbf to your computer and use it in GitHub Desktop.
Save clasense4/6df5e78223b0d829c529ed7d9abdefbf to your computer and use it in GitHub Desktop.
Create DynamoDB Table from Lambda function
// Configuring the AWS SDK
var AWS = require('aws-sdk');
AWS.config.update({region: 'REGION'});
exports.handler = (event, context, callback) => {
// TODO implement
// create DynamoDB service object
var dynamodb = new AWS.DynamoDB({region: 'REGION', apiVersion: '2012-08-10'});
/* This example creates a table named Music. */
var params = {
AttributeDefinitions: [
{
AttributeName: "Artist",
AttributeType: "S"
},
{
AttributeName: "SongTitle",
AttributeType: "S"
}
],
KeySchema: [
{
AttributeName: "Artist",
KeyType: "HASH"
},
{
AttributeName: "SongTitle",
KeyType: "RANGE"
}
],
ProvisionedThroughput: {
ReadCapacityUnits: 1,
WriteCapacityUnits: 1
},
TableName: "Music"
};
dynamodb.createTable(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
callback(null, 'DynamoDB Table is created');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment