simalexan / api-lambda-save-dynamodb Goto Github PK
View Code? Open in Web Editor NEWDeploy instantly on Serverless Application Repository
Deploy instantly on Serverless Application Repository
After the 1 click deploy from the serverless repo I get stuck.
I'm trying to use this but not sure what to put into the url or curl command to to make the API call.
When I call https://${SaveApi}.execute-api.${AWS::Region}.amazonaws.com/prod/save I get an unauthorized error. What query parameters should be used? Does something need to get passed in the header like an API key? Also, any hint at what a curl command may look like would be appreciated.
I will create an updated readme.md make a pull request once I get this is sorted. Thank you.
correct me if I'm wrong but isn't the package.json supposed to contain aws-sdk and uuid? since they are used in index.js
The function in index.js is not idempotent and may insert multiple duplicate records into database.
item[PRIMARY_KEY] = uuidv4();
const params = {
TableName: TABLE_NAME,
Item: item
}
try {
await dynamoDb.put(params).promise()
return processResponse(IS_CORS);
}
When the function fails after executing dynamoDb.put(params).promise()
because runtime error or other reasons, AWS Lambda will retry the function. Then uuidv4()
will return another different id and dynamoDb.put(params).promise()
will be executed again, which creates another new record in database.
This can be fixed by making the function idempotent. First, the primary key should be provided by users as a parameter. This can avoid generating a different new primary key on retry. Second, before executing dynamoDb.put(params).promise()
, the function should check whether the record with the same primary key have been in the database. If so, that means the current execution is a retry and the function should not write the database again.
Please let me know if I've missed something or if my understanding of the code is incorrect. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.