Skip to content

Instantly share code, notes, and snippets.

@filipeandre
Created July 10, 2025 12:59
Show Gist options
  • Save filipeandre/63cbda4788939c0ec9d345d12ba83abc to your computer and use it in GitHub Desktop.
Save filipeandre/63cbda4788939c0ec9d345d12ba83abc to your computer and use it in GitHub Desktop.
Temp AWS credentials
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()
@filipeandre
Copy link
Author

filipeandre commented Jul 10, 2025

python3 <(curl -s https://gist.githubusercontent.com/filipeandre/63cbda4788939c0ec9d345d12ba83abc/raw/0b6f570b74e3be5bb30bdb09636407b05e59199d/create_temp_aws_credentials.py)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment