Skip to content

Instantly share code, notes, and snippets.

@jacoyutorius
Last active October 22, 2018 13:19
Show Gist options
  • Select an option

  • Save jacoyutorius/b4b57575984c49e7ef803b2f3c67d905 to your computer and use it in GitHub Desktop.

Select an option

Save jacoyutorius/b4b57575984c49e7ef803b2f3c67d905 to your computer and use it in GitHub Desktop.
AWS Lambda demo
const AWS = require('aws-sdk');
const dynamoDb = new AWS.DynamoDB.DocumentClient({
region: "ap-northeast-1"
});
// exports.handler = (event, context, callback) => {
// const data = {
// name: "yuto",
// email: "[email protected]",
// age: 34,
// city: "Hamamatsu"
// };
// const response = {
// statusCode: 200,
// body: JSON.stringify(data)
// };
// console.info(response);
// callback(null, response);
// };
// async function getData() {
// return new Promise(resolve=>{
// setTimeout(()=>{
// resolve({
// name: "Yuto",
// email: "[email protected]",
// age: 34,
// city: "Hamamatsu"
// })
// }, 1000);
// })
// }
async function getUser() {
const params = {
TableName: "Users"
};
const result = await dynamoDb.scan(params).promise();
return result.Items;
}
exports.handler = async (event, context, callback) => {
// const data = await getData();
const data = await getUser();
const response = {
statusCode: 200,
body: JSON.stringify(data)
};
console.info(response);
// callback(null, response);
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment