Last active
October 22, 2018 13:19
-
-
Save jacoyutorius/b4b57575984c49e7ef803b2f3c67d905 to your computer and use it in GitHub Desktop.
AWS Lambda demo
This file contains hidden or 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 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