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
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