Is it possible to set Docker Swarm using my local machine as Master and AWS EC2 instances as worker node

I unable to setup the Docker Swarm cluster using below the machines.
Docker Swarm master : my local machine (ubuntu 16.04 LtS)
Docker Swarm.work.nodes : two AWS EC2 instances.

I have installed Docker on all three instances and but I unable to join the AWS ec2 instances to my docker swarm manager running on my local machine.

Getting connection refused.please help.

Your local machine is probably running behind a NAT. So to make it “work”, you shoud export your port 2377 over that NAT.
A huge warning though : that would be a large security issue. Beside, since the servers are far away (network wise at least) latency will be an issue and your cluster might not behave as expected (swarm is not meant to create geo-cluster).

So while it might be possible to make it works, it’s far from the best idea…

I couldn’t agree more.

Even if you manage to mitigate the security risk by using mTLS, the problem remains that the consensus algorithm underneath is not designed for wide area communication. Swarm uses RAFT, which is designed for low latency networks for health check, master election, and a data synchronisation and more…

Though, if controlling the ec2 instance as a independend node is an option, you might want to take a look at Portainer and run the ec2 instance as an “Edge Agent”.