aws_sts#

AWS Secure Token Service enhancement.

Usage:

from fixa.aws.aws_sts import (
    mask_user_id,
    mask_aws_account_id,
    mask_iam_principal_arn,
    get_caller_identity,
    get_account_alias,
    get_account_info,
    print_account_info,
)
aws_ops_alpha.vendor.aws_sts.mask_user_id(user_id: str) str[source]#

Example:

>>> mask_user_id("A1B2C3D4GABCDEFGHIJKL")
'A1B2***IJKL'

New in version 0.2.1.

aws_ops_alpha.vendor.aws_sts.mask_aws_account_id(aws_account_id: str) str[source]#

Example:

>>> mask_aws_account_id("123456789012")
'12*********12'

New in version 0.1.1.

aws_ops_alpha.vendor.aws_sts.mask_iam_principal_arn(arn: str) str[source]#

Mask an IAM principal ARN.

Example:

>>> mask_iam_principal_arn("arn:aws:iam::123456789012:role/role-name")
'arn:aws:iam::12*********12:role/role-name'

New in version 0.1.1.

aws_ops_alpha.vendor.aws_sts.get_caller_identity(sts_client: STSClient, masked: bool = False) Tuple[str, str, str][source]#

A wrapper of boto3.client(“sts”).get_caller_identity(). But it can mask the returned value.

New in version 0.2.1.

aws_ops_alpha.vendor.aws_sts.get_account_alias(iam_client: IamClient) Optional[str][source]#

Get AWS Account alias. If no alias is set, return None.

Reference:

New in version 0.2.1.

aws_ops_alpha.vendor.aws_sts.get_account_info(boto_ses: boto3.session.Session, masked_aws_account_id: bool = False) Tuple[str, str, str][source]#

Get the account ID, account alias and ARN of the given boto session.

Parameters:
  • boto_ses – the boto3.session.Session object.

  • masked_aws_account_id – whether to mask the account ID.

Returns:

tuple of aws account_id, account_alias, arn of the given boto session

New in version 0.1.1.

aws_ops_alpha.vendor.aws_sts.print_account_info(boto_ses: boto3.session.Session, masked_aws_account_id: bool = True)[source]#

Display the account ID, account alias and ARN of the given boto session.

Parameters:
  • boto_ses – the boto3.session.Session object.

  • masked_aws_account_id – whether to mask the account ID.

New in version 0.1.1.