Skip to content

Instantly share code, notes, and snippets.

@bharat-tiwari
Last active December 24, 2018 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bharat-tiwari/16c72b57a26a6c18939d1b1dbf546ff1 to your computer and use it in GitHub Desktop.
Save bharat-tiwari/16c72b57a26a6c18939d1b1dbf546ff1 to your computer and use it in GitHub Desktop.
noteWordy API - Lambda function to update a word
import { APP_CONSTANTS } from '../../config/app_constants';
import getResponse from '../../utils/responseUtils';
import * as AWS from "aws-sdk";
const dynamoDb = new AWS.DynamoDB.DocumentClient({
'region': 'us-east-1'
});
export async function main(event , context, callback){
const requestData = JSON.parse(event.body);
const params = {
TableName: APP_CONSTANTS.WORDS_TABLE,
Key: {
wordId: event.pathParameters.id,
userId: event.requestContext.identity.cognitoIdentityId
},
UpdateExpression: 'set word = :word, meaning = :meaning, example = :example, comments = :comments',
ExpressionAttributeValues: {
':word': requestData.word || null,
':meaning': requestData.meaning || null,
':example': requestData.example || null,
':comments': requestData.comments || null
}
};
try {
const result = await dynamoDb.update(params).promise();
const response = getResponse(200, {result} );
callback(null, response);
} catch (error) {
const errResponse = getResponse(500, {status: false});
callback(errResponse, null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment