File tree Expand file tree Collapse file tree 3 files changed +25
-28
lines changed Expand file tree Collapse file tree 3 files changed +25
-28
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,10 @@ const Order = require("../models/orderModel");
44// const { sendToQueue } = require("../utils/sqs");
55const { v4 : uuidv4 } = require ( "uuid" ) ;
66
7- const AWS = require ( 'aws-sdk' ) ;
7+ const DynamoDBClient = require ( '@aws-sdk/client-dynamodb' ) ;
8+ const client = new DynamoDBClient ( { } ) ;
9+ const docClient = DynamoDBDocumentClient . from ( client ) ;
10+
811
912const dynamodb = new AWS . DynamoDB . DocumentClient ( ) ;
1013const ordersTable = "OrdersTable" ;
@@ -15,26 +18,16 @@ exports.handler = async (event) => {
1518
1619 console . log ( 'Environment:' , process . env ) ;
1720
18- const res = await dynamodb . get ( {
19- TableName : ordersTable ,
20- Key : { "id" : "3" }
21- } ) . promise ( ) ;
22-
23- console . log ( "res from get item:" , res ) ;
24- console . log ( "item from res: " , res . Item ) ;
25-
26- const newCount = res . Item . count + 1 ;
27-
28- const res2 = await dynamodb . put ( {
21+ const command = new PutCommand ( {
2922 TableName : ordersTable ,
3023 Item : {
31- "id" : "3" ,
32- "count" : newCount
33- }
34- } ) . promise ( ) ;
35-
36- console . log ( "res2 after update: " , res2 ) ;
24+ id : uuidv4 ( ) ,
25+ name : "test1"
26+ } ,
27+ } ) ;
3728
29+ const order = await docClient . send ( command ) ;
30+ console . log ( order ) ;
3831
3932 // await connectDB();
4033
Original file line number Diff line number Diff line change 1010 "deploy" : " sam build && sam deploy --guided"
1111 },
1212 "dependencies" : {
13+ "@aws-sdk/lib-dynamodb" : " ^3.321.1" ,
1314 "@aws-sdk/client-apigatewaymanagementapi" : " ^3.428.0" ,
1415 "@aws-sdk/client-sqs" : " ^3.428.0" ,
1516 "@aws-sdk/client-dynamodb" : " ^3.428.0" ,
Original file line number Diff line number Diff line change 1- AWSTemplateFormatVersion : ' 2010-09-09'
1+ AWSTemplateFormatVersion : " 2010-09-09"
22Transform : AWS::Serverless-2016-10-31
33
44Globals :
5-
65 Function :
76 Timeout : 10
87
98Parameters :
10-
119 HOSTINGENV :
1210 Type : String
1311 Description : " Ex: Development, Staging, Production"
1412 Default : " Production"
15-
13+
1614 # VpcId:
1715 # Type: AWS::EC2::VPC::Id
1816 # Description: "The VPC ID where resources will be created"
@@ -23,9 +21,7 @@ Parameters:
2321 # Type: List<AWS::EC2::SecurityGroup::Id>
2422 # Description: "The security group IDs within the VPC"
2523
26-
2724Resources :
28-
2925 OrderApi :
3026 Type : AWS::Serverless::Api
3127 Properties :
@@ -69,7 +65,7 @@ Resources:
6965 Path : /orders
7066 Method : post
7167 RestApiId : !Ref OrderApi
72-
68+
7369 # GetMyOrdersFunction:
7470 # Type: AWS::Serverless::Function
7571 # Properties:
@@ -102,6 +98,13 @@ Resources:
10298 # Method: post
10399 # RestApiId: !Ref OrderApi
104100
105-
106-
107-
101+ Outputs :
102+ # ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
103+ # Find out more about other implicit resources you can reference within SAM
104+ # https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
105+ HelloWorldApi :
106+ Description : " API Gateway endpoint URL for Prod stage for Create Order function"
107+ Value : !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/orders"
108+ HelloWorldFunction :
109+ Description : " Create Order Lambda Function ARN"
110+ Value : !GetAtt CreateOrderFunction.Arn
You can’t perform that action at this time.
0 commit comments