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']])