We have written a few blog posts which talked about AWS Lamda, its introduction and some other areas about how to use it to spin up your API using javascript.
If you are looking to learn the basic concepts of AWS Lambda and how can we use it to spin up an API, you can read it in our AWS Lambda and API Gateway collection.
Using AWS Lambda with API is one way of invoking lambda functions. There is another way in which we can invoke AWS Lambda. In this post, we will talk about the ways we can invoke an AWS Lambda function.
There are three ways in which you can invoke an AWS Lambda function. These are:
Synchronous Invocation
The synchronous invocation is the most straightforward way to invoke an AWS Lambda function. You can either use the SDK or the CLI to invoke the function directly from the command line or your code.
The invocation type, in this case, will be RequestResponse
. This means a request will be sent to the function and the sender will wait for the response to come back from the function. Some of the services which use this model are:
- Application Load Balancer
- Amazon API Gateway
- Amazon Cognito
- Amazon Lex
- Amazon Alexa
- Amazon Cloudfront (Lambda@Edge)
- Amazon Kinesis Data Firehose
Asynchronous Invocation
The asynchronous invocation of AWS Lambda is an event-based invocation model. This is useful when you want to take action in response to an event. An example of an event can be a write operation in S3 or a broadcast of a message using an SNS topic.
The invocation type, in this case, will be Event
. Some of the services which use this model are:
- Amazon Simple Storage Service
- Amazon Simple Notification Service
- Amazon Simple Email Service
- AWS CloudFormation
- Amazon CloudWatch Logs
- Amazon CloudWatch Events
- AWS CodeCommit
- AWS Config
Poll Based Invocation
This invocation model is useful when you want to integrate queue and stream-based services with AWS Lambda. The Lambda service will poll the changes and will invoke the function once it has messages to process.
In the above diagram, the Lambda service will keep on polling the SQS and will wait until there are any messages available to process. Once it has a list of messages, it will batch them and will invoke the AWS Lambda to process. Some of the services which use this model are:
- Amazon Simple Queue Service
- Amazon Kinesis
- Amazon Dynamodb Streams
Conclusion
That is all for this post. In upcoming post I will write more about the how we can integrate the above mentioned services with AWS Lambda.