Skip to main content

swaj

"If you watch the movie Jaws backwards, it's a movie about a shark that keeps throwing up people until they have to open a beach."

swaj is a tool to simplify using multiple sets of credentials with AWS. If you have multiple profiles, swaj eliminates the need to constantly re-export values when using MFA or SSO. swaj is especially helpful when using MFA in that it persists the temporary session credentials, minimizing the number of times an OTP code must be entered.

Requires python.

If you'd like to use the built-in TOTP functionality (instead of an app, like Google Authenticator or Authy), you'll also need to install pyotp, like so: pip install pyotp.

Install

$ curl https://raw.githubusercontent.com/f0rk/swaj/master/tools/swaj-standalone > ~/bin/swaj
$ chmod +x ~/bin/swaj

Configuration

If you wish to use swaj to more safely use profiles, no additional configuration is needed.

If you wish to use an MFA device (currently, the AWS API only supports software-based devices), place the serial of that device in your ~/.aws/config like so:

[profile dev]
region = us-west-1
mfa_serial = arn:aws:iam::000000000000:mfa/jimmy

Additionally, if you wish to assume a role, you can configure it like so:

[profile admin]
region = us-west-1
mfa_serial = arn:aws:iam::000000000000:mfa/jimmy
swaj_role_arn = arn:aws:iam::000000000000:role/admin

This usage is non-standard but is a workaround for a bug in botocore.

Using SSO is straightforward, just configure your SSO normally and swaj will ensure you are authenticated.

Usage

swaj works with profiles as defined in your ~/.aws/config. It does not support other modes of operation. You must either set AWS_PROFILE in your environment or pass --profile yourprofile to it.

swaj will get everything squared away with MFA and then run your command with the determiend credentials:

$ swaj --profile dev exec aws s3api list-buckets               
enter token for mfa_serial arn:aws:iam::000000000000:mfa/jimmy: 123456  
{                                                     
    "Buckets": [
        {
            "Name": "bananaphone",            
            "CreationDate": "2020-05-08T01:01:01.000Z"
        },
    ],
    "Owner": {
        "DisplayName": "jimmysworld",
        "ID": "0000000000000000000000000000000000000000000000000000000000000000"
    }
}

Subsequent runs will not prompt you for MFA credentials:

$ swaj --profile dev exec aws s3api list-buckets               
{                                                     
    "Buckets": [
        {
            "Name": "bananaphone",            
            "CreationDate": "2020-05-08T01:01:01.000Z"
        },
    ],
    "Owner": {
        "DisplayName": "jimmysworld",
        "ID": "0000000000000000000000000000000000000000000000000000000000000000"
    }
}

Perhaps, though, you just want to set the credentials in your environment. To get the credentials you could run:

$ swaj --profile dev env
...
AWS_SECRET_ACCESS_KEY=...
AWS_SESSION_TOKEN=...
AWS_ACCESS_KEY_ID=...
AWS_SESSION_EXPIRATION=...
...

For convenience, you can use the eval subcommand to simplify:

$ eval $(swaj --profile dev eval)
$ env | grep AWS
... 
AWS_SECRET_ACCESS_KEY=...
AWS_SESSION_TOKEN=...
AWS_ACCESS_KEY_ID=...
AWS_SESSION_EXPIRATION=...
...

Metadata

Release files for swaj 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for swaj 1.0
File Interpreter ABI Platform Actions
swaj-1.0-py3-none-any.whl Python 3 none any Details for swaj-1.0-py3-none-any.whl

Release files / swaj-1.0-py3-none-any.whl

Download URL swaj-1.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
43834f9eb357f57bdda404ae051ea7dcd17e8fca1a2cc0a67b1268ceea900882
BLAKE2b-256 checksum
How to use checksums
99f4845e9b205a4e0548a54a35d2c49df845ec0d292903d82430722de61a2ac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Security for swaj 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page