Skip to content

Commit c94a96b

Browse files
authored
Configuration utility (#10)
* Add configuration manager and tests for environment variable validation * Bump version to 0.3.0-alpha.4 and update dependencies * Add configuration guide and examples for environment variable validation
1 parent badbb43 commit c94a96b

8 files changed

Lines changed: 890 additions & 14 deletions

File tree

README.md

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,33 @@ export const handler = async (event: any, context: any) => {
4646
};
4747
```
4848

49+
### Configuration Example
50+
51+
```typescript
52+
import { z } from 'zod';
53+
import { createConfigManager } from '@leanstacks/lambda-utils';
54+
55+
// Define your configuration schema
56+
const configSchema = z.object({
57+
TABLE_NAME: z.string().min(1),
58+
AWS_REGION: z.string().default('us-east-1'),
59+
LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
60+
});
61+
62+
type Config = z.infer<typeof configSchema>;
63+
64+
const configManager = createConfigManager(configSchema);
65+
const config = configManager.get();
66+
67+
export const handler = async (event: any) => {
68+
console.log(`Using table: ${config.TABLE_NAME}`);
69+
70+
// Your Lambda handler logic here
71+
72+
return { statusCode: 200, body: 'Success' };
73+
};
74+
```
75+
4976
### API Response Example
5077

5178
```typescript
@@ -77,12 +104,35 @@ Comprehensive guides and examples are available in the `docs` directory:
77104

78105
| Guide | Description |
79106
| ------------------------------------------------------------ | ---------------------------------------------------------------------- |
107+
| **[Configuration Guide](./docs/CONFIGURATION.md)** | Validate environment variables with Zod schemas and type safety |
80108
| **[Logging Guide](./docs/LOGGING.md)** | Configure and use structured logging with automatic AWS Lambda context |
81109
| **[API Gateway Responses](./docs/API_GATEWAY_RESPONSES.md)** | Format responses for API Gateway with standard HTTP patterns |
82-
| **[AWS Clients](./docs/README.md)** | Use pre-configured AWS SDK v3 clients in your handlers |
110+
| **[DynamoDB Client](./docs/DYNAMODB_CLIENT.md)** | Use pre-configured AWS SDK v3 clients in your handlers |
83111

84112
## Usage
85113

114+
### Configuration
115+
116+
Validate and manage environment variables with type safety:
117+
118+
```typescript
119+
import { z } from 'zod';
120+
import { createConfigManager } from '@leanstacks/lambda-utils';
121+
122+
const configManager = createConfigManager(
123+
z.object({
124+
TABLE_NAME: z.string().min(1),
125+
AWS_REGION: z.string().default('us-east-1'),
126+
}),
127+
);
128+
129+
const config = configManager.get();
130+
// TypeScript infers type from schema
131+
// Validation errors thrown immediately
132+
```
133+
134+
**→ See [Configuration Guide](./docs/CONFIGURATION.md) for detailed validation patterns and best practices**
135+
86136
### Logging
87137

88138
The Logger utility provides structured logging configured specifically for AWS Lambda:

0 commit comments

Comments
 (0)