33
44const randomBytes = require ( 'crypto' ) . randomBytes ;
55
6- const AWS = require ( 'aws-sdk' ) ;
6+ const { DynamoDBClient } = require ( '@aws-sdk/client-dynamodb' ) ;
7+ const { DynamoDBDocumentClient, PutCommand } = require ( '@aws-sdk/lib-dynamodb' ) ;
78
8- const ddb = new AWS . DynamoDB . DocumentClient ( ) ;
9+ const client = new DynamoDBClient ( { } ) ;
10+ const ddb = DynamoDBDocumentClient . from ( client ) ;
911
1012exports . handler = ( event , context , callback ) => {
1113
@@ -46,7 +48,7 @@ exports.handler = (event, context, callback) => {
4648} ;
4749
4850function recordObject ( message ) {
49- return ddb . put ( {
51+ const command = new PutCommand ( {
5052 TableName : process . env . DatabaseTable ,
5153 Item : {
5254 Name : message . name ,
@@ -56,7 +58,8 @@ function recordObject(message) {
5658 Address : message . address ,
5759 RequestTime : new Date ( ) . toISOString ( ) ,
5860 } ,
59- } ) . promise ( ) ;
61+ } ) ;
62+ return ddb . send ( command ) ;
6063}
6164
6265function toUrlString ( buffer ) {
@@ -77,4 +80,4 @@ function errorResponse(errorMessage, awsRequestId, callback) {
7780 'Access-Control-Allow-Origin' : '*' ,
7881 } ,
7982 } ) ;
80- }
83+ }
0 commit comments