Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 46 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const handler = async (event: APIGatewayProxyEvent) => {
- **📝 Structured Logging** – Pino logger pre-configured for Lambda with automatic AWS request context enrichment
- **📤 API Response Helpers** – Standard response formatting for API Gateway with proper HTTP status codes
- **⚙️ Configuration Validation** – Environment variable validation with Zod schema support
- **🔌 AWS SDK Clients** – Pre-configured AWS SDK v3 clients including DynamoDB, SNS, and Lambda with singleton patterns
- **🔌 AWS SDK Clients** – Pre-configured AWS SDK v3 clients including DynamoDB, Lambda, SNS, and SQS with singleton patterns
- **🔒 Full TypeScript Support** – Complete type definitions and IDE autocomplete
- **⚡ Lambda Optimized** – Designed for performance in serverless environments

Expand All @@ -108,8 +108,9 @@ Comprehensive guides and examples are available in the `docs` directory:
| **[Logging Guide](./docs/LOGGING.md)** | Configure and use structured logging with automatic AWS Lambda context |
| **[API Gateway Responses](./docs/API_GATEWAY_RESPONSES.md)** | Format responses for API Gateway with standard HTTP patterns |
| **[DynamoDB Client](./docs/DYNAMODB_CLIENT.md)** | Use pre-configured DynamoDB clients with singleton pattern |
| **[SNS Client](./docs/SNS_CLIENT.md)** | Publish messages to SNS topics with message attributes |
| **[Lambda Client](./docs/LAMBDA_CLIENT.md)** | Invoke other Lambda functions synchronously or asynchronously |
| **[SNS Client](./docs/SNS_CLIENT.md)** | Publish messages to SNS topics with message attributes |
| **[SQS Client](./docs/SQS_CLIENT.md)** | Send messages to SQS queues with message attributes |

## Usage

Expand Down Expand Up @@ -197,6 +198,32 @@ export const handler = async (event: any, context: any) => {

**→ See [DynamoDB Client Guide](./docs/DYNAMODB_CLIENT.md) for detailed configuration and examples**

#### Lambda Client

Invoke other Lambda functions synchronously or asynchronously:

```typescript
import { invokeLambdaSync, invokeLambdaAsync } from '@leanstacks/lambda-utils';

export const handler = async (event: any) => {
// Synchronous invocation - wait for response
const response = await invokeLambdaSync('my-function-name', {
key: 'value',
data: { nested: true },
});

// Asynchronous invocation - fire and forget
await invokeLambdaAsync('my-async-function', {
eventType: 'process',
data: [1, 2, 3],
});

return { statusCode: 200, body: JSON.stringify(response) };
};
```

**→ See [Lambda Client Guide](./docs/LAMBDA_CLIENT.md) for detailed configuration and examples**

#### SNS Client

Publish messages to SNS topics with optional message attributes:
Expand Down Expand Up @@ -224,35 +251,36 @@ export const handler = async (event: any) => {

**→ See [SNS Client Guide](./docs/SNS_CLIENT.md) for detailed configuration and examples**

#### Lambda Client
#### SQS Client

Invoke other Lambda functions synchronously or asynchronously:
Send messages to SQS queues with optional message attributes:

```typescript
import { invokeLambdaSync, invokeLambdaAsync } from '@leanstacks/lambda-utils';
import { sendToQueue, SQSMessageAttributes } from '@leanstacks/lambda-utils';

export const handler = async (event: any) => {
// Synchronous invocation - wait for response
const response = await invokeLambdaSync('my-function-name', {
key: 'value',
data: { nested: true },
});
const attributes: SQSMessageAttributes = {
priority: {
DataType: 'String',
StringValue: 'high',
},
};

// Asynchronous invocation - fire and forget
await invokeLambdaAsync('my-async-function', {
eventType: 'process',
data: [1, 2, 3],
});
const messageId = await sendToQueue(
'https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue',
{ orderId: '12345', status: 'completed' },
attributes,
);

return { statusCode: 200, body: JSON.stringify(response) };
return { statusCode: 200, body: JSON.stringify({ messageId }) };
};
```

**→ See [Lambda Client Guide](./docs/LAMBDA_CLIENT.md) for detailed configuration and examples**
**→ See [SQS Client Guide](./docs/SQS_CLIENT.md) for detailed configuration and examples**

## Examples

Example Lambda functions using Lambda Utilities are available in the repository:
To see an example Lambda microservice using the Lambda Utilities, see the LeanStacks [`lambda-starter`](https://github.com/leanstacks/lambda-starter) :octocat: GitHub repository.

- API Gateway with logging and response formatting
- Configuration validation and DynamoDB integration
Expand Down
5 changes: 3 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ Lambda Utilities is a collection of pre-configured tools and helpers designed to
- **[Logging Guide](./LOGGING.md)** – Implement structured logging in your Lambda functions with Pino and automatic AWS context enrichment
- **[API Gateway Responses](./API_GATEWAY_RESPONSES.md)** – Format Lambda responses for API Gateway with standard HTTP status codes and headers
- **[DynamoDB Client](./DYNAMODB_CLIENT.md)** – Reusable singleton DynamoDB client instances with custom configuration
- **[SNS Client](./SNS_CLIENT.md)** – Reusable singleton SNS client for publishing messages to topics with message attributes
- **[Lambda Client](./LAMBDA_CLIENT.md)** – Reusable singleton Lambda client for invoking other Lambda functions
- **[SNS Client](./SNS_CLIENT.md)** – Reusable singleton SNS client for publishing messages to topics with message attributes
- **[SQS Client](./SQS_CLIENT.md)** – Reusable singleton SQS client for sending messages to queues with message attributes

## Features

- 📝 **Structured Logging** – Pino logger pre-configured for Lambda with automatic request context
- 📤 **API Response Helpers** – Standard response formatting for API Gateway integration
- ⚙️ **Configuration Validation** – Environment variable validation with Zod schema support
- 🔌 **AWS Clients** – Pre-configured AWS SDK v3 clients for DynamoDB, SNS, and Lambda
- 🔌 **AWS Clients** – Pre-configured AWS SDK v3 clients for DynamoDB, SNS, SQS, and Lambda
- 🔒 **Type Safe** – Full TypeScript support with comprehensive type definitions

## Support
Expand Down
Loading