DEV Community 👩‍💻👨‍💻

Dinesh Rathee
Dinesh Rathee

Posted on • Updated on

Via AWS CLI-☁️📢Automating my post - Using AWS Systems Manager Automation Document🧐to fix✅SSH issue on a Linux EC2 Instance👨‍💻👩‍💻

How to execute actions listed under Post using AWS CLI

We've followed AWS Console Steps to use AWS Systems Manager Automation Document - "AWSSupport-ExecuteEC2Rescue" to fix SSH issue on a Linux EC2 Instance.

To check console steps , please click below link
How to use AWS Systems Manager Automation Document - "AWSSupport-ExecuteEC2Rescue" to fix SSH issue on a Linux EC2 Instance

Now, I will be explaining you how we can achieve this using AWS CLI commands using simple steps:

CMD Line

Make sure you have AWS CLI setup and you've enough permissions to use SSM to execute these documents.
If you have admin privileges , it will be great !

  • If you would like to know how to install and configure AWS CLI, please refer this link

  • Steps Using AWS CLI:


    • Running the Automation Document for an unreachable Instance (i-xxxxxxxxx) :

    # aws ssm start-automation-execution --document-name "AWSSupport-ExecuteEC2Rescue" --document-version "\$DEFAULT" --parameters '{"UnreachableInstanceId":["i-xxxxxxxxxxxxx"],"EC2RescueInstanceType":["t2.small"],"SubnetId":["CreateNewVPC"]}' --region eu-west-2
    {
        **"AutomationExecutionId": "43f1918f-b0bb-4a25-xxxxxxxxxxxxx"**
    }
    
    Enter fullscreen mode Exit fullscreen mode

    • You can also see the automation scheduled (using Console)

    01

    • Checking the Automation progress / Status:

    # aws ssm get-automation-execution --automation-execution-id "43f1918f-b0bb-4a25-xxxxxxxxxxxxxxxx" --output text --query "AutomationExecution.AutomationExecutionStatus"  --region eu-west-2
    **InProgress**
    
    Enter fullscreen mode Exit fullscreen mode

    • Let’s wait for few mins to get this completed and we can check the status again:

    # aws ssm get-automation-execution --automation-execution-id "43f1918f-b0bb-4a25-xxxxxxxxxxxxxx" --output text --query "AutomationExecution.AutomationExecutionStatus"  --region eu-west-2
    **Success**
    
    Enter fullscreen mode Exit fullscreen mode

    • You can also verify this (using Console)

    02

    • After the Status is returned as “Success”, Let’s try to SSH to the Instance again: (Success)

    # ssh -i "eu-west-2_key_pair.pem" ec2-user@ec2-xxxxxxxxx.eu-west-2.compute.amazonaws.com
    
    Enter fullscreen mode Exit fullscreen mode

    03

    Conclusion

    AWSSupport-ExecuteEC2Rescue is a new Automation document that automates all the steps required to fix common issues on your unreachable Windows & Linux instance using respective EC2Rescue for Linux & EC2Rescue for Windows tool tools, which is a framework for executing diagnostic and troubleshooting modules for analyzing and remediating issues.

    Overall, It will save a lot of time which is being invested with manual process of detach, attach volume and further steps to troubleshoot issues. This document does all the steps for you in an automated way in just few minutes.

    Tip

    With the integration between CloudWatch Events and Systems Manager
    Automation, you can run AWSSupport-ExecuteEC2Rescue automatically in
    response to an event in your infrastructure.

    SSH issue Fixed

    Thanks for reading.
    Any feedback, please write it to me here in comments..
    Also, 🤝🤗You can connect with me🤝🤗

    Top comments (0)

    All DEV content is created by the community!

    Hey, if you're landing here for the first time, you should know that this website is a global community of folks who blog about their experiences to help folks like you out.

    Sign up now if you're curious. It's free!