diff --git a/package.json b/package.json index 88cde03..1e177ec 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@middy/http-error-handler": "^5.4.3", "@middy/http-json-body-parser": "^5.4.3", "dynamodb-onetable": "^2.7.4", + "lodash": "^4.17.21", "zod": "^3.23.8" }, "devDependencies": { @@ -23,6 +24,7 @@ "@eslint/js": "^9.6.0", "@types/aws-lambda": "^8.10.140", "@types/jest": "^29.5.12", + "@types/lodash": "^4.17.6", "@types/node": "^20.14.10", "@types/serverless": "^3.12.22", "dotenv": "^16.4.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f4f02c3..9f39522 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ importers: dynamodb-onetable: specifier: ^2.7.4 version: 2.7.4 + lodash: + specifier: ^4.17.21 + version: 4.17.21 zod: specifier: ^3.23.8 version: 3.23.8 @@ -39,6 +42,9 @@ importers: '@types/jest': specifier: ^29.5.12 version: 29.5.12 + '@types/lodash': + specifier: ^4.17.6 + version: 4.17.6 '@types/node': specifier: ^20.14.10 version: 20.14.10 @@ -774,6 +780,9 @@ packages: '@types/jest@29.5.12': resolution: {integrity: sha512-eDC8bTvT/QhYdxJAulQikueigY5AsdBRH2yDKW3yveW7svY3+DzN84/2NUgkw10RTiJbWqZrTtoGVdYlvFJdLw==} + '@types/lodash@4.17.6': + resolution: {integrity: sha512-OpXEVoCKSS3lQqjx9GGGOapBeuW5eUboYHRlHP9urXPX25IKZ6AnP5ZRxtVf63iieUbsHxLn8NQ5Nlftc6yzAA==} + '@types/node@20.14.10': resolution: {integrity: sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ==} @@ -3649,6 +3658,8 @@ snapshots: expect: 29.7.0 pretty-format: 29.7.0 + '@types/lodash@4.17.6': {} + '@types/node@20.14.10': dependencies: undici-types: 5.26.5 diff --git a/serverless.ts b/serverless.ts index 6d5a5c1..9f5c513 100644 --- a/serverless.ts +++ b/serverless.ts @@ -1,3 +1,4 @@ +import resources from "./src/resources"; import { ServerlessExtended } from "./src/types/extendedSlsTypes"; const environment = { @@ -120,36 +121,7 @@ const serverlessConfig: ServerlessExtended = { }, }, - resources: { - Resources: { - DdbTable: { - Type: "AWS::DynamoDB::Table", - Properties: { - AttributeDefinitions: [ - { - AttributeName: "pk", - AttributeType: "S", - }, - { - AttributeName: "sk", - AttributeType: "S", - }, - ], - KeySchema: [ - { - AttributeName: "pk", - KeyType: "HASH", - }, - { - AttributeName: "sk", - KeyType: "RANGE", - }, - ], - BillingMode: "PAY_PER_REQUEST", - }, - }, - }, - }, + resources, }; export default serverlessConfig; diff --git a/src/resources/ddb.ts b/src/resources/ddb.ts new file mode 100644 index 0000000..0f68eb0 --- /dev/null +++ b/src/resources/ddb.ts @@ -0,0 +1,32 @@ +import { ServerlessExtended } from "../types/extendedSlsTypes"; + +export const ddbResources: ServerlessExtended["resources"] = { + Resources: { + DdbTable: { + Type: "AWS::DynamoDB::Table", + Properties: { + AttributeDefinitions: [ + { + AttributeName: "pk", + AttributeType: "S", + }, + { + AttributeName: "sk", + AttributeType: "S", + }, + ], + KeySchema: [ + { + AttributeName: "pk", + KeyType: "HASH", + }, + { + AttributeName: "sk", + KeyType: "RANGE", + }, + ], + BillingMode: "PAY_PER_REQUEST", + }, + }, + }, +}; diff --git a/src/resources/index.ts b/src/resources/index.ts new file mode 100644 index 0000000..cfbf391 --- /dev/null +++ b/src/resources/index.ts @@ -0,0 +1,7 @@ +import { merge } from "lodash"; + +import { ddbResources } from "./ddb"; + +const resources = merge(ddbResources); + +export default resources;