{"id":20683998,"url":"https://github.com/ibrahimcesar/middy-idempotent","last_synced_at":"2025-07-24T09:34:23.758Z","repository":{"id":42653143,"uuid":"365044911","full_name":"ibrahimcesar/middy-idempotent","owner":"ibrahimcesar","description":"🛵 📬  ‎‎‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎Idempotence Middy middleware for your AWS Lambdas","archived":false,"fork":false,"pushed_at":"2023-03-14T15:53:38.000Z","size":1070,"stargazers_count":16,"open_issues_count":10,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-10T00:48:52.298Z","etag":null,"topics":["api-idempotent","aws","aws-lambda","aws-lambda-node","hacktoberfest","hacktoberfest2021","idempotence-middleware","idempotency","lambda","middy","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/middy-idempotent","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ibrahimcesar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["ibrahimcesar"]}},"created_at":"2021-05-06T21:46:49.000Z","updated_at":"2024-10-04T02:36:48.000Z","dependencies_parsed_at":"2024-11-16T22:18:44.740Z","dependency_job_id":"b305ba3a-1ae2-4b37-8859-5036c374970f","html_url":"https://github.com/ibrahimcesar/middy-idempotent","commit_stats":{"total_commits":16,"total_committers":3,"mean_commits":5.333333333333333,"dds":0.1875,"last_synced_commit":"8f2ab69690bf015957ba97b68f5037a1b5cdd93a"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ibrahimcesar/middy-idempotent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Fmiddy-idempotent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Fmiddy-idempotent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Fmiddy-idempotent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Fmiddy-idempotent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibrahimcesar","download_url":"https://codeload.github.com/ibrahimcesar/middy-idempotent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Fmiddy-idempotent/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266822001,"owners_count":23989821,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-idempotent","aws","aws-lambda","aws-lambda-node","hacktoberfest","hacktoberfest2021","idempotence-middleware","idempotency","lambda","middy","typescript"],"created_at":"2024-11-16T22:18:36.238Z","updated_at":"2025-07-24T09:34:22.354Z","avatar_url":"https://github.com/ibrahimcesar.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ibrahimcesar"],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n \n  \u003ch1\u003e🛵 📬  Idempotent Middleware for Middy\u003c/h1\u003e\n  \u003cblockquote\u003eAn Idempotent Middy middleware for your AWS Lambdas\u003c/blockquote\u003e\n\n  [![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/)\n\n  [![Version](https://img.shields.io/npm/v/middy-idempotent?label=latest%20version)](https://www.npmjs.com/package/middy-idempotent\n)\u0026nbsp; \u0026nbsp;[![License](https://badgen.net/github/license/ibrahimcesar/middy-idempotent)](./LICENSE)\u0026nbsp; \u0026nbsp;![GitHub issues by-label](https://img.shields.io/github/issues/ibrahimcesar/middy-idempotent/bug)\n \n\n\u003cp\u003eDeveloped in 🇧🇷 \u003cspan role=\"img\" aria-label=\"Flag for Brazil\"\u003eBrazil\u003c/p\u003e\n\n\u003c/div\u003e\n\n## 🛵 What is does\n\n[Middy](https://middy.js.org/) is a very simple middleware engine that allows you to simplify your AWS Lambda code when using Node.js. This middleware aims to simplify the implementations of a idempotent API.\n\nMaking an API idempotent is [not trivial as much people think](https://awslabs.github.io/aws-lambda-powertools-python/develop/utilities/idempotency/), and you could take a look at _Lambda Powertools for Python_ from AWS that does a great job to explain this use case and a concrete way to implement. There's also this great article from [Malcolm Featonby](https://twitter.com/mfeatonby), [Making retries safe with idempotent APIs](https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/) featured in the Amazon Builder's Library as [Architecture level 300](https://aws.amazon.com/blogs/architecture/category/learning-levels/advanced-300/) which falls ins the _advanced_ classification.\n\n## 🚀 Install\n\nUse your favorite package manager:\n\n```bash\nyarn add middy-idempotent\n```\n\n```bash\nnpm install middy-idempotent -S\n```\n\n## Usage\n\nBesides `@middy/core`, you must also use `@middy/http-json-body-parser` since this middleware will read the request body and needed parsed as json. And right now I only tested twith the client provided by the `ioredis` lib as well, so you'll need to install it too. At tthe bottom there's a write-up where we'll find how to use a Serverless Database service called [Upstash](https://upstash.com/) for free that is currently (`0.0.20`) the only storage supported.\n\n```ts\nhandler.use(jsonBodyParser()).use(\n  idempotent({\n    client: new Redis(process.env.UPSTASH_REDISS),\n  })\n);\n```\n\nJust place in your code, as soon as possible, passing the Redis client constructor with your `rediss://` url. See `demo` for an example of application with infrastructure provisioned in AWS CD\nBesides the client, you have th possibility to choose your own idempotency key instead of the whole `event`:\n\n| Prop   |      Type      |  Description |\n|----------|:--------:|------------|\n| **client** |  Instance of class Redis | instance of the class Redis provided by the lib [`ioredis`](https://github.com/luin/ioredis), the only supported at the moment |\n| body |    boolean or string   | Optional. If `true` uses the body sent in the request. If no body is sent, this will yield an error.  |\n| header | string | Optional. If you pass any value, will try to get this value as a key header in your request (i.e, `x-forwarded-for` and `x-idempotency-key`) |\n| path | String. One of \"rawPath\" or \"rawQueryString\" | Optional. If you want to target a very specific (and possibly dynamic) path or raw query string in the request |\n| ttl | number | Optional. Redis keys live forever by default, so being able to set a time to live is useful to avoid running out of memory in your Redis instance, as this will cause your lambdas to fail. Time unit: _seconds_.\n\nNote that the optional targets are mutually excludents, they obey the hierarchy `body` \u003e `header` \u003e `path` meaning if you pass all of them, it will pick `body` and if that is not provided `header` is picked. The default behaviour is use all the event object as idempotency key.\n\n### TODO\n- [ ] Add more storages (DynamoDB, etc)\n\n## 📚 Read more\n\n- [Redis: Exploring Redis as Serverless Database to solve idempotence in APIs](https://dev.to/aws-builders/redis-exploring-redis-as-serverless-database-to-solve-idempotence-in-apis-2gma)\n\n## See Also\n\n[🛵 🔐  reCAPTCHA Middleware for Middy](https://github.com/ibrahimcesar/react-lite-youtube-embed/): reCAPTCHA validation Middy middleware for yours AWS Lambdas\n\n\n## MIT License\n\nCopyright (c) 2021 Ibrahim Cesar\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibrahimcesar%2Fmiddy-idempotent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibrahimcesar%2Fmiddy-idempotent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibrahimcesar%2Fmiddy-idempotent/lists"}