https://github.com/ibrahimcesar/middy-idempotent
π΅ π¬ βββββ ββββ ββββ βIdempotence Middy middleware for your AWS Lambdas
Science Score: 13.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
βCITATION.cff file
-
βcodemeta.json file
Found codemeta.json file -
β.zenodo.json file
-
βDOI references
-
βAcademic publication links
-
βCommitters with academic emails
-
βInstitutional organization owner
-
βJOSS paper metadata
-
βScientific vocabulary similarity
Low similarity (13.7%) to scientific vocabulary
Keywords
Repository
π΅ π¬ βββββ ββββ ββββ βIdempotence Middy middleware for your AWS Lambdas
Basic Info
- Host: GitHub
- Owner: ibrahimcesar
- License: mit
- Language: TypeScript
- Default Branch: main
- Homepage: https://www.npmjs.com/package/middy-idempotent
- Size: 1.02 MB
Statistics
- Stars: 17
- Watchers: 2
- Forks: 2
- Open Issues: 10
- Releases: 2
Topics
Metadata Files
README.md
π΅ π¬ Idempotent Middleware for Middy
An Idempotent Middy middleware for your AWS Lambdas[](https://github.com/ellerbrock/typescript-badges/) [](https://www.npmjs.com/package/middy-idempotent ) [](./LICENSE) 
Developed in π§π· Brazil
π΅ What is does
Middy 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.
Making an API idempotent is not trivial as much people think, 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, Making retries safe with idempotent APIs featured in the Amazon Builder's Library as Architecture level 300 which falls ins the advanced classification.
π Install
Use your favorite package manager:
bash
yarn add middy-idempotent
bash
npm install middy-idempotent -S
Usage
Besides @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 for free that is currently (0.0.20) the only storage supported.
ts
handler.use(jsonBodyParser()).use(
idempotent({
client: new Redis(process.env.UPSTASH_REDISS),
})
);
Just 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
Besides the client, you have th possibility to choose your own idempotency key instead of the whole event:
| Prop | Type | Description |
|----------|:--------:|------------|
| client | Instance of class Redis | instance of the class Redis provided by the lib ioredis, the only supported at the moment |
| body | boolean or string | Optional. If true uses the body sent in the request. If no body is sent, this will yield an error. |
| 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) |
| 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 |
| 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.
Note that the optional targets are mutually excludents, they obey the hierarchy body > header > 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.
TODO
- [ ] Add more storages (DynamoDB, etc)
π Read more
See Also
π΅ π reCAPTCHA Middleware for Middy: reCAPTCHA validation Middy middleware for yours AWS Lambdas
MIT License
Copyright (c) 2021 Ibrahim Cesar
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.
Owner
- Name: Ibrahim Cesar
- Login: ibrahimcesar
- Kind: user
- Location: SΓ£o Paulo
- Company: @aws
- Website: https://ibrahimcesar.cloud
- Repositories: 74
- Profile: https://github.com/ibrahimcesar
Cloud Optimization Solutions Architected @ Amazon Web Services (AWS) β Opinions are my own (He/him/his ele/dele)
GitHub Events
Total
- Watch event: 1
Last Year
- Watch event: 1
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Ibrahim Cesar | i****a@n****r | 13 |
| Ibrahim Cesar | e****l@i****m | 2 |
| GΓΆran Nehlin | g****n@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 6
- Total pull requests: 8
- Average time to close issues: about 15 hours
- Average time to close pull requests: 6 months
- Total issue authors: 1
- Total pull request authors: 2
- Average comments per issue: 0.0
- Average comments per pull request: 0.38
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 7
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- ibrahimcesar (6)
Pull Request Authors
- dependabot[bot] (7)
- Nehlin (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- npm 40 last-month
-
Total dependent packages: 3
(may contain duplicates) -
Total dependent repositories: 1
(may contain duplicates) - Total versions: 38
- Total maintainers: 1
npmjs.org: middy-idempotent
An Idempotent Middleware for Middy
- Homepage: https://github.com/ibrahimcesar/middy-idempotent
- License: MIT
-
Latest release: 0.21.0
published over 4 years ago
Rankings
Maintainers (1)
npmjs.org: @ibrahimcesar/middy-idempotent
An Idempotent Middleware for Middy
- Homepage: https://github.com/ibrahimcesar/middy-idempotent
- License: MIT
-
Latest release: 0.0.20
published almost 5 years ago
Rankings
Maintainers (1)
Dependencies
- 509 dependencies
- @rollup/plugin-commonjs ^18.0.0 development
- @rollup/plugin-json ^4.1.0 development
- @rollup/plugin-node-resolve ^11.2.1 development
- @types/aws-lambda ^8.10.72 development
- @types/ioredis ^4.26.1 development
- @types/jest ^26.0.22 development
- @types/node ^14.14.41 development
- @types/react ^17.0.3 development
- @typescript-eslint/eslint-plugin ^4.20.0 development
- @typescript-eslint/parser ^4.20.0 development
- aws-cdk ^1.89.0 development
- aws-sdk ^2.890.0 development
- babel-eslint ^10.1.0 development
- babel-loader ^8.2.2 development
- babel-preset-minify ^0.5.0 development
- css-loader ^5.2.0 development
- esbuild ^0.8.44 development
- eslint ^7.23.0 development
- ioredis ^4.27.2 development
- prettier ^2.2.1 development
- rollup-plugin-banner2 ^1.2.2 development
- rollup-plugin-copy ^3.4.0 development
- rollup-plugin-peer-deps-external ^2.2.4 development
- rollup-plugin-terser ^7.0.2 development
- rollup-plugin-typescript2 ^0.30.0 development
- ts-node ^9.1.1 development
- typescript ^3.4.3 development
- @aws-cdk/aws-apigatewayv2 1.100.0 development
- @aws-cdk/aws-apigatewayv2-integrations 1.100.0 development
- @aws-cdk/aws-lambda 1.100.0 development
- @aws-cdk/core 1.100.0 development
- @babel/cli ^7.13.14 development
- @babel/core ^7.13.14 development
- @babel/plugin-proposal-class-properties ^7.13.0 development
- @babel/plugin-transform-typescript ^7.13.0 development
- @babel/polyfill ^7.12.1 development
- @babel/preset-env ^7.13.12 development
- @babel/preset-react ^7.13.13 development
- @babel/preset-typescript ^7.13.0 development
- @middy/core ^2.0.1 development
- @middy/http-json-body-parser ^2.0.1 development
- @rollup/plugin-commonjs ^18.0.0 development
- @rollup/plugin-node-resolve ^11.2.1 development
- @types/aws-lambda ^8.10.72 development
- @types/ioredis ^4.26.1 development
- @types/jest ^26.0.22 development
- @types/node ^14.14.25 development
- @types/react ^17.0.3 development
- @typescript-eslint/eslint-plugin ^4.20.0 development
- @typescript-eslint/parser ^4.20.0 development
- aws-cdk ^1.89.0 development
- aws-sdk ^2.890.0 development
- babel-eslint ^10.1.0 development
- babel-loader ^8.2.2 development
- babel-preset-minify ^0.5.0 development
- css-loader ^5.2.0 development
- esbuild ^0.8.44 development
- eslint ^7.23.0 development
- middy-idempotent 0.0.19 development
- prettier ^2.2.1 development
- rollup-plugin-banner2 ^1.2.2 development
- rollup-plugin-copy ^3.4.0 development
- rollup-plugin-peer-deps-external ^2.2.4 development
- rollup-plugin-typescript2 ^0.30.0 development
- ts-node ^9.1.1 development
- typescript ^3.4.3 development
- ioredis ^4.27.2
- 753 dependencies