Created
August 26, 2022 17:07
-
-
Save mikegrima/b12a4ecad92eb8f71d2855e278efd791 to your computer and use it in GitHub Desktop.
Boto3 STS endpoint "fun"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If doing STS things, you will need to make sure that you use the proper STS endpoint now. | |
# You need to remember that you need to pass in the endpoint URL. Use this for CloudAux: | |
from typing import Any, Dict, List | |
from botocore.client import BaseClient | |
from cloudaux import sts_conn | |
from cloudaux.aws.decorators import paginated | |
ROLE_TO_ASSUME = "AssumeThisRole" | |
ACCOUNT_NUMBER = "012345678910" | |
REGION = "af-south-1" | |
@paginated("Keys", request_pagination_marker="Marker", response_pagination_marker="NextMarker") | |
@sts_conn("kms") | |
def list_keys(client: BaseClient = None, **kwargs) -> List[Dict[str, Any]]: | |
return client.list_keys(**kwargs) | |
# Using it: | |
kms_keys = list_keys( | |
account_number=ACCOUNT_NUMBER, | |
assume_role=ROLE_TO_ASSUME, | |
region=REGION, | |
sts_client_kwargs={"endpoint_url": f"https://sts.{REGION}.amazonaws.com", "region_name": REGION}, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment