Skip to content

Instantly share code, notes, and snippets.

@takakabe
Created September 7, 2019 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takakabe/3b188ce23da13a552c0a55d883c8592e to your computer and use it in GitHub Desktop.
Save takakabe/3b188ce23da13a552c0a55d883c8592e to your computer and use it in GitHub Desktop.
Python
import boto3
iam = boto3.client('iam')
sts = boto3.client('sts')
access_key_id = iam.list_access_keys()['AccessKeyMetadata'][0]['AccessKeyId']
response = sts.get_caller_identity()
user_name = response['Arn'].split('/')[1]
iam.delete_access_key(
AccessKeyId=access_key_id,
UserName=user_name
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment