Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 2.22 KB

2-webserver-lambda-function.md

File metadata and controls

22 lines (15 loc) · 2.22 KB

Web Server in Lambda Function

Why

For better modularity, we set up another lambda function which serves as a web server, exclusively dealing with all requests from and to the Arduino end.

It has its own storage and persistent variables. The lambda function storing logic for Alexa Skill has all "puzzle-related" variables, whereas this web server lambda function stores all "arduino request-related" variables ( e.g. toMove, startingPos, endingPos, you could also save something like timesRequested etc. )

For this web server to be synchronized with the latest puzzle states, we will need to invocation between lambda functions, which will be discussed later.

How

  1. copy the entire arduinoRequestHandlers folders to your project folder.
  2. type ./publish.sh to execute the bash script which compresses all files under arduinoRequestHandlers/lambda including node_modules into a .zip file and update to your Amazon Lambda Function.

Quick Walk-through of the code

  • query parameters in API query string will appear as a child object in event parameter. In our case: event.action has a few possible values ( arduinoPull, arduinoMove, update and availabilityCheck ), and when any other clients request for the API specified in the next step: api gateway appending with ?action=arduinoPull for instance, the web server could find respective handling logic.
  • DynamoDB read and write are standard implementation, whose more samples could be seen here.
  • Since DynamoDB is also a network asynchronous request (within Amazon's different service), the request our web server received could actually come from DynamoDB which is distinguishable as its event.Records will have contents.
  • DynamoDB supported types