Via AWS CLI-☁️📢Automating my post - Using AWS Systems Manager Automation Document🧐to fix✅SSH issue on a Linux EC2 Instance👨‍💻👩‍💻
Tags: aws, linux, devops
Published: 2020-07-20 00:48:52

### <b> How to execute actions listed under [Post](https://dev.to/dineshrathee12/how-to-use-aws-systems-manager-automation-document-to-fix-ssh-issue-on-a-linux-ec2-instance-7n3) using AWS CLI</b>

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***
<b><a href="https://dev.to/dineshrathee12/how-to-use-aws-systems-manager-automation-document-to-fix-ssh-issue-on-a-linux-ec2-instance-7n3" target="_blank"> How to use AWS Systems Manager Automation Document - "AWSSupport-ExecuteEC2Rescue" to fix SSH issue on a Linux EC2 Instance</a>

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

![CMD Line](https://media.giphy.com/media/26gssNZ4EF6c8Simk/giphy.gif)

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

<li>If you would like to know how to install and configure AWS CLI, please refer <b><a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html" target="_blank"> this link </a></b></li>



***

### <b>Steps Using AWS CLI:</b>

***

•	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"**
    }

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

![01](https://dev-to-uploads.s3.amazonaws.com/i/ks0lcz7cptp3z8wiv5xk.jpg)

•	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**

•	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**

•	You can  also verify this **(using Console)**

![02](https://dev-to-uploads.s3.amazonaws.com/i/hskm6gmwmoemx5bbsnwi.jpg)

•	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

![03](https://dev-to-uploads.s3.amazonaws.com/i/2gbkj9hea5r5o1egz1t4.jpg)


### <b>**Conclusion**</b>
**[AWSSupport-ExecuteEC2Rescue](https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-awssupport-executeec2rescue.html)**  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](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Linux-Server-EC2Rescue.html)** &  **[EC2Rescue for Windows](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/Windows-Server-EC2Rescue.html)** tool tools, which is a framework for executing diagnostic and troubleshooting modules for analyzing and remediating issues.

<code>**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.</code>

<b>Tip</b>
> 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](https://media.giphy.com/media/11kcEW8uNh8RwY/giphy.gif)

<b>Thanks for reading.<b>
Any feedback, please write it to me here in comments..
<b>Also, 🤝🤗You can connect with me🤝🤗</b>
<ul>
<li><b><a href="https://www.linkedin.com/in/%E2%80%8Bdineshrathee12" target="_blank">LinkedIn</a></li>
<li><b><a href="https://dev.to/dineshrathee12" target="_blank">DevTo</a></li>
<li><b><a href="https://github.com/dineshrathee12" target="_blank">GitHub</a></li>
<li><b><a href="https://twitter.com/dinesh_rathee12" target="_blank">Twitter</a></li>
</ul>