Certainly! Here’s the README.md
content in plain text:
This project is a CRUD (Create, Read, Update, Delete) microservice for user management. It is built using the Serverless Framework, AWS Lambda, API Gateway, and DynamoDB. The service is written in TypeScript and leverages environment variables for configuration.
- Prerequisites
- Setup
- Configuration
- Running the Service Locally
- Deploying the Service
- Running Tests
- Linting
- Environment Variables
- Folder Structure
- License
Before you begin, ensure you have the following installed on your machine:
- Node.js (version 14.x or higher)
- npm (comes with Node.js)
- AWS CLI (configured with your credentials)
- Serverless Framework
You can install the Serverless Framework globally using npm:
npm install -g serverless
-
Clone the repository:
git clone https://github.com/kgtech/user-crud-service.git cd user-crud-service
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.env
file in the root of your project and add your configuration. You can use the provided.env.example
as a template.cp .env.example .env
Then, open
.env
and configure it according to your needs.
-
.env
File: This file contains environment-specific settings like table names and pagination limits.Example:
# .env USER_TABLE=Users ORDER_TABLE=Orders PRODUCT_TABLE=Products USER_PAGINATION_LIMIT=10
-
TypeScript Configuration: The
tsconfig.json
file contains the TypeScript compiler options.
To run the service locally for development and testing purposes:
npm run start
This command will start the Serverless service locally using the serverless-offline
plugin, allowing you to invoke functions via HTTP requests.
To deploy the service to AWS:
npm run deploy
This command will use the Serverless Framework to deploy your service to AWS Lambda, API Gateway, and DynamoDB.
To run the test suite:
npm run test
This project uses Jest for unit testing. Ensure that you have written tests in the __tests__
directory.
To check your code for linting errors:
npm run lint
This command will run ESLint against your TypeScript code to ensure it adheres to the coding standards defined in the .eslintrc
configuration.
The service relies on environment variables defined in the .env
file for configuration. Key environment variables include:
- USER_TABLE: The name of the DynamoDB table used to store user data.
- ORDER_TABLE: The name of the DynamoDB table used to store order data.
- PRODUCT_TABLE: The name of the DynamoDB table used to store product data.
- USER_PAGINATION_LIMIT: The default pagination limit for listing users.
user-crud-service/
│
├── .env # Environment configuration file
├── .env.example # Example environment configuration file
├── .gitignore # Git ignore file
├── __tests__/ # Unit tests directory
│ ├── createUser.test.ts # Test for createUser function
│ ├── getUser.test.ts # Test for getUser function
│ ├── updateUser.test.ts # Test for updateUser function
│ └── deleteUser.test.ts # Test for deleteUser function
│
├── src/ # Source code directory
│ ├── handlers/ # Lambda function handlers
│ │ ├── createUser.ts # Handler for creating a user
│ │ ├── getUser.ts # Handler for getting a user
│ │ ├── updateUser.ts # Handler for updating a user
│ │ ├── deleteUser.ts # Handler for deleting a user
│ │ └── listUsers.ts # Handler for listing users
│ │
│ ├── utils/ # Utility functions
│ │ ├── validateUser.ts # User input validation logic
│ │ ├── handleError.ts # Error handling logic
│ │ └── logger.ts # Logger utility
│ │
│ └── config/ # Configuration files
│ └── loadEnv.ts # Load environment variables
│
├── serverless.yml # Serverless Framework configuration file
├── tsconfig.json # TypeScript configuration file
└── package.json # Project metadata and scripts
This project is licensed under the MIT License - see the LICENSE file for details.
This is the full text of the README that outlines the setup, configuration, and usage of the User CRUD microservice.