This project is an AWS Lambda-based microservice for managing invoices. It uses AWS DynamoDB as the database and is built using Node.js and TypeScript. The project includes several Lambda functions for creating, updating, retrieving, and deleting invoices.
- Node.js
- AWS CLI
- Docker (for local DynamoDB)
-
Install dependencies:
npm install
-
Start DynamoDB Local in a Docker container:
docker run --rm -p 8000:8000 -v /tmp:/data amazon/dynamodb-local
-
Retrieve the ip address of your docker container running dynamodb local:
docker inspect <container_name_or_id> -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
-
Create the DynamoDB table:
aws dynamodb create-table --table-name invoices --attribute-definitions AttributeName=userId,AttributeType=S AttributeName=invoiceId,AttributeType=S --key-schema AttributeName=userId,KeyType=HASH AttributeName=invoiceId,KeyType=RANGE --billing-mode PAY_PER_REQUEST --endpoint-url http://localhost:8000
-
Update env.json with the IP of your Docker container for the endpoint override:
{ "getAllInvoicesFunction": { "ENDPOINT_OVERRIDE": "http://172.17.0.2:8000", "TABLE_NAME": "invoices", "userId": "123456", "userName": "admin" }, "postInvoiceFunction": { "ENDPOINT_OVERRIDE": "http://172.17.0.2:8000", "TABLE_NAME": "invoices", "userId": "123456", "userName": "admin" } }
-
run the following commands to start the sam local api:
sam build sam local start-api --env-vars env.json --host 0.0.0.0 --port 3002 --debug
-
To run the tests, use the following command:
npm run test
-
Deploy the application using the AWS SAM CLI:
sam deploy --guided