The 2 Ec2 instances would need to be able to see each other on the network. This means that you would need to have them in the same VPC and/or have whitelisting in place to allow that. Once this is done you would, as Sean suggested, set up SSH keys to allow that communication. This is effectively the same process that you would use for on prem servers and though the steps are a bit abstract they are essentially the same.
.How to access one ec2 instance from another ec2 instance without using the password with the help of SSH. I have created two instances with the same vpc and same .pem file. then added the user with the name of "Cloudlinux" and set the password for this user on both instances.
Cloudlinux@Server1} ssh Cloudlinux@server2hostname // I m getting the error.
$ ssh-copy-id -i ~/.ssh/id_rsa.pub Cloudlinux@XXXX.compute-1.amazonaws.com Permission denied (publickey).