CloudWatch -
Monitor AWS resources such as EC2 instances, RDS databases and S3 bucket.
Collect and analyse logs from AWS services and applications.
You can set alarms and notifications based on metric and log data.
Visualize data using dashboard and charts.
Troubleshoot issues using detailed metrics and logs.
- Steps to create CloudWatch-
Create dashboard for monitoring
Create instance
Give id to dashboard
Select parameters like cpu utilization etc
- Cloud watch - Dashboard
- Create dashboard
- Give name
- Duplicate tab - Create an EC2 instance
- On cloud dashboard- Add widget- select required format - e.g.,Number
- Select required parameters- eg., NetworkOut, NetworkIn and CPU utilisation
- Here you can see data if instance to monitor- we can set limits in hour
- You can add multiple widgets. Add another widget if required
- Search instance Id - select metrics
- Here you can see data in respective formats
SNS - (Simple Notification Service)
Publish messages to topics.
Subscribe to topics sing various protocols (ex SMS, emails)
Filter messages based on attributes, allowing for target notification.
Here we can set alerts like if cpu utilities above 60% instance should stop
- Steps to create SNS-
Create topic
Create subscription
- SNS - Dashboard
- Topics- Create topic
- Standard - Name and display name
- Here created topic can be seen
Create subscription
Subscription - Create subscription
- Select topic you create-required protocol eg., email - give email address
Here subscription is pending
You will receive mail to subscribe
- After you subscribe mail, status will be confirmed
Create Alarm
Alarms - In Alarm - Create alarm
- Select metric - next
- Give instance id - select metrics
- Select required parameters eg., CPU utilisation
- Default period is 5 min , you can select as per your needs
Conditions - Static - Greater/Equal -60%
So when you cpu utilises 60% your instance will be stopped
- Select topic
- EC2 instance - Stop this instance
- Give alarm name
- Insufficient data because we just initiated process
- After some time it will be in Ok state
- Connect EC2 instance on your gitbash - give following command to utilise cpu fast for testing
- Check CPU consumption
- After 60% utilisation you get below message
- In alarm alert is activated
- And your EC2 instance is stopped automatically
Lambda -
AWS Lambda is a server-less computing service provided by Amazon Web Services that allows you to run code without provisioning or managing servers.
Lambda functions are triggered by events and can execute in response to changes in data, state, or resource updates.
Lambda is an ideal compute service for application scenarios that need to scale up rapidly, and scale down to zero when not in demand. For example, you can use Lambda for:
File processing
Stream processing
Web applications
IoT backends
Mobile backends
Lambda function is a small, stateless code snippet that runs in response to events:
API gateway request
Database updates
File Uploads
Schedule
Lambda Functions are:
Serverless - No server management needed.
Event Driven - Runs only when triggered
Steps to create lambda function-
- Lambda - Create a function
- Name - language on which you’re running script
Duplicate tab
Create IAM role as admin
IAM - Roles - Create role
- Select AWS service
- Use case Lambda
- Give admin permission
- Give role name
- On lambda tab - Existing role - select IAM you created
- Test below script to stop instance
Now your instance will be stopped automatically.