npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

middy-idempotency

v0.1.0

Published

Idempotency Middleware for AWS Lambda Functions using Middy

Downloads

33

Readme

Version   License: MIT   GitHub issues by-label

In programming, idempotency refers to the capacity of an application or component to identify repeated events and prevent duplicated, inconsistent, or lost data. Making your AWS Lambda function idempotent requires designing your function logic to treat duplicated events correctly.

Idempotent function logic can help to reduce the following issues:

  • Unnecessary API calls
  • Code processing time
  • Data inconsistency
  • Throttles
  • Latency

Middy is a middleware framework that allows you to simplify your AWS Lambda code when using Node.js. This middleware aims to replicate the AWS Lambda Powertools idempotency utility built in Python.

Other sources to learn about idempotency:

Other idempotency projects for Middy:

Install

To install this middleware you can use NPM:

npm install --save middy-idempotency

Requires @middy/core >= 2.0.0

Usage

middy-idempotency requires a persistence store to save the current status of an AWS Lambda execution. Currently, only DynamoDB is supported as a persistence store.

const middy = require('@middy/core')
const idempotency = require('middy-idempotency')

const DynamoDbPersistenceLayer = require('middy-idempotency/persistence/dynamodb')

const processEvent = async (event, context) => {
  return {
    statusCode: 200,
    body: JSON.stringify({
      message: 'hello world',
    }),
  }
}

const dynamodb = new DynamoDbPersistenceLayer({
  tableName: 'myIdempotencyTable',
})

const lambdaHandler = middy(processEvent).use(idempotency({ PersistenceStore: dynamodb }))

module.exports = { lambdaHandler }

TODO

  • [ ] Improve documentation
  • [ ] Add in-memory cache
  • [ ] Add payload validation
  • [ ] Add more advanced customization
  • [ ] Add other persistence stores (i.e. Redis)
  • [ ] Convert to TypeScript for type checking

Contributing

Feel free to fork and make a PR for any enhancements or new features!

MIT License

Copyright (c) 2021 Ryan Toler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.