
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
@aws-lambda-powertools/event-handler
Advanced tools
Lightweight routing to reduce boilerplate for API Gateway REST/HTTP API, ALB and Lambda Function URLs
Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless best practices and increase developer velocity.
You can use the library in both TypeScript and JavaScript code bases.
Event handler for Amazon API Gateway REST and HTTP APIs, Application Loader Balancer (ALB), Lambda Function URLs, and VPC Lattice.
To get started, install the library by running:
npm i @aws-lambda-powertools/event-handler
Event Handler for AWS AppSync real-time events.
When using the publish event handler, you can register a handler for a specific channel or a wildcard pattern. The handler will be called once for each message received on that channel.
import { AppSyncEventsResolver } from '@aws-lambda-powertools/event-handler/appsync-events';
const app = new AppSyncEventsResolver();
app.onPublish('/default/foo', async (payload) => {
// your logic here
return payload;
});
export const handler = async (event, context) =>
app.resolve(event, context);
In some cases, you might want to process all the messages at once, for example to optimize downstream operations. In this case, you can set the aggregate
option to true
when registering the handler. This will cause the handler to be called once for all messages received on that channel.
import { AppSyncEventsResolver } from '@aws-lambda-powertools/event-handler/appsync-events';
const app = new AppSyncEventsResolver();
app.onPublish('/default/foo', async (payloads) => {
const newMessages = [];
for (const message of payloads) {
// your logic here
}
return newMessages;
}, {
aggregate: true
});
export const handler = async (event, context) =>
app.resolve(event, context);
You can also register a handler for subscribe events. This handler will be called once for each subscription request received on the specified channel. You can use this handler to perform any necessary setup or validation before allowing the subscription to proceed.
import { AppSyncEventsResolver } from '@aws-lambda-powertools/event-handler/appsync-events';
const app = new AppSyncEventsResolver();
app.onSubscribe('/default/foo', async (event) => {
// your logic here
});
export const handler = async (event, context) =>
app.resolve(event, context);
If you want to reject a subscription request, you can throw an UnauthorizedException
error. This will cause the subscription to be rejected and the client will receive an error message.
import {
AppSyncEventsResolver,
UnauthorizedException,
} from '@aws-lambda-powertools/event-handler/appsync-events';
const app = new AppSyncEventsResolver();
app.onSubscribe('/default/foo', async (event) => {
// your logic here
throw new UnauthorizedException('Unauthorized');
});
export const handler = async (event, context) =>
app.resolve(event, context);
See the documentation for more details on how to use the AppSync event handler.
If you are interested in contributing to this project, please refer to our Contributing Guidelines.
The roadmap of Powertools for AWS Lambda (TypeScript) is driven by customers’ demand.
Help us prioritize upcoming functionalities or utilities by upvoting existing RFCs and feature requests, or creating new ones, in this GitHub repository.
#typescript
- Invite linkKnowing which companies are using this library is important to help prioritize the project internally. If your company is using Powertools for AWS Lambda (TypeScript), you can request to have your name and logo added to the README file by raising a Support Powertools for AWS Lambda (TypeScript) (become a reference) issue.
The following companies, among others, use Powertools:
Share what you did with Powertools for AWS Lambda (TypeScript) 💞💞. Blog post, workshops, presentation, sample apps and others. Check out what the community has already shared about Powertools for AWS Lambda (TypeScript) here.
This helps us understand who uses Powertools for AWS Lambda (TypeScript) in a non-intrusive way, and helps us gain future investments for other Powertools for AWS Lambda languages. When using Layers, you can add Powertools as a dev dependency to not impact the development process.
This library is licensed under the MIT-0 License. See the LICENSE file.
FAQs
Lightweight routing to reduce boilerplate for API Gateway REST/HTTP API, ALB, Lambda Function URLs, and AppSync.
The npm package @aws-lambda-powertools/event-handler receives a total of 277 weekly downloads. As such, @aws-lambda-powertools/event-handler popularity was classified as not popular.
We found that @aws-lambda-powertools/event-handler demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.