Skip to content

Commit 16b3ec0

Browse files
committed
cloudfront-apigw-rest-api-lambda-dynamodb-sam: Update SDK to v3 for nodejs22.x runtime
1 parent dd2494d commit 16b3ec0

File tree

1 file changed

+8
-5
lines changed
  • cloudfront-apigw-rest-api-lambda-dynamodb-sam/src

1 file changed

+8
-5
lines changed

cloudfront-apigw-rest-api-lambda-dynamodb-sam/src/function.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44
const 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

1012
exports.handler = (event, context, callback) => {
1113

@@ -46,7 +48,7 @@ exports.handler = (event, context, callback) => {
4648
};
4749

4850
function 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

6265
function toUrlString(buffer) {
@@ -77,4 +80,4 @@ function errorResponse(errorMessage, awsRequestId, callback) {
7780
'Access-Control-Allow-Origin': '*',
7881
},
7982
});
80-
}
83+
}

0 commit comments

Comments
 (0)