Overview of Middy.js Pollers
{ source, poll, acknowledge }, which is used to integrate external event sources into a processing loop.website·Indexed 30 days ago
https://middy.js.org/A simple middleware engine for Node.js that simplifies AWS Lambda development by decorating main business logic. It provides tools for bundling Lambda packages, connection reuse, internal context management, and profiling, with specific support for API Gateway (HTTP and REST), Alexa Skills Kit, and various middleware such as @middy/http-router and @middy/http-header-normalizer.
{ source, poll, acknowledge }, which is used to integrate external event sources into a processing loop.The event-batch-parser middleware is a unified body-parser for Lambda batch event sources. It iterates through records from supported sources, performs base64-decoding, optionally strips AWS Glue Schema Registry framing (including decompression), and applies a specified parser (such as JSON, Avro, or Protobuf).
Supported event sources and their mapped fields:
aws:kafka or SelfManagedKafka): Configurable per-field for key and/or value.aws:kinesis): Maps data to record.kinesis.data.aws:lambda:events): Maps data to record.data.aws:sqs): Maps body to record.body.aws:amq): Maps data to message.data.aws:rmq): Maps data to message.data.Constraint: For non-Kafka sources, you must use the specific field (body or data) that matches the underlying record field. Using the incorrect field will result in a TypeError during startup.
The @middy/ecs-batch package is a runtime wrapper (not middleware) that enables a Middy handler designed for Lambda batch event source mappings to run on AWS ECS/Fargate. It supports polling from SQS, Kinesis, DynamoDB Streams, Kafka (MSK/Self-Managed), ActiveMQ, and RabbitMQ.
The runner mimics Lambda's behavior by pulling records, constructing the standard batch event shape, and invoking the handler with (event, context). It uses the handler's return value ({ batchItemFailures: [...] }) to perform native acknowledgments (e.g., DeleteMessageBatch for SQS or channel.ack for RabbitMQ). For stream sources like Kinesis and DynamoDB Streams, the iterator advances implicitly, and the handler is responsible for checkpointing.
rds-signer middleware to fetch RDS credentials when connecting via IAM roles. This replaces the functionality previously built into the deprecated db-manager middleware.Adopting Middy.js has minimal impact on Lambda performance and developer experience due to the following characteristics:
@middy/core has no dependencies other than @middy/util. Middlewares are opt-in and support tree-shaking..use(). To minimize this, tree-shake aggressively and exclude the AWS SDK from the bundle..use() is used to register middleware with optional before, after, and onError hooks. The handler maintains the standard AWS Lambda signature.dynamodb middleware for Middy.js allows you to fetch configuration values stored in DynamoDB and automatically unmarshal DynamoDB AttributeValues into native JavaScript values, making them easily accessible within your Lambda function.s3 middleware for Middy.js allows a Lambda function to fetch configuration stored in an Amazon S3 bucket and automatically parse it as JSON. This is typically used to manage dynamic configuration without redeploying the Lambda function.