This is a sample application that demonstrates the communication between two Lambda services using AWS Kinesis. The Order Service receives HTTP POST requests to create new orders, and it produces events to a Kinesis stream. The Product Service consumes the events and updates the product quantity in a DynamoDB table.
- Docker and Docker Compose are installed.
- AWS CLI is installed (for creating the Kinesis stream).
- Serverless Framework is installed globally (
npm install -g serverless).
-
Clone the repository and navigate to the project directory.
-
Start LocalStack using Docker Compose to emulate AWS services locally:
docker-compose up -d- Create a new Kinesis stream named "my-stream" using the AWS CLI:
aws --endpoint-url=http://localhost:4566 kinesis create-stream --stream-name my-stream --shard-count 1- Install dependencies for the Order Service:
cd order-service
yarn install- Run the Order Service locally using Serverless Offline:
sls offlineTo create a new order, send an HTTP POST request to the /order endpoint:
curl -X POST -H "Content-Type: application/json" -d '{
"orderId": "1",
"productId": "1",
"quantity": 1
}' http://localhost:3005/dev/orderTo check if Kinesis has received the data, follow these steps:
- List the shards of the Kinesis stream using the AWS CLI:
aws --endpoint-url=http://localhost:4566 kinesis describe-stream --stream-name my-stream-
Note the shard ID of the shard you want to read records from.
-
Get a shard iterator for the shard using the AWS CLI:
aws --endpoint-url=http://localhost:4566 kinesis get-shard-iterator --stream-name my-stream --shard-id shard-id --shard-iterator-type TRIM_HORIZON-
Note the ShardIterator value.
-
Read records from the Kinesis stream using the shard iterator:
aws --endpoint-url=http://localhost:4566 kinesis get-records --shard-iterator shard-iterator-value- Install dependencies for the Product Service:
cd product-service
yarn install- Invoke the Product Service function locally using Serverless:
sls invoke local -f product-serviceBy following these steps, you should be able to run the Order-Product Service app locally and observe the communication between the services using AWS Kinesis.