{"id":23317950,"url":"https://github.com/luberlu/aws-lambda-api-dynamodb-cognito","last_synced_at":"2025-07-05T18:07:17.186Z","repository":{"id":266857293,"uuid":"899570360","full_name":"luberlu/aws-lambda-api-dynamodb-cognito","owner":"luberlu","description":"🚀 AWS Lambda API with DynamoDB storage and Cognito authentication. Built with TypeScript and Serverless Framework.","archived":false,"fork":false,"pushed_at":"2024-12-06T14:42:50.000Z","size":23,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-07T04:52:45.025Z","etag":null,"topics":["aws","aws-lambda","cognito","dynamodb","serverless","serverless-framework","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luberlu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-06T14:41:03.000Z","updated_at":"2024-12-06T14:45:37.000Z","dependencies_parsed_at":"2024-12-06T15:48:19.227Z","dependency_job_id":null,"html_url":"https://github.com/luberlu/aws-lambda-api-dynamodb-cognito","commit_stats":null,"previous_names":["luberlu/aws-lambda-api-dynamodb-cognito"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/luberlu/aws-lambda-api-dynamodb-cognito","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luberlu%2Faws-lambda-api-dynamodb-cognito","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luberlu%2Faws-lambda-api-dynamodb-cognito/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luberlu%2Faws-lambda-api-dynamodb-cognito/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luberlu%2Faws-lambda-api-dynamodb-cognito/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luberlu","download_url":"https://codeload.github.com/luberlu/aws-lambda-api-dynamodb-cognito/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luberlu%2Faws-lambda-api-dynamodb-cognito/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263781178,"owners_count":23510419,"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":["aws","aws-lambda","cognito","dynamodb","serverless","serverless-framework","typescript"],"created_at":"2024-12-20T17:14:37.049Z","updated_at":"2025-07-05T18:07:17.168Z","avatar_url":"https://github.com/luberlu.png","language":"TypeScript","readme":"# TypeScript Lambda Functions with Serverless Framework, DynamoDB and AWS Cognito\n\nThis project demonstrates how to develop and deploy AWS Lambda functions using TypeScript with DynamoDB and AWS Cognito authentication, using the Serverless Framework.\n\n## Features\n\n- **AWS Lambda Functions** for HTTP request processing\n- **API Gateway v2** for HTTP endpoints exposure\n- **TypeScript** for static typing\n- **DynamoDB** for data storage\n- **AWS Cognito** for secure authentication\n- **JWT Authentication** for endpoint security\n- **Serverless Framework** for deployment\n\n## Architecture\n\nThe project consists of several Lambda functions:\n- `generateToken`: JWT token generation via Cognito\n- `refreshToken`: Token refresh for expired tokens\n- `getItems`: Item retrieval (public endpoint)\n- `createItem`: Item creation (protected endpoint)\n\nEach function is triggered by API Gateway v2 and uses `APIGatewayProxyEventV2` types to handle requests/responses.\n\n## Prerequisites\n\n- Node.js and npm installed\n- An AWS account\n- Serverless Framework CLI installed globally:\n  ```bash\n  npm install -g serverless\n  ```\n- AWS configured via:\n  ```bash\n  serverless login\n  ```\n- An AWS Cognito User Pool (see configuration below)\n\n## Installation\n\nClone the repository and install dependencies:\n\n```bash\ngit clone \u003crepo-url\u003e\ncd \u003crepo-name\u003e\nnpm install\n```\n\n## AWS Cognito Configuration\n\nThis step is **required** before using the API.\n\n### User Pool Creation\n\n1. Go to AWS Cognito console\n2. Create a new User Pool with the following settings:\n   - Select \"Email\" as sign-in option\n   - In \"Security requirements\", choose \"Password policy mode: Custom\"\n   - In \"App integration\", enable \"ALLOW_USER_PASSWORD_AUTH\"\n   - Note down the User Pool ID and AWS region\n\n3. Create an App Client:\n   - Keep the generated Client Secret (it will be used for authentication)\n   - In \"Auth Flows Configuration\", enable \"ALLOW_USER_PASSWORD_AUTH\"\n   - Note down the Client ID and Client Secret\n\n4. Configure environment variables in your `.env` file:\n\n```bash\nCOGNITO_USER_POOL_ID=your_user_pool_id\nCOGNITO_CLIENT_ID=your_client_id\nCOGNITO_CLIENT_SECRET=your_client_secret\nREGION=your_region\n```\n\n## API Flow\n\n1. **Authentication** (Lambda: generateToken)\n   \n   Get a token:\n   ```bash\n   curl --request POST 'https://your-api.com/auth/token' \\\n   --header 'Content-Type: application/json' \\\n   --data-raw '{\n     \"username\": \"your_email\",\n     \"password\": \"your_password\"\n   }'\n   ```\n\n2. **Public Endpoints** (Lambda: getItems)\n   \n   List all items:\n   ```bash\n   curl --request GET 'https://your-api.com/items'\n   ```\n\n3. **Protected Endpoints** (Lambda: createItem)\n\n   Create an item (requires token):\n   ```bash\n   curl --request POST 'https://your-api.com/items' \\\n   --header 'Authorization: Bearer your_jwt_token' \\\n   --header 'Content-Type: application/json' \\\n   --data-raw '{\n     \"itemName\": \"My Item\",\n     \"description\": \"Description of my item\"\n   }'\n   ```\n\n## Deployment\n\nTo deploy your service to AWS:\n\n```bash\nserverless deploy\n```\n\nAfter deployment, you'll see output similar to:\n\n```\nService deployed to stack express-nosql-serverless-dev\nendpoint: ANY - https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com\nfunctions:\n  api: express-nosql-serverless-dev-api\n```\n\n## API Response Structure\n\nAll responses follow a standard format:\n\n**Success**:\n```json\n{\n  \"success\": true,\n  \"data\": {\n    // Returned data\n  }\n}\n```\n\n**Error**:\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"message\": \"Error message\",\n    \"code\": \"ERROR_CODE\"\n  }\n}\n```\n\n## Project Structure\n\n```\n.\n├── src/\n│   ├── functions/          # Lambda functions\n│   │   ├── auth.ts        # Authentication functions\n│   │   └── items.ts       # Item management functions\n│   └── types/             # TypeScript types\n├── serverless.yml         # Serverless configuration\n└── package.json\n```\n\n## Notes\n\n- Ensure your DynamoDB table is properly configured\n- Verify that IAM permissions are in place for DynamoDB access\n\n## License\n\nThis project is licensed under the MIT License.\n# aws-lambda-api-dynamodb-cognito\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluberlu%2Faws-lambda-api-dynamodb-cognito","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluberlu%2Faws-lambda-api-dynamodb-cognito","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluberlu%2Faws-lambda-api-dynamodb-cognito/lists"}