AWS Lambda + API Gateway + DynamoDB + node.js 사용기 (삽질기)
yumenohosi
174

좋은 내용감사합니다.

그대로 따라했는데 ‘body’: JSON.stringify(data) 이부분에서

테이블 정보를 못가져와서 null만 나오는데 혹시 어디 확인해야될지

조언 부탁드립니다.

‘use strict’;

console.log(‘Loading function’);

const doc = require(‘dynamodb-doc’);

const dynamo = new doc.DynamoDB();

/**
 * Provide an event that contains the following keys:
 *
 * — operation: one of the operations in the switch statement below
 * — tableName: required for operations that interact with DynamoDB
 * — payload: a parameter to pass to the operation being performed
 */
exports.handler = (event, context, callback) => {
 //console.log(‘Received event:’, JSON.stringify(event, null, 2));

const operation = event.httpMethod;
 const payload = {
 TableName: ‘test’
 }

switch (operation) {
 case ‘GET’:
 dynamo.scan(payload, (err, data) => {
 callback(null, {
 ‘statusCode’: 200,
 ‘headers’: {},
 ‘body’: JSON.stringify(data)
 });
 });
 break;
 default:
 callback(new Error(`Unrecognized operation “${operation}”`));
 }
};

Show your support

Clapping shows how much you appreciated 배두병’s story.