Skip to main content

Login to AWS using CLI named profiles, IAM access key credentials, or SSO.

Project description

Overview

Login to AWS using CLI named profiles, IAM access key credentials, or SSO.

Prerequisites

  • Python >= 3.6

  • aws-ssooidc (https://pypi.org/project/aws-ssooidc/) >= 2021.1.1.1

  • boto3 (https://pypi.org/project/boto3/) >= 1.17.78

Conditional Arguments

If authenticating with named profiles:

  • AWSCLI profile name

If authenticating with IAM acccess key credentials:

  • AWS access key id

  • AWS secret access key

If authenticating with SSO:

  • AWS account ID

  • AWS SSO Permission Set (role) name

  • AWS SSO login URL

Usage

Installation:

pip3 install aws-authenticator
# or
python3 -m pip install aws-authenticator

In Python3 authenticating with named profiles:

import aws_authenticator

auth = aws_authenticator.AWSAuthenticator(
   profile_name="<profile-name>",
)
session = auth.profile()
client = session.client("<service-name>")

In Python3 authenticating with IAM access key credentials:

import aws_authenticator

auth = aws_authenticator.AWSAuthenticator(
   access_key_id="<access-key-id>",
   secret_access_key="<secret-access-key>",
)
session = auth.iam()
client = session.client("<service-name>")

In Python3 authenticating with SSO:

import aws_authenticator

auth = aws_authenticator.AWSAuthenticator(
   sso_url="<sso-url>",
   sso_role_name="<sso-role-name>",
   sso_account_id="<sso-account-id>",
)
session = auth.sso()
client = session.client("<service-name>")

Testing Examples

Testing SSO-based login in Python3:

import aws_authenticator

auth = aws_authenticator.AWSAuthenticator(
   sso_url="<sso-url>",
   sso_role_name="<sso-role-name>",
   sso_account_id="<sso-account-id>",
)
session = auth.sso()
client = session.client("sts")

response = client.get_caller_identity()
print(response)

Testing profile-based login as a script in BASH:

python [/path/to/]aws_authenticator \
-m profile \
-p <profile-name>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_authenticator-2024.1.0.0.tar.gz (2.7 kB view hashes)

Uploaded Source

Built Distribution

aws_authenticator-2024.1.0.0-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page