Christian Bongiorno
Christian Bongiorno

Reputation: 5648

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

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

Upvotes: 2

Views: 1490

Answers (2)

Denis
Denis

Reputation: 174

You don't have to export. You can use it like this: AWS_PROFILE=bernard ssh ubuntu@i-xxxx

The value of AWS_PROFILE will be valid only for this command and will save you from later issues with AWS commands, i.e. for other profiles.

In the same way you can set the region: AWS_REGION=us-east-1 AWS_PROFILE=bernard ssh ubuntu@i-xxxx

Upvotes: 2

b.b3rn4rd
b.b3rn4rd

Reputation: 8830

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

Upvotes: 3

Related Questions