Hello, today a quick tutorial about AWS Session Manager and Amazon SSM Agent. If you are having problems connecting to EC2(Windows system), by Session Manager then you should read this article to the end. You will learn from it how I deal with such problems.

Before you start
Before you start, make sure you have a role connected to EC2 with the correct permissions. What those permissions should be, you’ll learn from this article: https://lepczynski.it/en/aws_en/session-manager-in-amazon-web-services-aws/
Fixing a problem with Session Manager
It often turned out that the Session Manager was having problems because the SSM Agent was not running.
How to fix it? What can be done to make it work?
Well, I connected via VPN to AWS and then to my machine via RDP. You should use a VPN, but if for some reason you don’t, just log into EC2 using RDP.
1) Situation when you are lucky

On EC2, open the services. If you just click start on Amazon SSM Agent
and it works, you’re in luck. Just make sure the agent still has the auto-start option enabled, otherwise the problem will persist.
2) A situation where you are not so lucky

If you are not so lucky and the agent is not starting up, but is throwing errors, maybe the problem is in the routing table. Turn on PowerShell and paste these 2 commands:

Import-Module "C:\ProgramData\Amazon\EC2-Windows\Launch\Module\Ec2Launch.psd1"
Add-Routes
This should fix the routing table. Now when you run the SSM agent it should work, at least it helps me.
3) Situation when you are unlucky
If by some miracle you still have the problem, you’ll have to look in the logs, unfortunately. You’ll usually find them in the directory …ProgramData\Amazon\SSM\Logs
…

Of course, you can also try removing the agent and reinstalling it.
Summary
It was an AWS Quick Advice article. If I helped and you like such short, quick tips, let me know in the comments.
I will then share a solution to more bugs that I encounter every now and then.