-
AWS CLI provides
aws configure export-credentialscommand, which exports credentials in a format that can be set as environment variables. By executing the authentication process with AWS CLI and passing only the resulting credentials to applications, you can use authentication processes that are not directly supported by applications.- An example is the
aws logincommand supported from AWS CLI v2.32.0. Applications using older AWS SDKs cannot directly use credentials fromaws login, so credentials need to be passed to applications via theaws configure export-credentialscommand.
- An example is the
-
Passing the output of the
aws configure export-credentialscommand to applications requires multiple steps. These steps are often tedious and require some basic knowledge of shell scripting.- Execute
aws configure export-credentials. - Set the output credentials as environment variables.
- Execute the target command.
- Execute
-
awsexecis a very simple wrapper program that automates these steps.
-
Two distribution formats are provided.
- Single binary built with golang (GitHub Releases)
- Shell script (awsexec.sh)
-
Since this is a security-related feature, no external libraries are used.
- This is to avoid the need to check the safety of dependency libraries.
-
Pre-built binaries are provided as GitHub Releases Assets, but you can also build them in your own environment if Docker is installed. Also, if using the shell script, you can create it in your own environment by copying and pasting.
-
AWS CLI must be installed:
aws --version
-
If not installed, please install it according to AWS installation instructions.
-
AWS CLI v2.32.0 or later is recommended. The
aws logincommand is available.
-
-
Download the awsexec binary appropriate for your environment from GitHub Releases and place it in a location where the path is available.
-
For example, you can install it with the following steps:
-
Download the binary:
curl -L -o /tmp/awsexec https://github.com/ikedam/awsexec/releases/download/latest/awsexec_linux_amd64
-
Place the binary:
sudo cp /tmp/awsexec /usr/local/bin/awsexec
-
Grant execute permission to the binary:
chmod +x /usr/local/bin/awsexec
-
-
You can build the binary using Docker. The built binary will be generated at
build/awsexec. -
For example, you can build it with the following steps:
-
Build the binary:
GOOS=darwin GOARCH=arm64 docker compose run --rm build
-
Place the binary:
sudo cp build/awsexec /usr/local/bin/awsexec
-
-
If a shell script environment is available, you can also place the shell script in your own environment by copying and pasting.
- Usually available on Linux and macOS.
- Only available in WSL environment on Windows.
-
For example, you can install it with the following steps:
-
Download the shell script:
curl -L -o /tmp/awsexec.sh https://raw.githubusercontent.com/ikedam/awsexec/refs/heads/main/awsexec.sh
-
Place the shell script:
sudo cp /tmp/awsexec.sh /usr/local/bin/awsexec
-
Grant execute permission to the shell script:
chmod +x /usr/local/bin/awsexec
-
-
To specify a profile:
awsexec profile -- command- Executes the specified command with the credentials of the specified AWS profile set as environment variables.
-
To specify a profile using the
AWS_PROFILEenvironment variable:AWS_PROFILE=profile awsexec -- command- To avoid using the wrong profile, specifying the
AWS_PROFILEenvironment variable is required. - If you don't need to use multiple profiles, you can set
AWS_PROFILE=defaultin your user profile.
- To avoid using the wrong profile, specifying the
The following environment variables are set for the subprocess that awsexec runs:
- Credentials:
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_SESSION_TOKEN(when using temporary credentials), andAWS_CREDENTIAL_EXPIRATION(when available) are set from the result ofaws configure export-credentials. - AWS_PROFILE reset: The subprocess receives credentials via the environment variables above, so the parent's
AWS_PROFILEis not inherited. This ensures the subprocess uses only the provided credentials, not profile-based resolution. - Region:
AWS_DEFAULT_REGIONandAWS_REGIONare set when a value is available. The value is determined in this order: (1) theregionsetting for the chosen profile in~/.aws/config, (2) the parent'sAWS_DEFAULT_REGION, (3) the parent'sAWS_REGION. If none are set, these variables are not added.
You can build the binary using Docker. The built binary will be generated at build/awsexec.
-
Linux (amd64)
GOOS=linux GOARCH=amd64 docker compose run --rm build
-
Windows (amd64)
GOOS=windows GOARCH=amd64 docker compose run --rm build
-
macOS (arm64)
GOOS=darwin GOARCH=arm64 docker compose run --rm build
This application and source code are distributed under the MIT License.