━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
- Install AWS CLI v2 (
aws --version) - Configure AWS SSO profiles in
~/.aws/config(must includesso_account_idandregion) - Install
jqfor JSON parsing - Install
expectfor file upload functionality (macOS:brew install expect) - Install
nc(netcat) for file transfers (usually pre-installed on macOS/Linux)
Example AWS profile (in ~/.aws/config):
[sso-session my-session]
sso_start_url = https://example.awsapps.com/start
sso_region = us-east-1
sso_registration_scopes = sso:account:access
[profile my-sso-profile]
sso_session = my-session
sso_account_id = 123456789012
sso_role_name = ReadOnly
region = us-east-1
output = json━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
- Decide how you want to load the helpers:
- One-time (current shell only):
- Run:
- One-time (current shell only):
source /path/aws-cli-helpers/main.sh- Permanent (every new shell):
- Add to
~/.zshrc,~/.bashrc(or~/.bash_profile:
- Add to
Notes:
main.shexportsAWS_HELPERS_DIRand loads all helper functions and aliases.- An alias
sso_loginis created for convenience:sso_login <profile>.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-
aws_session -
Interactively select an AWS SSO profile (parses
~/.aws/configforsso_account_idandregion) -
Performs SSO login if not already authenticated
-
Ensures the SSM session document
SSM-SessionManagerRunShellexists (creates if missing usingtemplates/SessionManagerRunShell.json) -
Clears the terminal and displays account/profile/region in a styled table
-
Sets a helpful prompt showing
user@account:profile:region -
sso_login <profile>(alias)- Shortcut for
aws sso login --profile <profile>
- Shortcut for
-
ec2helper with subcommands:ec2 ls— list all EC2 instances (id, name, state)ec2 ls-running— list only running EC2 instancesec2 session <instance-id>— start an SSM shell session usingSSM-SessionManagerRunShellec2 port-forward <remote-port> <local-port> <instance-id>— start SSM port forwardingec2 upload <instance-id> <local-file> [remote-path] [port]— upload a file to an EC2 instance via SSM port forwarding- Arguments:
<instance-id>— EC2 instance ID (e.g.,i-0123456789abcdef0)<local-file>— Path to the local file to upload[remote-path]— (Optional) Remote file path (default:/home/ec2-user/<filename>)[port]— (Optional) Port number for transfer (default: random port 50000-59999)
- Features:
- Uses SSM port forwarding for secure file transfer
- Automatically creates remote directory if needed
- Displays file size and MD5 checksums for verification
- Verifies file was successfully uploaded
- Cleans up SSM sessions automatically
- Arguments:
-
ecshelper with subcommands:ecs clusters— list all ECS clustersecs services <cluster>— list services in a clusterecs tasks <cluster> [--running]— list tasks in a cluster (optionally only running)ecs service-tasks <cluster> <service> [--running]— list tasks for a specific serviceecs task-info <cluster> <task-id>— get detailed task information (status, container, image, uptime)ecs exec <cluster> <task-id> <container> [command]— execute command in a container (default: /bin/bash)ecs logs <cluster> <task-id> [--tail N]— get task information and container logsecs stop <cluster> <task-id> [reason]— stop a running taskecs describe <cluster> <service>— describe a service (status, running/desired count, task definition)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
- Load the helpers (see Setup above)
- Run
aws_session- Select your desired profile from the interactive list
- If prompted, complete SSO login in your browser
- Verify the printed table shows the expected Account, Profile, Region
- Use EC2 helpers as needed, for example:
ec2 lsec2 ls-runningec2 session i-0123456789abcdef0ec2 port-forward 5432 15432 i-0123456789abcdef0ec2 upload i-0123456789abcdef0 /local/file.txtec2 upload i-0123456789abcdef0 /local/file.txt /home/ec2-user/file.txtec2 upload i-0123456789abcdef0 /local/file.txt /home/ec2-user/file.txt 8888
- Use ECS helpers as needed, for example:
ecs clustersecs services my-clusterecs tasks my-cluster --runningecs service-tasks my-cluster my-service --runningecs task-info my-cluster abc123def456ecs exec my-cluster abc123def456 my-container /bin/bashecs exec my-cluster abc123def456 my-container ls -la /var/logecs logs my-cluster abc123def456ecs stop my-cluster abc123def456ecs describe my-cluster my-service
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
- Running
aws_sessionshows a bordered table with:- Correct AWS Account (formatted
XXXX-XXXX-XXXX) - Selected AWS Profile
- Current Region
- Identity ARN and User ID
- Correct AWS Account (formatted
ec2 lsoutputs instances data as JSON lines (viajq -r), without errorsec2 session <instance-id>starts an interactive SSM shell sessionec2 port-forward <remote-port> <local-port> <instance-id>starts an SSM port forwarding sessionec2 upload <instance-id> <local-file>uploads a file to the instance and displays verification (file size, MD5 checksums)ecs clusterslists all available ECS clustersecs services <cluster>lists services in the specified clusterecs tasks <cluster>displays a formatted table with task ID, status, container, and uptimeecs exec <cluster> <task-id> <container>starts an interactive shell in the containerecs describe <cluster> <service>shows service details in a table format- Your shell prompt updates to include
user@account:profile:region
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
-
jq: command not found- Install
jq(macOS:brew install jq)
- Install
-
aws: command not foundor AWS CLI v1 detected- Install
awscli(macOS:brew install awscli)
- Install
-
No profiles listed in
aws_session- Ensure your
~/.aws/configprofiles include bothsso_account_idandregion - Example provided in the Prerequisites section
- Ensure your
-
SSM session errors
- Ensure the instance has SSM agent installed and proper IAM role
- Ensure network/VPC endpoints allow SSM
- Confirm
SSM-SessionManagerRunShellexists (it is auto-created byaws_sessionif missing)
-
ECS exec command fails
- Ensure ECS Exec is enabled on the service (
enableExecuteCommand: true) - Verify the task role has required permissions for SSM
- Check that the container has a shell available at the specified path
- Ensure ECS Exec is enabled on the service (
-
ECS tasks showing incorrect uptime
- Ensure system time is synchronized
- Verify
jqversion supports time functions (jq 1.5+)
-
File upload fails
- Ensure
expectis installed (which expect) - Ensure
nc(netcat) is available on both local and remote systems - Verify the instance has SSM agent running and proper IAM permissions
- Check that the specified port is not already in use (script uses random port 50000-59999 by default)
- Ensure the remote directory path exists or can be created
- Ensure
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
main.sh— Entrypoint; exportsAWS_HELPERS_DIR, loads sessions and EC2/ECS helperssession.sh— Session orchestration: profile picker, SSO login, table display, SSM doc ensureservices/ec2.sh—ec2command group: list instances, SSM session, port forwarding, file uploadservices/_ec2_upload.sh— File upload script using Expect for SSM port forwarding transfersservices/ecs.sh—ecscommand group: clusters, services, tasks, exec, logs, stop, describetemplates/SessionManagerRunShell.json— SSM document used for interactive shell sessions
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
- Remove or comment the
source /path/aws-cli-helpers/main.shline from:~/.zshrc(Zsh) or~/.bashrc/~/.bash_profile(Bash)
- Restart your terminal (or re-source the rc file)