Member-only story

How to rotate your IAM user Access Keys very effectively?

Bhanu Reddy
6 min readMay 30, 2022

--

Rotate IAM user Access Keys for every 90 days

OBJECTIVE: In this blog, I am going to explain how to rotate the IAM user access keys very effectively in a simple manner. all the organizations can use this set-up to overcome security issues and improve security scores.

I have used the below AWS services to achieve this,

  1. IAM users with tag(email:useremail@domain.com)
  2. SES with domain configured
  3. Lambda function(x3) with Python 3.x
  4. EventBridge rule(x3)
  5. Secret Manager (create secrets exactly with user names for all the IAM users)

Create 1st lambda function with the name create_access_keys and paste the below code. Create the 1st Eventbridge rule with the name invoke_create_access_keys, add the target of the lambda function and schedule it for every 1 day.

import boto3, os, time, datetime, sys, json
from datetime import date
from botocore.exceptions import ClientError
from time import gmtime, strftime
from datetime import datetime
iam = boto3.client('iam')
secretmanager = boto3.client('secretsmanager')
email_list = []todaysDate = strftime("%Y-%m-%d %H:%M:%S", gmtime())
todaysDate = str(todaysDate)
todaysDate = todaysDate[0:10]
todaysDate =…

--

--

Bhanu Reddy
Bhanu Reddy

Written by Bhanu Reddy

DevSecOps Engineer from India

No responses yet