Skip to main content

Posts

Showing posts with the label secret access key

Python - Getting AWS account ID

Here is the Python script that helps to find out the AWS account id. # The script helps you to find out AWS account number import boto3 # Configure AWS access key and secret access key to access AWS resources access_key_id = "test-key" secret_access_key_id = "secret-key" sts = boto3 . client (     "sts" , aws_access_key_id = access_key_id , aws_secret_access_key = secret_access_key_id , ) account_id = sts .get_caller_identity()[ "Account" ] # Print account number print ( account_id ) # The following code helps you to return AWS account number when IAM role based permissions are used account_id = boto3 . client ( "sts" ).get_caller_identity()[ "Account" ] # Print account number print ( account_id ) Hope you find it useful. Disclaimer: www.TechieTalks.co.uk does not conceal the possibility of error and shortcomings due to human or technical factors. www.TechieTalks.co.uk does not bear responsibility upon any loss or da