How to stop/start an EC2 instance on a schedule within an autoscale group without terminating the instance?

前端 未结 2 1885
孤街浪徒
孤街浪徒 2021-01-26 12:29

If you have have an autoscaling group, how do you go about start/stopping the instances (not launch/terminate) ? The default behaviour is only for launching an

2条回答
  •  北荒
    北荒 (楼主)
    2021-01-26 12:35

    You may consider to run your script using AWS Data Pipeline.
    Use this script to retrieve instance ID as well as availability zone and region, etc

    Choose Create New Pipeline and enter the following information:

    Name: for example, "Start EC2 instances" and "Stop EC2 instances".
    Description: Provide relevant details about the pipeline as needed.
    Source: Choose Build using template and choose the template Run AWS CLI command.
    AWS CLI command: This is where you put your script to specify what the pipeline does.
    

    Configure each pipeline with appropriate scheduling information.

    Run: Choose on activation to run the pipeline as an on-demand pipeline.  
    Run every: Enter a period for every pipeline run.
    Starting: Enter a time and date for the pipeline to start.
    Ending: Enter a time and date for the pipeline to end.
    

    Set the following options for implementing appropriate security access:

    IAM Roles: Choose Custom
    Pipeline Role: DataPipelineDefaultRole
    EC2 Instance Role: DataPipelineDefaultResourceRole
    

    Note that Data Pipeline creates the necessary IAM Roles for you.
    For more information, see AWS Data Pipeline Pricing.

    See also other option using AWS Lambda.

提交回复
热议问题