{"id":21377223,"url":"https://github.com/softchef/lambda-events","last_synced_at":"2025-03-16T09:44:37.425Z","repository":{"id":37051995,"uuid":"377074256","full_name":"SoftChef/lambda-events","owner":"SoftChef","description":null,"archived":false,"fork":false,"pushed_at":"2023-11-23T08:17:56.000Z","size":1783,"stargazers_count":0,"open_issues_count":2,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-22T21:45:25.449Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SoftChef.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-15T07:26:52.000Z","updated_at":"2021-12-30T00:05:21.000Z","dependencies_parsed_at":"2022-06-25T00:26:36.187Z","dependency_job_id":null,"html_url":"https://github.com/SoftChef/lambda-events","commit_stats":null,"previous_names":[],"tags_count":100,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftChef%2Flambda-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftChef%2Flambda-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftChef%2Flambda-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SoftChef%2Flambda-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SoftChef","download_url":"https://codeload.github.com/SoftChef/lambda-events/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243852432,"owners_count":20358270,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T09:19:37.718Z","updated_at":"2025-03-16T09:44:37.401Z","avatar_url":"https://github.com/SoftChef.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Lambda Events\n\n[![npm version](https://badge.fury.io/js/%40softchef%2Flambda-events.svg)](https://badge.fury.io/js/%40softchef%2Flambda-events)\n![Release](https://github.com/SoftChef/lambda-events/workflows/Release/badge.svg)\n![npm](https://img.shields.io/npm/dt/@softchef/lambda-events?label=NPM%20Downloads\u0026color=orange)\n\n## Installation\n\n```\n// NPM\nnpm install @softchef/lambda-events\n\n// Yarn\nyarn add @softchef/lambda-events\n```\n\n## RestApi\n\n_JavaScript require_\n\n```\nconst { RestApi } = require('@softchef/lambda-events');\nor\nconst { Request, Response } = require('@softchef/lambda-events');\n```\n\n_TypeScript import_\n\n```\nimport { RestApi } from '@softchef/lambda-events';\nor\nimport { Request, Response } from '@softchef/lambda-events';\n```\n\n### RestApi.Request / Request class:\n\n```\nconst request = new RestApi.Request(event);\nor\nconst request = new Request(event);\n```\n\n***Methods***\n\n_Get Parameters_\n\n```\nconst value = request.parameter(key);\n\n// Get URL path paramter, ex: /Users/{username}, \n\nconst username = request.parameter('username');\n```\n\n_Get QueryStrings_\n\n```\nconst value = request.get(key, defaultValue);\n\n// Get query string, ex: ?filter=hello\n\nconst value = request.get('filter', null);\n```\n\n_Get Post data / Body_\n\n```\nconst value = request.input(key, defaultValue);\n\n// Get post field data, ex: name=John\n\nconst name = request.input('name', 'Who');\n\nconst inputs = request.inputs(keys);\n\n// Get post mulitple fields data, ex: name=John\u0026enabled=true,\n\nconst inputs = request.inputs(['name', 'enabled']);\n\n// inputs: { name: 'John', enabled: true }\n```\n\n_Validate Inputs or QueryStrings_\n\n```\nconst validated = request.validate(keysProvider);\n\n// Validate input data, keysProvider is an callback, keysProvider(joi) please return a Joi schemas\n```\n\n### RestApi.Response / Response class:\n\n```\nconst response = new RestApi.Response();\nor\nconst response = new Response();\n```\n\n***Methods***\n\n_Response JSON_\n\n```\nresponse.json(data, httpStatusCode);\n\n// If the API request are success, use response.json and give a JSON object data to return client. ex:\n\nresponse.json({ hello: \"world\"}, 200);\n```\n\n_Response error_\n\n```\nresponse.error(error, httpStatusCode);\n\n// If the API request are failure, use response.error and give a Error object to return client. ex:\n\nresponse.error(\n  new Error('Invalid input data'),\n  422\n)\n```\n\n## CustomResource\n\nCloudFormation can use CustomResource to invoke a Lambda function. You will get request type, properties from event, and response to stacks when process success/failure.\n\n```\n// JavaScript require\nconst { CustomResource } = require('@softchef/lambda-events');\n\n// TypeScript import\nimport { CustomResource } from '@softchef/lambda-events';\n```\n\n### CustomResource.Request class:\n\n```\nconst request = new CustomResource.Request(event);\n```\n\n***Methods***\n\n_Get Properties_\n\n```\nconst value = request.property(key);\n\n// Get the CustomResource property by key. ex:\n\nconst tableName = request.property('DynamoDbTableName');\n\n// Will return the reference table name from stacks.\n```\n\n_Get RequestType_\n\n```\nconst isOn = request.on\b(requestType);\n\n// The request type is the stacks process status, allow: Create / Update / Delete. ex:\n\nconst isCreate = request.on('create');\n\n// When stacks has first time to create will be true\n\nconst isCreateOrUpdate = request.on(['create', 'update']);\n\n// When stacks has first time to create or any update will be true\n```\n\n### CustomResource.Response class:\n\n```\nconst response = new CustomResource.Response(event);\n```\n\n***Methods***\n\n_Response success to stacks_\n```\nresponse.success(returnData): Promise;\n\n// You can return data to stacks. ex:\n\nawait response.success({\n  time: Date.now()\n});\n\n// In the stacks can reference. CDK ex:\n\nnew CfnOutput(stack, id, {\n  value: customResource.getAtt('time')\n});\n```\n\n_Response failure to stacks_\n\n```\nresponse.failed(error): Promise;\n\n// If process has any error, you can report the error message to response stacks. ex:\n\nawait response.failed(\n  new Error('Something wrong.')\n);\n\n// The stacks will rollback and display your error message.\n\n```\n\n## Future\n\n- Support more lambda events\n  - Cognito Trigger\n  - S3 Trigger\n  - EventBridge event source\n  - SQS event source\n  - Kinesis Data Firehose event source\n  - more...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftchef%2Flambda-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoftchef%2Flambda-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoftchef%2Flambda-events/lists"}