Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const AWS = require('aws-sdk');
AWS.config.update({
'region': 'ap-northeast-1'
});
const dynamo = new AWS.DynamoDB.DocumentClient();
exports.handler = (event, context, callback) => {
const l = 8;
const c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
const cl = c.length;
let r = "";
for(let i=0; i<l; i++){
r += c[Math.floor(Math.random()*cl)];
}
const data = {
TableName: 'セッションID一覧テーブル',
Item: {
設定したキー: r
}
}
dynamo.put(data, function(err, data) {
let result = {result: true, session_id: r};
if(err) {
result = {result: false, error: JSON.stringify(err, null, 2)}
}
callback(null, result)
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment