-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamo.js
45 lines (37 loc) · 1.23 KB
/
dynamo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
'use strict';
// aws-sdk를 불러옵니다.
const AWS = require('aws-sdk');
// dynamodb 초기화합니다.
const dynamodb = new AWS.DynamoDB.DocumentClient();
exports.handler = async (event) => {
// 리턴할 값을 선언합니다.
let response;
// queryStringParameters즉 GET값들이 들어오는지 들어온다면 id가 있는지 체크합니다.
if (!event.queryStringParameters || !event.queryStringParameters.id) {
response = {
statusCode: 400,
body: JSON.stringify("id가 없습니다.")
};
return response;
} else {
let params = {
Item: {
id: event.queryStringParameters.id,
data: event.queryStringParameters
},
TableName: "dynamo_apigateway_query"
};
await dynamodb.put(params).promise().catch(error => {
response = {
statusCode: 500,
body: JSON.stringify("에러가 발생하였습니다.", error)
};
return response;
})
response = {
statusCode: 200,
body: JSON.stringify("데이터가 성공적으로 저장되었습니다.")
};
return response;
}
};