Created
July 10, 2025 12:59
-
-
Save filipeandre/63cbda4788939c0ec9d345d12ba83abc to your computer and use it in GitHub Desktop.
Temp AWS credentials
This file contains hidden or 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 | |
import os | |
def export_temp_credentials(): | |
session = boto3.Session() | |
credentials = session.get_credentials().get_frozen_credentials() | |
print(f'os.environ["AWS_ACCESS_KEY_ID"] = "{credentials.access_key}"') | |
print(f'os.environ["AWS_SECRET_ACCESS_KEY"] = "{credentials.secret_key}"') | |
# If using temporary credentials (like in CloudShell), session_token will be present | |
if credentials.token: | |
print(f'os.environ["AWS_SESSION_TOKEN"] = "{credentials.token}"') | |
if __name__ == "__main__": | |
export_temp_credentials() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python3 <(curl -s https://gist.githubusercontent.com/filipeandre/63cbda4788939c0ec9d345d12ba83abc/raw/0b6f570b74e3be5bb30bdb09636407b05e59199d/create_temp_aws_credentials.py)