‫So now that
‫we've seen synchronous invocations,
‫let's go into asynchronous invocation.
‫So they're for service
‫that will invoke another functions behind the scenes,
‫so Amazon S3, SNS topics, CloudWatch Events, and so on.
‫So let's go through a concrete example.
‫Say we have an S3 bucket
‫and an S3 event notification for new files.
‫This will go into the Lambda Service,
‫and because it's asynchronous something will happen.
‫The events are going to be placed
‫in an internal Event Queue.
‫So we have an Event Queue here
‫and your Lambda function is going to
‫be reading off that Event Queue.
‫The Lambda function then will try to process these events,
‫but if somehow things go wrong,
‫the Lambda function will automatically attempt to retry.
‫So that means that it will be three tries in total.
‫The first one will happen right away,
‫then the second one will happen a minute after,
‫and the third one will happen two minutes after
‫the second one.
‫So the idea is that our Lambda function
‫is going to retry three times in total.
‫And then, once the retries happen,
‫that means that our Lambda function is possibly
‫going to process those same events multiple times
‫and so this could be a problem.
‫And so if you lambda function is not idempotent
‫this could be big problem, so meaning your Lambda function
‫should be idempotent.
‫Idempotentcy means that, in case of retries,
‫the result is the same.
‫So then, if you have a retry happening,
‫what will happen is that you will see
‫duplicate log entries in CloudWatch Logs
‫because your Lambda function
‫will try over and over and over again.
‫So we can define a DLQ, or dead-letter queue,
‫for after the retries are done.
‫So that means that in case there's a failed processing
‫and we never were able to succeed
‫because of the retries, then the Lambda function
‫can send some events to SQS or SNS
‫for further processing later one.
‫And so, this is the whole idea
‫behind asynchronous invocations.
‫And so you may ask me,
‫"Why we will use asynchronous versus synchronous?"
‫Well, first of all, some services must use asynchronous,
‫so you have no choice,
‫and the second one is, for example,
‫say you need to speed up processing
‫and you don't need to wait for the results,
‫then you can start 1000 files being processed
‫at the same time, and you just wait at the end
‫for all five to be processed in parallel,
‫but you don't wait for each individual results,
‫and so that speeds up your processing time.
‫So, what services are done asynchronously?
‫The first one is Amazon S3
‫when we have S3 Event Notifications
‫invoking Lambda functions.
‫We have SNS, so when we receive notifications
‫and we trigger a Lambda function.
‫CloudWatch Events or CloudWatch EventBridge,
‫which will basically have our Lambda functions
‫react to events happening in our AWS infrastructure.
‫Other services that we will not necessarily see
‫in the hands-on would be CodeCommit
‫to trigger a Lambda function whenever
‫there's a new branch or new tag or new push,
‫CodePipeline to invoke a Lambda function during the pipeline
‫and the Lambda must callback CodePipeline,
‫or some other services, CloudWatch Logs for log processing,
‫SES, so Simple Email Service for sending out emails,
‫CloudFormation, Config, Io T, and IoT Events.
‫So from our standpoint for this certification
‫we need to know how Lambda works with Amazon S3,
‫SNS, and CloudWatch Events or EventBridge.
‫So let's go ahead and learn
‫about asynchronous invocation in the hands-on.
‫I will see you in the next lecture.