Created
July 20, 2017 17:32
-
-
Save clasense4/6df5e78223b0d829c529ed7d9abdefbf to your computer and use it in GitHub Desktop.
Create DynamoDB Table from Lambda function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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