8000 GitHub - ikedam/awsexec: awsexec is a tiny tool to run command wrapped with aws configure export-credentials · GitHub
[go: up one dir, main page]

Skip to content
ikedamPublic

About

awsexec is a tiny tool to run command wrapped with aws configure export-credentials

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

awsexec: execute command with aws configure export-credentials

日本語

Background

  • AWS CLI provides aws configure export-credentials command, 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.

  • Passing the output of the aws configure export-credentials command to applications requires multiple steps. These steps are often tedious and require some basic knowledge of shell scripting.

    1. Execute aws configure export-credentials.
    2. Set the output credentials as environment variables.
    3. Execute the target command.
  • awsexec is a very simple wrapper program that automates these steps.

awsexec Implementation and Distribution Policy

  • Two distribution formats are provided.

    1. Single binary built with golang (GitHub Releases)
    2. 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.

Prerequisites

Installation

Binary Installation (Download)

  • 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:

    1. Download the binary:

      curl -L -o /tmp/awsexec https://github.com/ikedam/awsexec/releases/download/latest/awsexec_linux_amd64
    2. Place the binary:

      sudo cp /tmp/awsexec /usr/local/bin/awsexec
    3. Grant execute permission to the binary:

      chmod +x /usr/local/bin/awsexec

Binary Installation (Build)

  • 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:

    1. Build the binary:

      GOOS=darwin GOARCH=arm64 docker compose run --rm build
    2. Place the binary:

      sudo cp build/awsexec /usr/local/bin/awsexec

Shell Script Installation

  • 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:

    1. Download the shell script:

      curl -L -o /tmp/awsexec.sh https://raw.githubusercontent.com/ikedam/awsexec/refs/heads/main/awsexec.sh
    2. Place the shell script:

      sudo cp /tmp/awsexec.sh /usr/local/bin/awsexec
    3. Grant execute permission to the shell script:

      chmod +x /usr/local/bin/awsexec

Usage

  • 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_PROFILE environment variable:

    AWS_PROFILE=profile awsexec -- command
    • To avoid using the wrong profile, specifying the AWS_PROFILE environment variable is required.
    • If you don't need to use multiple profiles, you can set AWS_PROFILE=default in your user profile.

Environment Variables Set for the Subprocess

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), and AWS_CREDENTIAL_EXPIRATION (when available) are set from the result of aws configure export-credentials.
  • AWS_PROFILE reset: The subprocess receives credentials via the environment variables above, so the parent's AWS_PROFILE is not inherited. This ensures the subprocess uses only the provided credentials, not profile-based resolution.
  • Region: AWS_DEFAULT_REGION and AWS_REGION are set when a value is available. The value is determined in this order: (1) the region setting for the chosen profile in ~/.aws/config, (2) the parent's AWS_DEFAULT_REGION, (3) the parent's AWS_REGION. If none are set, these variables are not added.

Building the Binary

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

License

This application and source code are distributed under the MIT License.

About

awsexec is a tiny tool to run command wrapped with aws configure export-credentials

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0