This is a sample of an ecommerce backend RESTful microservices built with the AWS CDK using AWS Serverless Services.
- AWS API Gateway (client request)
- AWS Lambda (compute)
- AWS DynamoDB (storage)
- AWS SQS (integration)
- AWS Eventbridge (application integration)
Within the lib
directory the aws-microservice-stack.ts contains all the custom constructs to be provsioned on the AWS Platform.
- apigateway.ts - provisions each api needed for each microservice
- databases.ts - provisions each database for each microservice
- microservices.ts - proviosns each lambda function needed for each service
Each service has its own api gateway, lambda function and database. The lambda functions can handle different http request sent by its respective api and process logic accordingly. The logic for each of the three lambda functions is stored in the src
directory: 1. /basket, 2. /ordering 3. /product. Each of the three directories have their own database client, i.e. ddbClient.js
for database communication, and package.json
file to install needed dependencies. In addition, the basket directory also contains an eventbridge client to send asynchronous request to the eventbridge. The basket microservice publishes events to the eventbridge and the ordering microservice subscribes to those events via an SQS Queue. The event received from the queue contains a payload with context of the basket and stores it as an order.
- Node.js
- AWS Account
- AWS CLI
- AWS CDK
- Docker
Make sure you have installed all Required Software
- Clone the repository
- At the root directory which include cdk.json files run below command:
Make sure Docker is running
cdk synth # To synthesize into cloudformation template
next run the the command below:
cdk deploy
-
Once all microservices are deployed you can test each service by hitting the following endpoints:
The cdk.json
file tells the CDK Toolkit how to execute your app.
npm run build
compile typescript to jsnpm run watch
watch for changes and compilenpm run test
perform the jest unit testscdk deploy
deploy this stack to your default AWS account/regioncdk diff
compare deployed stack with current statecdk synth
emits the synthesized CloudFormation template