Giter VIP home page Giter VIP logo

api-lambda-save-dynamodb's People

Contributors

simalexan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

api-lambda-save-dynamodb's Issues

Help request - {"message":"Missing Authentication Token"}

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.

Idempotency bug 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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.