Skip to content

Commit ce528e6

Browse files
authored
SNS client wrapper (#15)
* feat: update package version to 0.4.0-alpha.1 and add SNS client utilities - Updated version in package.json to 0.4.0-alpha.1 - Upgraded @typescript-eslint packages to 8.50.1 - Added aws-sdk-client-mock as a dev dependency - Updated AWS SDK dependencies to version 3.957.0 - Introduced sns-client.ts with functions to initialize, get, reset SNS client and publish messages - Added tests for SNS client functionalities in sns-client.test.ts - Exported SNS client utilities from index.ts * feat: add SNS client utilities and update documentation
1 parent a6580f7 commit ce528e6

File tree

8 files changed

+1224
-241
lines changed

8 files changed

+1224
-241
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const handler = async (event: APIGatewayProxyEvent) => {
9494
- **📝 Structured Logging** – Pino logger pre-configured for Lambda with automatic AWS request context enrichment
9595
- **📤 API Response Helpers** – Standard response formatting for API Gateway with proper HTTP status codes
9696
- **⚙️ Configuration Validation** – Environment variable validation with Zod schema support
97-
- **🔌 AWS SDK Clients** – Pre-configured AWS SDK v3 clients including DynamoDB with document client support
97+
- **🔌 AWS SDK Clients** – Pre-configured AWS SDK v3 clients including DynamoDB and SNS with singleton patterns
9898
- **🔒 Full TypeScript Support** – Complete type definitions and IDE autocomplete
9999
- **⚡ Lambda Optimized** – Designed for performance in serverless environments
100100

@@ -107,7 +107,8 @@ Comprehensive guides and examples are available in the `docs` directory:
107107
| **[Configuration Guide](./docs/CONFIGURATION.md)** | Validate environment variables with Zod schemas and type safety |
108108
| **[Logging Guide](./docs/LOGGING.md)** | Configure and use structured logging with automatic AWS Lambda context |
109109
| **[API Gateway Responses](./docs/API_GATEWAY_RESPONSES.md)** | Format responses for API Gateway with standard HTTP patterns |
110-
| **[DynamoDB Client](./docs/DYNAMODB_CLIENT.md)** | Use pre-configured AWS SDK v3 clients in your handlers |
110+
| **[DynamoDB Client](./docs/DYNAMODB_CLIENT.md)** | Use pre-configured DynamoDB clients with singleton pattern |
111+
| **[SNS Client](./docs/SNS_CLIENT.md)** | Publish messages to SNS topics with message attributes |
111112

112113
## Usage
113114

@@ -195,6 +196,33 @@ export const handler = async (event: any, context: any) => {
195196

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

199+
#### SNS Client
200+
201+
Publish messages to SNS topics with optional message attributes:
202+
203+
```typescript
204+
import { publishToTopic, SNSMessageAttributes } from '@leanstacks/lambda-utils';
205+
206+
export const handler = async (event: any) => {
207+
const attributes: SNSMessageAttributes = {
208+
priority: {
209+
DataType: 'String',
210+
StringValue: 'high',
211+
},
212+
};
213+
214+
const messageId = await publishToTopic(
215+
'arn:aws:sns:us-east-1:123456789012:MyTopic',
216+
{ orderId: '12345', status: 'completed' },
217+
attributes,
218+
);
219+
220+
return { statusCode: 200, body: JSON.stringify({ messageId }) };
221+
};
222+
```
223+
224+
**→ See [SNS Client Guide](./docs/SNS_CLIENT.md) for detailed configuration and examples**
225+
198226
Additional AWS Clients are coming soon.
199227

200228
## Examples

docs/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ Lambda Utilities is a collection of pre-configured tools and helpers designed to
1212
- **[Logging Guide](./LOGGING.md)** – Implement structured logging in your Lambda functions with Pino and automatic AWS context enrichment
1313
- **[API Gateway Responses](./API_GATEWAY_RESPONSES.md)** – Format Lambda responses for API Gateway with standard HTTP status codes and headers
1414
- **[DynamoDB Client](./DYNAMODB_CLIENT.md)** – Reusable singleton DynamoDB client instances with custom configuration
15+
- **[SNS Client](./SNS_CLIENT.md)** – Reusable singleton SNS client for publishing messages to topics with message attributes
1516

1617
## Features
1718

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

2425
## Support

0 commit comments

Comments
 (0)