A demo project which implements a RESTful API (specs here) with AWS Lambda & API Gateway Related technologies include:
- HikariCP for connection pooling to AWS RDS
- Log4j2 for logging
- Kafka Streaming for data analysis. Specifically, this application streams liftId to a Kafka topic which is consumed every few seconds to determine the most frequently used lift by far.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
What you need to install and how to install them
- Install AWS Command Line Interface (AWS CLI)
- Install Docker (Docker must always be running whenever you develop, test, analyze, or deploy serverless applications or functions)
- Install AWS Serverless Application Model Command Line Interface (AWS SAM CLI)
- AWS-Toolkit for Intellij
- Create an IAM user and group
- Create an access key for the user
-
Create another EC2 instance to host zookeeper/ kafka broker
-
Set up security settings to allow inbound connections on port 9092 from VPC and/or your machine
-
Update jdk
sudo yum update -y sudo yum install java-1.8.0 sudo yum remove java-1.7.0-openjdk
-
Download Kafka
wget https://www-eu.apache.org/dist/kafka/2.3.1/kafka-2.3.1-src.tgz tar -xzf kafka-2.3.1-src.tgz cd kafka-2.3.1-src/
-
Start Zookeeper
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
Test that zookeeper is up and running:
echo "ruok" | nc localhost 2181
-
Set up advertised.listeners config param in server.properties
advertised.listeners=PLAINTEXT://<kafka-hostname>:9092
-
Start Kafka server
bin/kafka-topics.sh –create –bootstrap-server localhost:9092 –replication-factor 1 –partitions 1 –topic lift-usage-input bin/kafka-topics.sh –create –bootstrap-server localhost:9092 –replication-factor 1 –partitions 1 –topic lift-usage-output
-
-
Grant AWSLambdaVPCAccessExecutionRole policy to AWS Lambda Functions
-
Enable Lambda Proxy Integration from API Gateway
-
Make sure you are using the correct AWS Credentials in the right region
-
Deploy AWS Lambda Functions onto a CloudFormation stack
-
Send GET/POST requests to API Gateway
-
Check if database gets updated correspondingly
-
Read messages from lift-usage-output topic on kafka broker hosted on EC2
-
Read from command line:
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic lift-usage-output \ --from-beginning --formatter kafka.tools.DefaultMessageFormatter --property print.key=true --property print.value=true \ --property key.deserializer=org.apache.kafka.common.serialization.StringDeserializer --property value.deserializer=org.apache.kafka.common.serialization.LongDeserializer
-
Read from Kafka Consumer written in Java:
Run kafka.StreamConsumer.java
-
- Maven - Dependency Management
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
- QA Hoang
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details