Let’s say you have an instance A and instance B either in the same account or different accounts. I am making a script I was wondering how I can you use boto3 and guarantee that both instances can communicate through a given port or protocol. I am thinking may be I have to first check SGs/NACLs for each instance in the script.
You should be able to use boto3 to run a reachability analyser analysis, if you don’t want to evaluate routing tables etc yourself.
Here is the official doc: https://docs.aws.amazon.com/vpc/latest/reachability/what-is-reachability-analyzer.html
Why not just run a telnet, netcat, or curl command from one or each instance?
Not sure why boto3 is required here. One could simply use telnet to check connectivity between two instances on a given port.
A word of warning - it costs $0.10 for each time you analyze connectivity.
See https://aws.amazon.com/vpc/pricing/ (switch to tab “Network Analysis”
).
That was my thought. You’re checking if device X can connect to device Y via port Z. Just try to connect them and see what happens.
You can use this lambda function using boto3 (see handler.py). I was in a role where I was not allowed to connect to instances but had network rights. Used this function to verify connectivity and a port was listening
I was a network engineer and did not have rights to connect to instances. I used a lambda function as a workaround
Technically the case here, but if I was confused about how to do something, and asked a community about it, and someone just shoved this link in my face instead of illuminating what X even was in my case, I’d feel pretty discouraged.
Just check if the two instances are in the same VPC and no ACL’s are preventing access.. and that security goups allow access.
reachability analyzer
Wouldn’t that just be testing that the lambda can connect to 2 instances ? Not that instance 1 can connect to instance 2…
If I am not mistaken it does not have cross-account network analysis capability.
I guess you can do something like ssm session on 1 instance and run the telnet to the other instance and check the result on lambda
As long as the accounts are in the same org it can.
theres a feature that checks for reachability in the AWS dashboard, havent used it but im guessing this is also available in the API
If you can SSM to EC2, then you do have rights to connect to it AFAIK.
You can press the “connect” button, and it gives you different ways to connect. SSH, SSM, Serial…
It would help if you used the create_network_insights_path of the EC2 Boto3 client in your Lambda function to define your network path. Then use start_network_insights_analysis to analyze it and process results.