AWS EventBridge Service - process AWS events

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ม.ค. 2025

ความคิดเห็น • 20

  • @indranilgoswami1500
    @indranilgoswami1500 5 หลายเดือนก่อน +1

    Thanks sir..very good explanation.

  • @nikafiq310
    @nikafiq310 ปีที่แล้ว +1

    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

  • @shrutiagrawal5012
    @shrutiagrawal5012 ปีที่แล้ว +1

    👍🏻

  • @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.

  • @tompatrickhankz2244
    @tompatrickhankz2244 ปีที่แล้ว +1

    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

  • @sahabsinghlathwal5956
    @sahabsinghlathwal5956 ปีที่แล้ว +1

    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  ปีที่แล้ว

      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 ปีที่แล้ว

      I'm waiting for your response for above queries.

    • @AWSTrainingByGauravAgrawal
      @AWSTrainingByGauravAgrawal  ปีที่แล้ว

      @@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 ปีที่แล้ว

      @@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 ปีที่แล้ว

      Can you plz fix this code and help for another which I asked you for tagging and security group?

  • @sudsrmsee
    @sudsrmsee ปีที่แล้ว +1

    super > keep it up