https://github.com/ibrahimcesar/middy-idempotent

πŸ›΅ πŸ“¬ β€Žβ€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€ŽIdempotence Middy middleware for your AWS Lambdas

https://github.com/ibrahimcesar/middy-idempotent

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

api-idempotent aws aws-lambda aws-lambda-node hacktoberfest hacktoberfest2021 idempotence-middleware idempotency lambda middy typescript
Last synced: 5 months ago · JSON representation

Repository

πŸ›΅ πŸ“¬ β€Žβ€Žβ€β€β€Ž β€Žβ€β€β€Ž β€Žβ€β€β€Ž β€ŽIdempotence Middy middleware for your AWS Lambdas

Basic Info
Statistics
  • Stars: 17
  • Watchers: 2
  • Forks: 2
  • Open Issues: 10
  • Releases: 2
Topics
api-idempotent aws aws-lambda aws-lambda-node hacktoberfest hacktoberfest2021 idempotence-middleware idempotency lambda middy typescript
Created almost 5 years ago · Last pushed almost 3 years ago
Metadata Files
Readme Funding License

README.md

πŸ›΅ πŸ“¬ Idempotent Middleware for Middy

An Idempotent Middy middleware for your AWS Lambdas
[![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/) [![Version](https://img.shields.io/npm/v/middy-idempotent?label=latest%20version)](https://www.npmjs.com/package/middy-idempotent )   [![License](https://badgen.net/github/license/ibrahimcesar/middy-idempotent)](./LICENSE)   ![GitHub issues by-label](https://img.shields.io/github/issues/ibrahimcesar/middy-idempotent/bug)

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

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

All Time
  • Total Commits: 16
  • Total Committers: 3
  • Avg Commits per committer: 5.333
  • Development Distribution Score (DDS): 0.188
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email 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
enhancement (6) documentation (2) help wanted (1) good first issue (1)
Pull Request Labels
dependencies (7) enhancement (1)

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

  • Versions: 37
  • Dependent Packages: 2
  • Dependent Repositories: 1
  • Downloads: 38 Last month
Rankings
Dependent packages count: 8.8%
Stargazers count: 9.0%
Forks count: 9.8%
Average: 10.1%
Dependent repos count: 10.3%
Downloads: 12.3%
Maintainers (1)
Last synced: 6 months ago
npmjs.org: @ibrahimcesar/middy-idempotent

An Idempotent Middleware for Middy

  • Versions: 1
  • Dependent Packages: 1
  • Dependent Repositories: 0
  • Downloads: 2 Last month
Rankings
Stargazers count: 11.5%
Forks count: 12.3%
Dependent packages count: 16.2%
Average: 21.1%
Dependent repos count: 25.3%
Downloads: 40.0%
Maintainers (1)
Last synced: 6 months ago

Dependencies

package-lock.json npm
  • 509 dependencies
package.json npm
  • @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
demo/package.json npm
  • @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
demo/package-lock.json npm
  • 753 dependencies