Skip to main content

Posts

Showing posts with the label IAM

List all AWS IAM roles with their last used date

The following Python script will help to list all the AWS IAM roles with the last used date. If the role is not been used, it will show 'Never used" instead of date. You will require Python3.8 or above to run the script. I prefer to use Tabulate to format the output in to table format. You can format the output in to HTML or even convert in to CSV file too. Let's start the script to list all IAM role and its last used date. import boto3 import time from tabulate import tabulate Once you've imported the boto3, time and tabulate module, let's setup the AWS session using the AWS config profile and region name. session = boto3 . Session ( profile_name = profile , region_name = region ) iam_client = session . client ( 'iam' ) # use paginator if you have long list of IAM roles paginator = iam_client .get_paginator( 'list_roles' ) iterator = paginator .paginate() The following lines will help to setup the header row of the table in the output. In

List the AWS Lambda function information

In this blog, I will share the Python script that will help you to list the AWS Lambda function details such as Function name, Function ARN, Run time, Description and Version etc... I will be using Tabulate module to format my output in to table format. If you are new to Tabulate, please visit my previous blog where I have provided details of Tabulate module. The following Python code is written in to Python 3.8 version.  import boto3 from tabulate import tabulate   After importing the Boto3 and Tabulate module, let's setup our AWS session details by providing region and profile name.  profile = "default" region = "us-east-1" session = boto3 . Session ( profile_name = profile , region_name = region ) lambda_client = session . client ( 'lambda' ) response = lambda_client .list_functions() # Get the list of functions lambda_list = response [ 'Functions' ] The following code will help you to setup a Header row in the table  # Setup heade