Use hop like the aws command
hop doesn’t replace the AWS CLI: it runs it for you. hop acme-prod <args>
runs aws <args> with the alias’ profile and region set, after making sure
you are signed in. Anything you can do with aws, you can do with hop.
The rule
Section titled “The rule”Take any aws command, replace aws with hop <alias>, and remove
--profile (the alias already says which account and role):
aws s3 cp report.csv s3://acme-reports/ --profile acme-prodhop acme-prod s3 cp report.csv s3://acme-reports/With no arguments, hop <alias> runs aws sts get-caller-identity, a quick
“who am I?”:
hop acme-prod{ "UserId": "AROAEXAMPLEID:you@acme.com", "Account": "123456789012", "Arn": "arn:aws:sts::123456789012:assumed-role/AWSReservedSSO_AdministratorAccess_abc123/you@acme.com"}Everything passes through
Section titled “Everything passes through”| You use | It works because |
|---|---|
Any service and subcommand (s3, ec2, eks, logs tail --follow, …) |
The arguments go to aws untouched |
--region eu-west-1 |
It overrides the alias’ region for that command only |
--output json, --query, --no-cli-pager |
They are aws options, passed as is |
Pipes and redirects: hop acme-prod s3 ls | grep logs |
Standard output is aws’s own; cloudhop writes its messages to standard error |
| Interactive commands and prompts | Standard input goes straight to aws |
| Ctrl+C | It stops aws, as usual |
Exit codes in scripts (if hop acme-prod s3 ls ...) |
hop returns the exit code of aws |
What cloudhop adds around the command
Section titled “What cloudhop adds around the command”- Finds the alias: account, role and region.
- Checks the session. If it expired, cloudhop renews it silently, or opens the browser and waits for you to sign in.
- Runs
awswithAWS_PROFILEandAWS_REGIONset to the alias. Access keys inherited from your shell (AWS_ACCESS_KEY_IDand friends) are ignored so they can’t silently override the alias. - Retries once if
awsstill reports an expired session, after signing you in again.
So a command never starts with a session cloudhop already knows is expired.
In scripts
Section titled “In scripts”hop works in shell scripts and Makefiles exactly like aws:
#!/usr/bin/env bashset -euo pipefail
for alias in acme-prod acme-dev; do echo "== $alias" hop "$alias" s3 ls --output text | wc -ldoneIf a session expired, the script stops at the first hop and opens the
browser; once you sign in, it continues.
Other tools, not aws
Section titled “Other tools, not aws”For Terraform, the SDKs or any other program, use the alias’ profile
(AWS_PROFILE=acme-prod) or cloudhop exec. See
Use with other tools.
cloudhop exec acme-prod -- terraform plan- Tab completion:
hop acme-prod s3 <Tab>doesn’t complete AWS subcommands. If you rely on completion,aws --profile acme-prod ...works too, because the alias is a real profile (for company portals). - Another region once:
--regionat the end is enough; to change it for good, usecloudhop region acme-prod <region>. - Several accounts side by side: each
hopcall is independent, so two terminals can use two aliases at the same time.