I'm using serverless framework to create an application that writes and reads data from DynamoDB. I follow their official docs and look into other examples on github.
As far as I understand Serverless uses AWS SDK for NodeJS under the hood.
I noticed the DynamoDB API Difference in Serverless and official AWS SDK.
Method names. They are different: in the official AWS SDK docs for reading there's a getItem
method (link for the docs), whereas in the Serveless get
method is being used (link) everywhere.
Params definition:
In accordance to the official documentation I need to use the following convention to create params:
var params = {
Key: {
UserId: {
S: '123456'
}
},
TableName: 'Users'
};
dynamodb.getItem(params, function(err, data) {
...
})
However, Serverless shows a different approach:
const params = {
Key: {
UserId: '123456'
},
TableName: 'Users'
}
dynamoDb.get(params, (error, result) => {}
Question: Could somebody please explain the difference and why is that? It's a little bit confusing and hard to understand which convention to follow. Thanks!
After few hours of research, I found why.
All examples that are shown in Serverless docs use specific class DocumentClient
that simplifies development in javascript world by omitting DynamoDB datatypes.
Methods and parameters they accept are also different so that it's possible to send/retrieve data without specifying a datatype. However, in the end, DynamoDB still requires types, but all conversion is happening behind the scenes.