Тёмный
No video :(

AWS EventBridge Service - process AWS events 

AWS Training by Gaurav Agrawal
Подписаться 503
Просмотров 1,4 тыс.
50% 1

This video will explain the use of the AWS eventbridge service and how we can use it to control the resources that are created within the AWS account. We will perform a hands on exercise to simulate terminating a costly ec2 instance created by a naive user.
Lambda python script to terminate ec2 instances - github.com/gau...
Content:
AWS EventBridge
AWS Training
automatically stop costly ec2 instances
AWS Projects

Опубликовано:

 

4 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 19   
@indranilgoswami1500
@indranilgoswami1500 Месяц назад
Thanks sir..very good explanation.
@sudsrmsee
@sudsrmsee 8 месяцев назад
super > keep it up
@nikafiq310
@nikafiq310 11 месяцев назад
Thank you for the detailed hands on video. I've been learning AWS recently and had trouble finding hands on guide on AWS EventBridge. This video have been really helpful to me
@AWSTrainingByGauravAgrawal
@AWSTrainingByGauravAgrawal 11 месяцев назад
go thru the other videos also and perform hands on of the same.
@shrutiagrawal5012
@shrutiagrawal5012 Год назад
👍🏻
@sahabsinghlathwal5956
@sahabsinghlathwal5956 11 месяцев назад
Thank you Gaurav, I liked this video, and subscribed your channel, am sure you will upload more informative video for AWS services. I have an query about EventBridge rule, you just created a t2. micro instance and that also got deleted by this rule, but t2.micro is free tier, so I'm little bit confused, I want delete instance those are above t2.large, can you please help for this?
@AWSTrainingByGauravAgrawal
@AWSTrainingByGauravAgrawal 11 месяцев назад
Thanks Sahab. I have keep the lambda code simple to reduce the complexity. The lambda code as of now is deleting any instance that got created. We can modify this code to ignore certain instance types. Let me know if you are looking for a modified lambda. I can provide you the same.
@sahabsinghlathwal5956
@sahabsinghlathwal5956 11 месяцев назад
I'm waiting for your response for above queries.
@AWSTrainingByGauravAgrawal
@AWSTrainingByGauravAgrawal 11 месяцев назад
@@sahabsinghlathwal5956 - this is the code that you can try (not tested, please test it out) import boto3 def lambda_handler(event, context): # Initialize the EC2 client for the N. Virginia region (us-east-1) ec2_client = boto3.client('ec2', region_name='us-east-1') # Get a list of all EC2 instances in the N. Virginia region instances = ec2_client.describe_instances() # Define a list of instance types that are eligible for the AWS Free Tier in us-east-1 free_tier_instance_types = ["t2.micro", "t3.micro", "t3.nano"] for reservation in instances['Reservations']: for instance in reservation['Instances']: # Check if the instance is in a running state if instance['State']['Name'] == 'running': instance_type = instance['InstanceType'] instance_id = instance['InstanceId'] # Check if the instance type is not in the free tier list if instance_type not in free_tier_instance_types: print(f"Terminating instance: {instance_id} (Instance Type: {instance_type})") ec2_client.terminate_instances(InstanceIds=[instance_id]) else: print(f"Skipping instance in Free Tier: {instance_id} (Instance Type: {instance_type})")
@sahabsinghlathwal5956
@sahabsinghlathwal5956 11 месяцев назад
@@AWSTrainingByGauravAgrawal I tried to execute this code, but getting below error - { "errorMessage": "An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation.", "errorType": "ClientError", "requestId": "d3493d54-903d-4852-bd0c-fc1164cc1acc", "stackTrace": [ " File \"/var/task/lambda_function.py\", line 8, in lambda_handler instances = ec2_client.describe_instances() ", " File \"/var/lang/lib/python3.11/site-packages/botocore/client.py\", line 534, in _api_call return self._make_api_call(operation_name, kwargs) ", " File \"/var/lang/lib/python3.11/site-packages/botocore/client.py\", line 976, in _make_api_call raise error_class(parsed_response, operation_name) " ] } Function Logs START RequestId: d3493d54-903d-4852-bd0c-fc1164cc1acc Version: $LATEST [ERROR] ClientError: An error occurred (UnauthorizedOperation) when calling the DescribeInstances operation: You are not authorized to perform this operation. Traceback (most recent call last): File "/var/task/lambda_function.py", line 8, in lambda_handler instances = ec2_client.describe_instances() File "/var/lang/lib/python3.11/site-packages/botocore/client.py", line 534, in _api_call return self._make_api_call(operation_name, kwargs) File "/var/lang/lib/python3.11/site-packages/botocore/client.py", line 976, in _make_api_call raise error_class(parsed_response, operation_name)END RequestId: d3493d54-903d-4852-bd0c-fc1164cc1acc REPORT RequestId: d3493d54-903d-4852-bd0c-fc1164cc1acc Duration: 449.11 ms Billed Duration: 450 ms Memory Size: 128 MB Max Memory Used: 88 MB Request ID d3493d54-903d-4852-bd0c-fc1164cc1acc
@sahabsinghlathwal5956
@sahabsinghlathwal5956 11 месяцев назад
Can you plz fix this code and help for another which I asked you for tagging and security group?
@tompatrickhankz2244
@tompatrickhankz2244 Год назад
Can i use EventBridge to terminate and start my ec2 instances depending the working times
@AWSTrainingByGauravAgrawal
@AWSTrainingByGauravAgrawal Год назад
yes, but insetad of using events, you will need to create a eventbridge scheduler. This scheduler can trigger a lambda function as per your schedule. That lambda will fetch all the ec2 instances in your account and stop or restart them as per your requirement.
@AWSTrainingByGauravAgrawal
@AWSTrainingByGauravAgrawal Год назад
In the comments, i am not able to paste screenshot for the scheduler.
@tompatrickhankz2244
@tompatrickhankz2244 Год назад
I really need that scheduler... I want to terminate the instance at 1am and then start it at 6am.. I want to do it repeatedly... Hope you can help me with that
@AWSTrainingByGauravAgrawal
@AWSTrainingByGauravAgrawal Год назад
@@tompatrickhankz2244 how comfortable r u with AWS ?? And with writing a AWS lambda ??
@tompatrickhankz2244
@tompatrickhankz2244 Год назад
@@AWSTrainingByGauravAgrawal Am not that comfortable but i can try.. With help of a video
@baranlirath5949
@baranlirath5949 Год назад
Nice video sir, in this way we can automate lot of mannual things.Any documents for lamda we can go through.
@AWSTrainingByGauravAgrawal
@AWSTrainingByGauravAgrawal Год назад
yeah, here is the aws doc - aws.amazon.com/lambda/ - Also i will be creating an entire course, so please feel free to subscribe to the channel.
Далее
AWS S3 Event Notifications with SNS and SQS
14:11
Просмотров 3 тыс.
AWS SQS vs SNS vs EventBridge - When to Use What?
22:37
Amazon EventBridge Pipes - A Crash Course
28:44
Просмотров 3,8 тыс.
AWS EventBridge with Shopify, Custom events
34:46
Просмотров 5 тыс.
AWS Lambda : Schedule Using Eventbridge Rule
12:16
Просмотров 16 тыс.
Send Email using SQS, Lambda and SES
17:07
Просмотров 2,8 тыс.