A Lambda is an executable function defined within AWS. AWS supports lambdas written in a variety of programming languages using a variety of runtime support packages.
The process for setting up a lambda depends on the programming language you use. For example, Building Lambda Functions with Node.js explains what you have to do in order to create a JavaScript lambda. Other AWS web pages explain how to set up lambdas written in other languages.
When creating a lambda, you should follow the best practice recommendations provided by AWS.
Event Processing¶
For Brightspace Data Streams, you create a lambda that processes new events as they appear in the BDS Kinesis stream. Typically, you design your lambda so that it handles multiple event objects received in a single batch. When you configure the Kinesis stream, you may specify the number of event objects to be grouped into a batch. You may also specify batch windows so that batches are sent within a certain period of time, even if the Kinesis stream hasn’t yet accumulated a full batch.
Processing may be as simple as copying each batch of event objects to a computer on your own local network, or as sophisticated as parsing the event object in place on AWS, obtaining additional information from Brightspace (e.g. student names to match student ID numbers), and taking further action based on each type of event. For example, if your lambda detects that a teacher has posted an announcement for a particular class, the lambda might send a text message or email to all students in the class, drawing their attention to the announcement.
For sophisticated event handling, lambdas often need more information than is contained in the actual event object. In the announcement example just given, the lambda will need to obtain a class list from Brightspace and will also need to obtain contact information for each student in the class. To do this, the lambda must use the Brightspace API to obtain the information.
Lambdas should return a status code to indicate success or failure. If the status code indicates success, AWS automatically removes the processed event objects from the Kinesis stream. Otherwise, the same batch of objects are sent to the lambda again. Various error handling facilities are available to cope with errors.
If the event flow is large enough, AWS may invoke multiple instances of your lambda to handle the stream. This means that your lambda should be designed so that multiple instances can run concurrently without interfering with each other. If an instance terminates successfully, it may be immediately reinvoked with a new batch of event objects in order to eliminate the overhead of unloading then reloading a function.
For a tutorial on creating and using a lambda with a Kinesis stream, see Using AWS Lambda with Amazon Kinesis.