In this module, we will learn about what is AWS Lambda and Amazon CloudWatch and how we are using it in AWS Management Console. We will create AWS Lambda S3 event function, configure and also upload files to that event and monitor those using Amazon CloudWatch.
WHAT IS AWS LAMBDA AND AWS CLOUDWATCH?
AWS LAMBDA: – this is a computer service which is provided by Amazon to runs code in return to events and manages computer resources which will be easy to built applications. It will respond very fast to the events like image upload, in-app activity, and website click. we can also create back end services where computer resources are automatically triggered based on requests.
AMAZON CLOUDWATCH: – this is a monitoring service which is provided by Amazon to monitor all applications and AWS cloud resources that we run on AWS. This will also collect files and alarms, and also it will monitor EC2 instances based on custom metrics which are set by applications and services.
HANDLING S3 EVENTS USING LAMBDA CONSOLE
We will create an S3 bucket and configure it as Lambda event source management. Then we will test the functionality by uploading the files and monitoring them.
Step 1. Go to services and type “S3” and we will create a bucket. If you are not sure how to create the Bucket you can refer the module “INTRODUCTION TO SIMPLE STORAGE SERVICE (S3)”
Step 2. Create the bucket with some unique name and set the region to which we are using from the start.
Step 3. After creating the bucket we need to create S3 Lambda function.
CREATING S3 LAMBDA FUNCTION
Step 1. Go to services and type “Lambda” we can see on the Lambda dashboard there are a lot of services which will vary according to our users. But since we are creating S3 Lambda functionality when we scroll down we will see s3-get-object-phyton blueprint.
Step 2. then on the next page it will ask us to link to the S3 bucket which we created just select that bucket and Event type select Object Created (ALL) this will include all the creation functionality like PUT, POST, COPY etc. And make sure to enable trigger option at the bottom to get triggers of this S3 bucket. Then click “Next”
Step 3. In this page, we need to configure its functions like Name, Description, and Runtime which defines the coding platform like phyton. In code, entry Type select Edit code Inline which will give us a sample code that can be edited. but as of now, we will leave like it is. Below when we scroll down we can see Lambda function handler and role here we will select the custom role in role tab. This will direct you to IAM page and here we can create the role and save. That role will be added here.
Step 4. Below we will have Advanced settings which will show memories and all details. Then Click Next and review after that again click Next.
Step 5. Open S3 bucket which we linked to lambda and upload files.
Step 6. then again come back to Lambda console we will see the function we created select that and then in here we will have monitoring option at the last. click on that and we will see graphs which will show us monitoring of that S3 bucket we have created.
Step 7. To view this in CloudWatch we can click on View Logs in CloudWatch where we can see a file under log groups that the event that was monitored in our S3 bucket using Lambda.
We learned what is Lambda and CloudWatch, how we create an S3 bucket and link that bucket to Lambda function. We also monitored the data in our S3 Lambda bucket using CloudWatch.