Skip to content

Commit

Permalink
SLSCMN-3 allow extension of lambda config schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Nov 19, 2023
1 parent bf25605 commit 24f54c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export type LambdaConfig = {
* @throws Throws a `ServiceError` when validation is unsuccessful.
*/
export function validateConfig<TConfig>(schema: Joi.ObjectSchema<TConfig>): TConfig {
console.log(`config::validateConfig::${JSON.stringify(process.env, null, 2)}`);
const { error, value } = schema.validate(process.env, {
abortEarly: false,
allowUnknown: true,
Expand All @@ -47,7 +46,7 @@ export function validateConfig<TConfig>(schema: Joi.ObjectSchema<TConfig>): TCon
/**
* A Joi ObjectSchema to validate the base AWS Lambda function configuration values.
*/
const lambdaConfigSchema = Joi.object<LambdaConfig>({
export const lambdaConfigSchema = Joi.object({
AWS_EXECUTION_ENV: Joi.string().required(),
AWS_LAMBDA_FUNCTION_NAME: Joi.string().required(),
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: Joi.string().required(),
Expand All @@ -60,4 +59,4 @@ const lambdaConfigSchema = Joi.object<LambdaConfig>({
* This is useful when your function does not have additional configuration attributes.
* @see {@link LambdaConfig}
*/
export const lambdaEnv = validateConfig<LambdaConfig>(lambdaConfigSchema);
export const lambdaConfigValues = validateConfig<LambdaConfig>(lambdaConfigSchema);
4 changes: 2 additions & 2 deletions src/services/dynamo.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import {
} from '@aws-sdk/lib-dynamodb';
import { DynamoDBClient, DynamoDBClientConfig } from '@aws-sdk/client-dynamodb';

import { lambdaEnv } from './config.service';
import { lambdaConfigValues as config } from './config.service';

const dynamoDbClientConfig: DynamoDBClientConfig = {
region: lambdaEnv.AWS_REGION,
region: config.AWS_REGION,
};

const marshallOptions = {
Expand Down
7 changes: 6 additions & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@
export { LambdaConfig, lambdaEnv, validateConfig } from './config.service';
export {
LambdaConfig,
lambdaConfigSchema,
lambdaConfigValues,
validateConfig,
} from './config.service';
export { DynamoService } from './dynamo.service';

0 comments on commit 24f54c4

Please sign in to comment.