Created
August 1, 2022 09:54
-
-
Save shar1z/a960f7ba45c0f99c571700145b2c7e17 to your computer and use it in GitHub Desktop.
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
import boto3 | |
def generate_credentials(event): | |
tenant_id = extract_tenant_from_auth_header(event) | |
dynamic_policy = generate_dynamodb_policy(tenant_id) | |
sts_client = boto3.client("sts") | |
assumed_role = sts_client.assume_role( | |
RoleArn="arn:aws:iam::<account-id>:role/DynamodbRoleToAssume", | |
RoleSessionName="<name-to-identify-the-assumed-role-session>", | |
Policy=dynamic_policy, | |
) | |
credentials = assumed_role["Credentials"] | |
return { | |
"aws_access_key_id": credentials["AccessKeyId"], | |
"aws_secret_access_key": credentials["SecretAccessKey"], | |
"aws_session_token": credentials["SessionToken"], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment