text: 29091/use-aws-cloudwatch-start-stop-ec2-instances-how-implement-it
  I am trying to figure out ways to start/stop a AWS EC2 instance in case of CPU utilization increase or decrease on another EC2 instance.
  I am familiar with service available Auto Scaling in AWS but I dont want to use these services.
  So just looking if it is possible.
  Just detailing the concern like suppose I have 2 EC2 instance on AWS account by name EC21 and EC22. By default, EC22 instance is stopped.
  Now I need to setup CloudWatch to check if load/CPU utilization increase on EC21 instance by 70% then need to start EC22 server and similarly if load decrease on EC21 instance by 30% then stop EC22 server.
  Please help!
  What you can do is set a CloudWatch alarm and check if it is triggered, it will notify an SNS topic.
  You can have that SNS topic then invoke a Lambda function, which can then start your EC2 instance.
  All you need to do is follow the following steps and you are good to go.
  Hi Hasan, this lambda function would do the job:
  import boto3
  region = 'es-east-1'
  instances = ['id']
  ec2 = boto3.client('ec2', region_name=region)
  def lambda_handler(event, context):
  ec2.stop_instances(InstanceIds=instances)
  print('stopped your instances: ' + str(instances))
  Have a look at this to configure CloudWatch:
  And, have a look at this to create an SNS topic:
  Nice article, very informative!
  I have a scenario ...READ MORE
  Hi@akhtar,
  To change the state of an EC2 ...READ MORE
  Hi@Lakshminarayanan,
  You can use InstanceState Data Types in your ...READ MORE
  Start by adding a new EC2 security group inbound ...READ MORE
  For configuration settings like instance type and ...READ MORE
  For some reason, the pip install of ...READ MORE
  You actually need to make changes to ...READ MORE
  Check if the FTP ports are enabled ...READ MORE
  Amazon has a handy page that details ...READ MORE
  You can check this link for a ...READ MORE
  OR
  Already have an account? Sign in.