Last active
October 15, 2018 21:59
-
-
Save CiscoKidxx/dfeba5c082a76a4c5890155aa369be0d to your computer and use it in GitHub Desktop.
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"); | |
const Connect = require("aws-sdk/clients/connect"); | |
AWS.config.setPromisesDependency(require("bluebird")); | |
module.exports.handler = async (event, context, callback) => { | |
AWS.config.update({ | |
accessKeyId: "g354yh76y54hrhj", | |
secretAccessKey: "dqwfwergfergerthetrhrtgrfw", | |
region: "us-east-1" | |
}); | |
const connect = new AWS.Connect(); | |
const params = { | |
listUsers: { | |
InstanceId: event.arguments.InstanceId | |
} | |
}; | |
switch (event.field) { | |
case "listUsers": | |
console.log("LIST USERS CASE MATCHED"); | |
const userList = await connect.listUsers(params.listUsers).promise(); | |
const userDetailList = Promise.all( | |
userList.UserSummaryList.map(user => { | |
return connect | |
.describeUser({ | |
InstanceId: event.arguments.InstanceId, | |
UserId: user.Id | |
}) | |
.promise(); | |
}) | |
); | |
return userDetailList | |
.then(res => { | |
const structuredRes = res.map(user => JSON.stringify(user.User)); | |
console.log(JSON.stringify(structuredRes)); | |
return callback(null, structuredRes); | |
}) | |
.catch(err => callback(err, null)); | |
break; | |
default: | |
callback("Unknown field, unable to resolve" + field, null); | |
break; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment