Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
+1 vote
34 views
in Information Technology by (153k points)
How do you use temporary credentials from an assumed role?

Please log in or register to answer this question.

1 Answer

+1 vote
by (153k points)

Once you have assumed a role and obtained temporary credentials, you can use these credentials to access AWS services. Here is an example using Python with the boto3 library:

import boto3

# Assume the role and get temporary credentials
sts_client = boto3.client('sts')
response = sts_client.assume_role(
    RoleArn='arn:aws:iam::123456789012:role/ExampleRole',
    RoleSessionName='ExampleSession'
)

credentials = response['Credentials']

# Use the temporary credentials to create a new session
s3_client = boto3.client(
    's3',
    aws_access_key_id=credentials['AccessKeyId'],
    aws_secret_access_key=credentials['SecretAccessKey'],
    aws_session_token=credentials['SessionToken']
)

# List S3 buckets
response = s3_client.list_buckets()
print('Buckets:', [bucket['Name'] for bucket in response['Buckets']])

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...