Skip to content

Scheduled Start and Stop of EC2 Instance: Start Works, but Stop Does Not

0

Title: Scheduled Start and Stop of EC2 Instance: Start Works, but Stop Does Not

Description:

I'm trying to schedule my EC2 instance to start at 9:15 AM and stop at 7:00 PM using EventBridge. Both actions are scheduled using separate EventBridge rules that invoke APIs directly, specifying the InstanceId.

What I've Done:

  • Configured two EventBridge schedules:
    • Start Rule: Triggers the StartInstances API at 9:15 AM UTC.
    • Stop Rule: Triggers the StopInstances API at 7:00 PM UTC.
  • Verified the InstanceId in both rules.
  • Ensured that the IAM permissions for the associated role seem adequate.
  • Both schedules use UTC time for consistency.

Issue:

The start rule works perfectly, but the stop rule does not trigger the action. I’ve reviewed the documentation but cannot determine why the stop action isn’t working.

Additional Context:

I've created a document outlining my setup and configuration for better understanding. You can access it here: My Setup Document.

Could you help identify what might be going wrong or suggest steps to debug the issue?

asked a year ago665 views
4 Answers
2

Based on the information provided, there are a few potential reasons why your stop rule might not be working as expected while the start rule is functioning correctly. Here are some suggestions to help identify and resolve the issue:

  1. Check EventBridge rule execution: Verify that the stop rule is actually being triggered at the scheduled time. You can do this by checking the CloudWatch Logs for the rule execution or by adding a CloudWatch Logs action to your rule for debugging purposes.

  2. Verify instance state: Ensure that the instance is in a 'running' state when the stop rule is scheduled to execute. Resource Scheduler (and by extension, EventBridge rules) only stops instances if they are in the 'running' state. If the instance is already stopped or in any other state, the stop action won't take effect.

  3. Review IAM permissions: Although you mentioned that IAM permissions seem adequate, double-check that the IAM role associated with the EventBridge rule has the necessary permissions to stop EC2 instances. The required permission is 'ec2:StopInstances'.

  4. Check for conflicting schedules: Ensure that there are no other automation tools or schedules that might be interfering with the stop action. For example, if you have multiple schedules or automation scripts running, they might be conflicting with each other.

  5. Verify the correct instance ID: Double-check that the instance ID specified in the stop rule is correct and matches the instance you're trying to stop.

  6. Monitor CloudTrail logs: Review AWS CloudTrail logs to see if there are any failed API calls or permission issues related to the StopInstances API action.

  7. Test manual stop: Try stopping the instance manually at the scheduled stop time to ensure there are no issues with the instance itself that might prevent it from stopping.

  8. Consider using Systems Manager Resource Scheduler: As an alternative to custom EventBridge rules, you could use AWS Systems Manager Resource Scheduler, which is designed specifically for scheduling start and stop actions for EC2 instances. This service handles the complexities of instance state management and scheduling.

If none of these steps resolve the issue, you may want to consider creating a new stop rule from scratch to eliminate any potential configuration errors in the existing rule. Additionally, reaching out to AWS Support might be helpful if the problem persists after trying these troubleshooting steps.
Sources
Stop and start EC2 instances automatically on a schedule using Quick Setup - AWS Systems Manager
Stop and start Amazon EC2 instances - Amazon Elastic Compute Cloud

answered a year ago
EXPERT
reviewed a year ago
  • I created 2 eventbridge scheduler for start & stop purpose both have same rule. 1 is working other is not. please check the word file as well .

1
Accepted Answer

In your word doc you are using 1am and not 1pm for the UTC Time. It is powering off at 1 am and then your powering it back on at 3am.

Update your CRON schedule for stop to be 13 and not 1

You may find they are powering off at 7am and powering back on at 9am because of this instead of 7pm

EXPERT
answered a year ago
  • Thx yesterday I also came to same conclusion, when I used eventbridge with lambda to stop the server. my lambda also not invoked.

  • I’m glad you’re able to resolve your issue. All the best. Gary

0

Please share rule screenshots along with the eventbridge targets. I do this a lot and have no issues. Id also check cloudtrail logs to make sure the Role issuing the STOP has the correct IAM access

EXPERT
answered a year ago
  • Please check the documentation titled "My Setup Document", where I have included screenshots of the target configuration and role permissions.

    Additionally, I am using EventBridge Scheduler, so I haven’t created any EventBridge rules. (Using API CALL) EventBridge Scheduler->cron setup->All API->ec2->StopInstances.

  • Appologies I missed that

  • Read word doc.. Created new answer.. I May have spotted an issue

0

Hi,

You want to check this doc to see how to troubleshoot EC2 instances not stopping: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesStopping.html

This KC question may also prove useful in your case: https://repost.aws/knowledge-center/ec2-instance-stuck-stopping-state

Best,

Didier

EXPERT
answered a year ago
EXPERT
reviewed a year ago
  • not helpful, These all are method if you server is stuck. but my server is running I want to stop it at specific time using eventbridge scheduler only.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.