diff --git a/functions/handler.ts b/functions/handler.ts deleted file mode 100644 index bd141f8..0000000 --- a/functions/handler.ts +++ /dev/null @@ -1,8 +0,0 @@ -export async function hello() { - return { - statusCode: 200, - body: JSON.stringify({ - message: "Go Serverless v4! Your function executed successfully!", - }), - }; -} diff --git a/functions/list.ts b/functions/list.ts new file mode 100644 index 0000000..1fd3900 --- /dev/null +++ b/functions/list.ts @@ -0,0 +1,45 @@ +import { Handler, APIGatewayProxyEventV2 } from "aws-lambda"; + +export const create: Handler = async (event) => { + console.log("event", event.body, event.pathParameters); + + return { + statusCode: 200, + body: JSON.stringify({ + message: "Go Serverless v4! Your function executed successfully!", + }), + }; +}; + +export const get: Handler = async (event) => { + console.log("event", event.body, event.pathParameters); + + return { + statusCode: 200, + body: JSON.stringify({ + message: "Go Serverless v4! Your function executed successfully!", + }), + }; +}; + +export const update: Handler = async (event) => { + console.log("event", event.body, event.pathParameters); + + return { + statusCode: 200, + body: JSON.stringify({ + message: "Go Serverless v4! Your function executed successfully!", + }), + }; +}; + +export const remove: Handler = async (event) => { + console.log("event", event.body, event.pathParameters); + + return { + statusCode: 200, + body: JSON.stringify({ + message: "Go Serverless v4! Your function executed successfully!", + }), + }; +}; diff --git a/package.json b/package.json index 3c780fc..d1a3ede 100644 --- a/package.json +++ b/package.json @@ -11,16 +11,17 @@ "packageManager": "pnpm@9.4.0", "dependencies": { "@aws-sdk/client-dynamodb": "^3.609.0", - "@types/serverless": "^3.12.22", - "dynamodb-onetable": "^2.7.4", - "serverless": "^4.1.11" + "dynamodb-onetable": "^2.7.4" }, "devDependencies": { "@eslint/js": "^9.6.0", + "@types/aws-lambda": "^8.10.140", "@types/node": "^20.14.10", + "@types/serverless": "^3.12.22", "eslint": "9.x", "globals": "^15.8.0", "prettier": "3.3.2", + "serverless": "^4.1.11", "typescript-eslint": "^7.15.0" } } \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8b3733c..25ab4bf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,22 +11,22 @@ importers: '@aws-sdk/client-dynamodb': specifier: ^3.609.0 version: 3.609.0 - '@types/serverless': - specifier: ^3.12.22 - version: 3.12.22 dynamodb-onetable: specifier: ^2.7.4 version: 2.7.4 - serverless: - specifier: ^4.1.11 - version: 4.1.11 devDependencies: '@eslint/js': specifier: ^9.6.0 version: 9.6.0 + '@types/aws-lambda': + specifier: ^8.10.140 + version: 8.10.140 '@types/node': specifier: ^20.14.10 version: 20.14.10 + '@types/serverless': + specifier: ^3.12.22 + version: 3.12.22 eslint: specifier: 9.x version: 9.6.0 @@ -36,6 +36,9 @@ importers: prettier: specifier: 3.3.2 version: 3.3.2 + serverless: + specifier: ^4.1.11 + version: 4.1.11 typescript-eslint: specifier: ^7.15.0 version: 7.15.0(eslint@9.6.0)(typescript@5.5.3) @@ -395,6 +398,9 @@ packages: resolution: {integrity: sha512-4pP0EV3iTsexDx+8PPGAKCQpd/6hsQBaQhqWzU4hqKPHN5epPsxKbvUTIiYIHTxaKt6/kEaqPBpu/ufvfbrRzw==} engines: {node: '>=16.0.0'} + '@types/aws-lambda@8.10.140': + resolution: {integrity: sha512-4Dh3dk2TUcbdfHrX0Al90mNGJDvA9NBiTQPzbrjGi/dLxzKCGOYgT8YQ47jUKNFALkAJAadifq0pzyjIUlhVhg==} + '@types/node@20.14.10': resolution: {integrity: sha512-MdiXf+nDuMvY0gJKxyfZ7/6UFsETO7mGKF54MVD/ekJS6HdFtpZFBgrh6Pseu64XTb2MLyFPlbW6hj8HYRQNOQ==} @@ -1748,6 +1754,8 @@ snapshots: '@smithy/types': 3.3.0 tslib: 2.6.3 + '@types/aws-lambda@8.10.140': {} + '@types/node@20.14.10': dependencies: undici-types: 5.26.5 diff --git a/serverless.ts b/serverless.ts index cad37ac..ab9ee89 100644 --- a/serverless.ts +++ b/serverless.ts @@ -18,20 +18,62 @@ const serverlessConfig: Serverless = { }, functions: { - hello: { - handler: "functions/handler.hello", + createList: { + handler: "functions/list.create", environment: { ddb_table: { Ref: "DdbTable" }, }, events: [ { httpApi: { - path: "/", + path: "/list", + method: "post", + }, + }, + ], + }, + getList: { + handler: "functions/list.get", + environment: { + ddb_table: { Ref: "DdbTable" }, + }, + events: [ + { + httpApi: { + path: "/list/{id}", method: "get", }, }, ], }, + updateList: { + handler: "functions/list.update", + environment: { + ddb_table: { Ref: "DdbTable" }, + }, + events: [ + { + httpApi: { + path: "/list/{id}", + method: "patch", + }, + }, + ], + }, + removeList: { + handler: "functions/list.remove", + environment: { + ddb_table: { Ref: "DdbTable" }, + }, + events: [ + { + httpApi: { + path: "/list/{id}", + method: "delete", + }, + }, + ], + }, }, resources: {