This Serverless project deployes three distinct Lambda functions:
- authorizerUser This function enable the authorizer capabilities of API Gateway. It queries the DynamoDB table to check if the API token in the http header request is valid or not.
- worker This function polls the Efergy cloud platform to retrive the data for each plant added
- webapi This function is a Flask application that make available the following API endpoints:
- [GET] /plants Return all the available plants
- [GET] /plants/{id} Return a particular plant
- [POST] /plants Create a new plant. The accepted body is
{ "api_key": Required, "plant_id": Required, "name": Required }
- [PUT] /plants/{id} Update a particular plant
- [DELETE] /plants/{id} Delete a particular plant
-
Set-up one environment variables:
- AWS_PROFILE: the AWS CLI profile
-
Set-up the following secured variables in the AWS Parameter store:
- RABBIT_USER The rabbitmq username
- RABBIT_PASS The rabbitmq password
- RABBIT_HOST The rabbitmq hostname
-
Use
sls plugin install -n serverless-python-requirements
to install the requirements.txt serverless plugin. -
Use
sls plugin install serverless-wsgi
to install the wsgi engine for the API endpoint management -
Install and configure the AWS Lambda Layer by cloning this repo and following the instructions reported. Copy the ARN of the Lambda function in the layers section of the serverless.yml file:
N.B This is required to enable the API call caching function.
-
Run
sls deploy
To test on local pc you have to:
-
Execute the DynamoDb dockerized local version with:
docker run -it -p 8000:8000 amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb
-
Execute the Wsgi server:
sls wsgi serve
-
To test the
worker
andauthorizerUser
functions, run:sls invoke local -f worker