Search code examples
shzsh

How can I avoid typing in the profile for aws each time?


I want to avoid typing --profile dev-platform every time I want to access the AWS cli commands.

How do I add a postfix or suffix like --profile dev-platform every time I want to run an AWS command?

I just want to type aws s3 ls with out manually putting in the profile each time like the above two instances.

aws *wild card* --profile dev-platform

I tried some things like

alias aws= aws ** | --profile dev-platform

but to no avail.


Solution

  • Assuming you have multiple profiles in your ~/.aws/config, and want to set dev-platform as the profile to use for your terminal session you can use:

    export AWS_DEFAULT_PROFILE=dev-platform
    

    This will set the default AWS profile to the selected profile for your terminal session.

    I switch between multiple profile regularly and create aliases for my different profiles so I can use a short command like use-dev to switch to my dev profile, or use-prod, to switch to my production profile quickly and easily without having to type the full command.