Skip to main content

Posts

Showing posts with the label Cloud Computing

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 AWS EC2 instance details with Name tag value

In this blog, we will look at how to execute Python script to get the AWS EC2 details like Name tag valie of the instance, Instance ID, Platform, Instance Type, State and its private IPv4 address. You will require Python 3.8 or above to run the the script successfully. Setting up Boto3 Session and client import boto3 # setup profile and region profile = "default" region = "us-east-1" session = boto3 . Session ( profile_name = profile , region_name = region ) ec2_client = session . client ( 'ec2' ) response = ec2_client .describe_instances() ec2_list = response [ 'Reservations' ] # Gather information about EC2 ec2_name = session . resource ( 'ec2' ) instances = ec2_name .instances.all() # This will help to retrieve Tags information Now, let's print the header row. # print header print ( 'Name, Instance ID, Platform, Instance Type, State, Private IPv4' ) Following code will run and collect the information about EC2.   for