Hands-On Serverless Applications with Kotlin
上QQ阅读APP看书,第一时间看更新

Event sources from other AWS Services

Event sources are the upstream components of an FaaS that produce triggers and contexts that are wired to an AWS Lambda execution environment automatically, for the developer to consume. The following AWS Services event sources are supported by Lambda:

  • API Gateway: The Amazon API Gateway is the turnkey solution to set up a production-grade API service. This can serve as the gatekeeper to Lambda functions. Using this, the developer can expose the function by REST verbs, like GET, PUT, POST, DELETE, and many more, over HTTPS.
  • AWS IoT Button: The AWS IoT Button is a programmable button based on the Amazon Dash Button hardware, which can be configured to invoke a Lambda function. The developer can expose an IoT backend using this.
  • Alexa Skills Kit: Developers can expose the existing APIs of their applications via a new user interface called Alexa Skills. Lambda functions configured to respond to an Alexa ask command get the Natural Language Processing (NLP) context, distilled by Lex, passed to them automatically.
    An example would be a platform for restaurant reservations having its core functionality exposed as a skill via an Alexa device. Lambda functions play a crucial role in piping the user's intent to the corresponding platform API.
  • Alexa Smart Home: Similar to Alexa Skills, Lambda functions can augment smart home solutions powered by the Alexa Voice Assistant.
  • CloudFront: CloudFront is AWS' Content Delivery Network (CDN) offering. Lambda functions configured to run as a response to Cloudfront events can deliver edge engineering at scale. A typical example would be applying interceptors and inspection logic on request headers, redirection, and rolling out an A/B testing scheme, among others.
  • CloudWatch Events: CloudWatch is the AWS in-house monitoring solution that generates millions of events in response to changes in the state of the infrastructure. Lambda functions can be configured to tap into some of them, based on a rule engine, to augment the infrastructure management capability. A typical example would be a Lambda function that triggers a PagerDuty alert if operational thresholds are breached in order to signal a possible deviation from the norm.
  • CloudWatch Logs: As mentioned earlier, CloudWatch is the monitoring solution. It generates events to audit the infrastructure state of a system. These events are piped into log files, called CloudWatch Logs. One can configure a Lambda function to consume these log files and roll out a custom log monitoring solution.
  • CodeCommit: AWS CodeCommit is a hosted version control system from AWS. In this integration, events are generated when a developer pushes code to a branch, when a branch is merged, and so on. These events can be consumed by a Lambda function, which can execute code as a part of a continuous integration pipeline.
  • Cognito Sync Triggers: AWS Cognito is an AuthN solution from AWS. Using Cognito, developers can get AuthN implemented into their system in a matter of minutes. Cognito Sync helps to synchronize user data, like preferences, tokens, and so on. Lambda functions can be set up to consume such events, and to sync such user data across all user devices. This helps to maintain consistency across all sessions pertaining to a user.
  • DynamoDB: In a typical RDBMS environment, there is the concept of triggers, which is SQL code executed in response to Data Modification Language (DML) statement execution. Using Lambda functions, one can simulate such triggers in DynamoDB, which is a NoSQL store. This is a powerful combination. The only caveat is that the Lambda platform needs to poll DynamoDB to monitor for changes.
  • Kinesis Data Streams: AWS Kinesis is the mechanism to ingest streaming data from a variety of sources into AWS. Lambda functions can be configured to consume these streams and apply a transformation logic to the incoming streaming packet. A typical example would be a pixel tracking mechanism that tracks all user interactions in the frontend and pushes them to AWS for further analysis. A Lambda function can intercept this packet and apply collation logic, like the filtering of duplicates.
  • S3: The AWS Simple Storage Service (S3) is an offering that provides scalable and secure storage in the cloud. S3 is used to store files from a variety of sources. The files in S3 are stored in buckets. Lambda functions can be configured to execute in response to S3 bucket events. Typical S3 events that can invoke Lambda functions are file uploads to an S3 bucket or file deletes from an S3 bucket.
  • SNS: The AWS Simple Notification Service (SNS) is a mechanism to produce notifications in response to various upstream events. Lambda functions can be configured to consume these events and apply custom business logic to them.

The Lambda functions sourcing events from Kinesis Data Streams and DynamoDB work on a pull model. What this means is that the Lambda function has to be configured to poll these sources in order to decide whether execution should be triggered.

Executions triggered by the other sources work on a push model. Lambda functions execute as a part of a reaction to a published event.

The preconfigured event source mappings are the sets of events that can occur along with the corresponding parameters that are passed to a Lambda function.

AWS Lambda functions require permissions to access allied AWS Services in order to tap into the preconfigured event sources. These permissions are applied by an IAM (AWS' offering for Identity and Access Management) role, called the execution role. There are various policies associated with an execution role when one creates a lambda function.