ssh, aws, amazon linux 2,

Fix 'An error occurred (InvalidInstanceId) when calling the SendCommand operation: Instances not in a valid state for account'

Nov 13, 2022 · 1 min read · Post a comment

If you try to SSH into the EC2 instance through SSM parameter or if you want to setup a RDS tunnel, you might get the following error: An error occurred (InvalidInstanceId) when calling the SendCommand operation: Instances not in a valid state for account. So, it comes down to some of the scenarios described in the Solution section below.

Prerequisites

  • AWS Account
  • EC2 Access

Solution

The above error might be related to some of the following scenarios:

  1. Wrong Instance ID.
  2. If the Instance is in a different Region. To export your instance region execute:
    export AWS_DEFAULT_REGION=us-west-1
    
  3. If the Instance is not in a Running State.
  4. If the Instance doesn’t have ssm agent up and running.

Conclusion

In case you have some other suggestions don’t hesitate to raise them below. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.