1
- const AWS = require ( "aws-sdk" ) ;
1
+ const { DynamoDBClient , PutItemCommand , GetItemCommand } = require ( "@ aws-sdk/client-dynamodb " ) ;
2
2
const express = require ( "express" ) ;
3
3
const serverless = require ( "serverless-http" ) ;
4
4
5
5
const app = express ( ) ;
6
6
7
7
const USERS_TABLE = process . env . USERS_TABLE ;
8
- const dynamoDbClient = new AWS . DynamoDB . DocumentClient ( ) ;
9
8
10
9
app . use ( express . json ( ) ) ;
11
10
@@ -18,7 +17,8 @@ app.get("/users/:userId", async function (req, res) {
18
17
} ;
19
18
20
19
try {
21
- const { Item } = await dynamoDbClient . get ( params ) . promise ( ) ;
20
+ const command = new GetItemCommand ( params ) ;
21
+ const { Item } = await client . send ( command ) ;
22
22
if ( Item ) {
23
23
const { userId, name } = Item ;
24
24
res . json ( { userId, name } ) ;
@@ -50,7 +50,8 @@ app.post("/users", async function (req, res) {
50
50
} ;
51
51
52
52
try {
53
- await dynamoDbClient . put ( params ) . promise ( ) ;
53
+ const command = new PutItemCommand ( input ) ;
54
+ await client . send ( command ) ;
54
55
res . json ( { userId, name } ) ;
55
56
} catch ( error ) {
56
57
console . log ( error ) ;
@@ -64,5 +65,4 @@ app.use((req, res, next) => {
64
65
} ) ;
65
66
} ) ;
66
67
67
-
68
- module . exports . handler = serverless ( app ) ;
68
+ exports . handler = serverless ( app ) ;
0 commit comments