Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@aws-sdk/middleware-stack

Package Overview
Dependencies
Maintainers
6
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aws-sdk/middleware-stack

Provides a means for composing multiple middleware functions into a single handler

  • 3.54.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3M
increased by0.46%
Maintainers
6
Weekly downloads
 
Created

What is @aws-sdk/middleware-stack?

@aws-sdk/middleware-stack is a package that provides a mechanism to compose middleware in the AWS SDK for JavaScript. It allows developers to add, remove, and modify middleware in the request/response lifecycle, enabling custom logic to be executed at various stages of the request processing.

What are @aws-sdk/middleware-stack's main functionalities?

Adding Middleware

This feature allows you to add custom middleware to the middleware stack. The middleware can perform actions before and after the request is processed.

const { MiddlewareStack } = require('@aws-sdk/middleware-stack');

const stack = new MiddlewareStack();

const myMiddleware = (next, context) => async (args) => {
  console.log('Before request');
  const result = await next(args);
  console.log('After request');
  return result;
};

stack.add(myMiddleware, {
  step: 'initialize',
  name: 'myMiddleware',
  priority: 'high'
});

// Use the stack in a client
const client = new SomeAWSClient({ middlewareStack: stack });

Removing Middleware

This feature allows you to remove middleware from the middleware stack by specifying its name.

const { MiddlewareStack } = require('@aws-sdk/middleware-stack');

const stack = new MiddlewareStack();

const myMiddleware = (next, context) => async (args) => {
  console.log('Before request');
  const result = await next(args);
  console.log('After request');
  return result;
};

stack.add(myMiddleware, {
  step: 'initialize',
  name: 'myMiddleware',
  priority: 'high'
});

// Remove the middleware
stack.remove('myMiddleware');

Modifying Middleware

This feature allows you to modify existing middleware in the middleware stack by adding a new middleware with the same name and step.

const { MiddlewareStack } = require('@aws-sdk/middleware-stack');

const stack = new MiddlewareStack();

const myMiddleware = (next, context) => async (args) => {
  console.log('Before request');
  const result = await next(args);
  console.log('After request');
  return result;
};

stack.add(myMiddleware, {
  step: 'initialize',
  name: 'myMiddleware',
  priority: 'high'
});

// Modify the middleware
stack.add((next, context) => async (args) => {
  console.log('Modified middleware');
  return next(args);
}, {
  step: 'initialize',
  name: 'myMiddleware',
  priority: 'high'
});

Other packages similar to @aws-sdk/middleware-stack

FAQs

Package last updated on 11 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc