I have a EC2 instance with a dynamic IP and I would like to connect to it directly without having to modify the .ssh/config
every time it changes.
I can query the ip with
aws ec2 describe-instances --filters 'Name=tag:Name,Values=MYTAG' --query 'Reservations[0].Instances[0].NetworkInterfaces[0].Association.PublicIp' --output text
Now, I want to add this command to the ProxyCommand
section in my .ssh/config
file but I'm getting some errors.
This is the section for that host
Host ec2-instance
User ubuntu
IdentityFile my/pem/file.pem
ProxyCommand bash -c "host=$(aws ec2 describe-instances --filters 'Name=tag:Name,Values=MYTAG' --query 'Reservations[0].Instances[0].NetworkInterfaces[0].Association.PublicIp' --output text); ssh ${host}"
I honestly don't know how the ProxyCommand
option works and neither man ssh
or man ssh_config
seems to do a good job explaining it.
can this be achieved?