A service in Node.js that exposes an API which can be consumed from any client. This service checks how many video streams a given user is watching and prevent a user from watching more than 3 video streams concurrently. Uses services like API Gateway, Lambda, DynamoDB etc
Hey- before you actually use this, make sure you've [Docker](https://www.docker.com/) installed and running. Expand to read more
### 🚨 AWS CREDENTIALS
This project uses AWS credentials that have been provided separately to help you run this project. This have been set to ENV variables with the keys below:
- ACCESS_KEY_ID
- SECRET_ACCESS_KEY
- DEFAULT_REGION
Once you have each of these: access key id, secret access key, region, you're all set!
In your project directory, run
docker build --build-arg ACCESS_KEY_ID=<ACCESS_KEY_ID> --build-arg SECRET_ACCESS_KEY=<SECRET_ACCESS_KEY> --build-arg DEFAULT_REGION=<DEFAULT_REGION> -t streams-count-api .
When build is complete you can verify your image with:
docker images
Then run your image with (make sure port 8080 is free on your local machine):
docker run -p 8080:8080 -d --name streams-count-api streams-count-api
docker ps
docker logs streams-count-api
docker exec -it streams-count-api /bin/bash
First do a curl
curl -i localhost:8080
You should get a ITS WORKING
response. You can open Postman (to make it easier) and test your the api
The endpoint for getting the streams for current user is localhost:8080/streams
Please note there are some users currently in database. The
localhost:8080/streams
endpoint requires aX-ID
header in other to identify the current user
You can user the following ids to test out the endpoint:
- 123
- 1234
- 12345
- 123456
curl -i https://l788umca3c.execute-api.us-west-2.amazonaws.com/prod/
Please note, you require a
X-ID
header in other to identify the current user. Possible values are listed above
curl https://l788umca3c.execute-api.us-west-2.amazonaws.com/prod/streams -H "X-ID: 123"
This api uses AWS Lambda, Lambda automatically scales out for incoming requests, if all existing execution contexts (lambda instances) are busy. Also we can use AWS Lambda with an Application Load Balancer,
We can also use Application Auto Scaling. Application Auto Scaling allows us to configure automatic scaling for different resources, including Provisioned Concurrency for Lambda. We can scale resources based on a specific CloudWatch metric or at a specific date and time.
This api implements CloudWatch
logs to help in logging and monitoring at scale. The api uses winston-cloudwatch
to send specific logs to CloudWatch
under a log group name.
The Log Group Name
is unique and the Log Streams Name
is also unique to aid in filtering and setting metrics.
Every other stdout
goes to to a different Log Group