How can I use ssh with AWS ssm sessions and multi profiles?

Viewed 549

With the explosion of multi-account AWS configuration, and ssh being snuffed out in favor of session manager, I need ssh functionality and multi-profile ProxyCommand.

From aws docs it's simple enough. But I can see now way to add extra args to specify a profile. All I can think of is essentially concatenating the profile to the instanceid and creating dedicated commands.

The question: How can I support multiple profiles using aws ssm when the proxycommand doesn't seem to offer me extra args?

Example that I would like: ssh ec2-user@i-18274659f843 --profile dev Because the i-* doesn't indicate what account profile to use

1 Answers

Assuming you're using the example below in your ssh/config, you can just define AWS_PROFILE environmental variable before connecting to the desired instance

host i-* mi-*
    ProxyCommand sh -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"

terminal:

$ export AWS_PROFILE=bernard
$ ssh i-12345
Related