Eventbridge Scheduler - Automatically shutdown EC2 machines on weekend

Поділитися
Вставка
  • Опубліковано 18 жов 2024

КОМЕНТАРІ • 20

  • @shrig018
    @shrig018 10 місяців тому +1

    great video! helped me out a lot. was using event scheduler as a starting point and the process just seemed so confusing! many thanks

    • @AWSTrainingByGauravAgrawal
      @AWSTrainingByGauravAgrawal  10 місяців тому

      Glad it helped!

    • @shrig018
      @shrig018 10 місяців тому

      Any idea how I can see the logs? When I go to cloudwatch logs I get error saying the log group does not exist

  • @that_epics
    @that_epics 10 місяців тому +1

    I need your one more help can you please help me out:
    Q. How can I getcustomised email notifications when someone creates an EC2 instance that’s not nano, micro, small or medium? can you please help me out...

    • @AWSTrainingByGauravAgrawal
      @AWSTrainingByGauravAgrawal  10 місяців тому

      Please refer to this video - ua-cam.com/video/XGkm2BwNpyI/v-deo.html
      For your requireement, the flow will be - EC2 Service -> listen to EC2 create instance events in Eventbridge --> Trigger lambda --> Send email to an group or whoever you want.

  • @01_Keren
    @01_Keren 10 місяців тому

    Is it possible to do that directly without using a lambda for shutting down ec2?

    • @15724388200
      @15724388200 10 місяців тому

      No you cannot do it without a compute instance. you need a way to run some code which will trigger the shutdown command to the correct set of instances and thats where lambda's come in. They are on demand and you only pay for the time it is running, so it actually very cost effective.

    • @that_epics
      @that_epics 10 місяців тому

      we can do it with Azure DevOps pipeline completely free

    • @tapiaomars
      @tapiaomars 3 місяці тому

      yeah, you can do it without using a lambda... no compute, just use event bridge for EC2 stop (not lambda), obviously you need IAM Role for your Scheduler (trusted policy for scheduler and IAM policy for actions on ec2) .... and you have a EC2 scheduler without lambda now guy :)

  • @kapilghule751
    @kapilghule751 11 місяців тому

    please give me a script for how to start multiple EC2 instances?

    • @AWSTrainingByGauravAgrawal
      @AWSTrainingByGauravAgrawal  11 місяців тому +1

      If you know the list of ec2 instance id's then you can run the following aws command -
      aws ec2 start-instances --instance-ids i-INSTANCE_ID1 i-INSTANCE_ID2 i-INSTANCE_ID3

    • @that_epics
      @that_epics 11 місяців тому +1

      @@AWSTrainingByGauravAgrawal ​Sure I can use that, however, I would like a script like you mentioned Python script, for example, to shut down the instance and I would use multiple instance IDs to auto-start the instance. Is it possible to get a complete Python script to auto-start the instance? it will be very helpful for me

    • @AWSTrainingByGauravAgrawal
      @AWSTrainingByGauravAgrawal  11 місяців тому +1

      @@that_epics use the below python lambda code
      import boto3
      def lambda_handler(event, context):
      # Create a Boto3 EC2 client
      ec2 = boto3.client('ec2')
      # Describe all instances in your account
      instances = ec2.describe_instances()
      # Extract instance IDs from the response
      instance_ids = []
      for reservation in instances['Reservations']:
      for instance in reservation['Instances']:
      instance_ids.append(instance['InstanceId'])
      # Start all instances
      if instance_ids:
      ec2.start_instances(InstanceIds=instance_ids)
      return f'Starting instances: {instance_ids}'
      else:
      return 'No instances to start'
      # Note: Make sure that your Lambda function has the appropriate IAM permissions to describe and start EC2 instances.

    • @that_epics
      @that_epics 11 місяців тому

      ​@@AWSTrainingByGauravAgrawalSorry I am bothering you but where is the name of the tag like start=true and where I can mention only two or three examples of the ID is only.

    • @that_epics
      @that_epics 11 місяців тому

      Earlier script you mentioned tags to stop each instance