By using AWS re:Post, you agree to the AWS re:Post Terms of Use

How to generate EC2 Report as PDF from instance page

0

Hello,

I need the complete report of all EC2 instances (as in the instances page) in my region as PDF format. But i couldn't find any option to generate this report. If you know means guys kindly let me know ASAP.

Thanks, Ragav

asked a month ago83 views
3 Answers
2
Accepted Answer

Unfortunately, there isn't a direct built-in option in AWS to generate a PDF report of all EC2 instances from the EC2 dashboard. However, there are a few alternative approaches you can consider:

  1. Using Amazon QuickSight: You can create a custom dashboard in Amazon QuickSight that displays EC2 instance information. Once created, you can export this dashboard as a PDF. To do this, open your QuickSight dashboard, click the "Export" button in the top right corner, and choose "Generate PDF". This will give you a snapshot of your EC2 data in PDF format.

  2. Using AWS CLI: You can use the AWS Command Line Interface (CLI) to extract EC2 instance information and save it as a CSV file. While this doesn't directly create a PDF, you can easily convert a CSV to PDF using various tools. Here's a sample CLI command:

aws ec2 describe-instances --query "Reservations[].Instances[].{InstanceId:InstanceId, InstanceType:InstanceType, State:State.Name, Name: Tags[?Key=='Name'].Value, LaunchTime:LaunchTime}" --output json | jq -r ".[] | [.Name[0], .InstanceId, .InstanceType, .State, .LaunchTime] | @csv" > ec2-info.csv

This command will create a CSV file with information about your EC2 instances.

  1. Custom Solution: For a more tailored approach, you could create a custom program using AWS SDK (like boto3 for Python) to fetch EC2 instance data and generate a PDF report.

While these methods don't provide an exact replica of the EC2 instances page as a PDF, they offer ways to capture and present the essential information about your EC2 instances in a format that can be easily shared or archived.
Sources
Exporting and printing interactive Amazon QuickSight dashboard reports - Amazon QuickSight
Exporting Amazon QuickSight analyses or dashboards as PDFs - Amazon QuickSight
How to get pdf for ec2 servers list | AWS re:Post
EC2 Instance information as csv download | AWS re:Post

profile picture
answered a month ago
profile picture
EXPERT
reviewed a month ago
1

Besides the other options listed including AWS CLI, and if you are comfortable with SQL syntax, another option is Steampipe as mentioned by blog Querying AWS at scale across APIs, Regions, and accounts

Once configured, you can run a query to get list of EC2 instances. Example output from blog below

select
  region,
  instance_id,
  instance_state,
  instance_type,
  title
from 
  aws_ec2_instance;

+-----------+---------------------+----------------+---------------+-----------------+
| region    | instance_id         | instance_state | instance_type | title           |
+-----------+---------------------+----------------+---------------+-----------------+
| eu-west-1 | i-003d889c8dc91f939 | running        | t3.medium     | Dev Bastion     |
| eu-west-2 | i-072ee9d889c80c59a | running        | m5a.large     | Squid           |
| us-east-1 | i-0667842133f5baeb7 | stopped        | t3.large      | WinBastion      |
| us-east-2 | i-059b0d1eaa04232f8 | running        | t3.large      | ECS Host        |
| us-east-2 | i-0e6f804203eb894eb | running        | t2.micro      | Linux Bastion   |
+-----------+---------------------+----------------+---------------+-----------------+

Time: 244.685827ms
AWS
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
0

Generating a Comprehensive EC2 Instances Report in PDF Format: Options and Alternatives

Unfortunately, AWS doesn't offer a direct, built-in option to export a PDF report of all EC2 instances from the EC2 Management Console. However, there are multiple approaches and workarounds to achieve the desired result, ranging from using AWS-native services to custom solutions. Below are various methods you can employ:

1. Amazon QuickSight: Creating Dashboards and Exporting as PDF

Amazon QuickSight is AWS's business intelligence service that allows you to create visual dashboards based on your EC2 instance data and export them as PDF reports. This approach is especially useful if you require a visual representation of your EC2 instances or need to share reports with stakeholders.

Steps:

1. Create a Dataset:

First, you'll need to connect QuickSight to your EC2 data source. You can create a dataset that pulls EC2 information from Amazon Athena or AWS Cost and Usage Reports (CUR). For more on datasets, see the https://docs.aws.amazon.com/quicksight/latest/user/welcome.html

2. Build a Dashboard:

Use the dataset to build a custom QuickSight dashboard, where you can display EC2 instance metadata such as instance IDs, types, states, tags, and other relevant attributes. Learn more about building dashboards here: https://docs.aws.amazon.com/quicksight/latest/user/using-dashboards.html

3. Export as PDF:

Once your dashboard is ready, click the Export button in the top-right corner and choose Generate PDF. Full details on exporting are available in the https://docs.aws.amazon.com/quicksight/latest/user/exporting-data.html

2. AWS CLI: Export EC2 Data to CSV and Convert to PDF

Using the AWS Command Line Interface (CLI), you can extract EC2 instance information into a CSV file and then convert it into a PDF using external tools such as Python. This method gives you control over the data fields you want to include in the report.

Steps:

Extract EC2 Data with AWS CLI:

Use the following CLI command to retrieve key details about EC2 instances:

aws ec2 describe-instances \
  --query "Reservations[].Instances[].{InstanceId:InstanceId, InstanceType:InstanceType, State:State.Name, Name: Tags[?Key=='Name'].Value, LaunchTime:LaunchTime}" \
  --output json | jq -r ".[] | [.Name[0], .InstanceId, .InstanceType, .State, .LaunchTime] | @csv" > ec2-info.csv

  • This command generates a CSV (ec2-info.csv) containing details like instance ID, type, state, launch time, and name.
  • Refer to the AWS CLI EC2 Command Documentation for more details on customizing the describe-instances query.

https://docs.aws.amazon.com/cli/latest/reference/ec2/

Convert CSV to PDF:

Once you have the CSV file, you can use a Python script to convert the data into a PDF. Here’s an example:

import pandas as pd
import pdfkit

# Load EC2 data from CSV
data = pd.read_csv('ec2-info.csv')

# Convert the DataFrame to HTML format
html = data.to_html()

# Save the HTML as a PDF
pdfkit.from_string(html, 'ec2_instances_report.pdf')

  • Install necessary libraries via pip: pip install pandas pdfkit.
  • This approach provides flexibility in formatting your EC2 instance data into a PDF document.

3. AWS SDK (Custom Solution)

For more customized or large-scale solutions, you can create a custom script or application using the AWS SDK. This method is ideal if you need complete control over the report generation process, from fetching the data to formatting and exporting it as a PDF.

Steps:

Fetch EC2 Data Using AWS SDK:

Using the boto3 library in Python (or the appropriate SDK for your language), you can fetch the required EC2 instance details programmatically:

import boto3

ec2 = boto3.client('ec2')

# Describe instances
instances = ec2.describe_instances()

# Process instance data
for reservation in instances['Reservations']:
    for instance in reservation['Instances']:
        print(f"Instance ID: {instance['InstanceId']}, State: {instance['State']['Name']}")

  • Refer to the official documentation for the boto3 EC2 Client: boto3 EC2 documentation.

https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/ec2.html

Generate and Export PDF:

After fetching and processing the data, you can use libraries like pdfkit or FPDF to generate a PDF report, just like in the CSV example. This gives you control over the report layout and presentation.

4. AWS Systems Manager: Inventory EC2 Instances

Another approach is to use AWS Systems Manager (SSM), which includes an Inventory feature that helps collect configuration data from EC2 instances. You can configure Systems Manager to report on your EC2 instances and then export the data for further processing.

5. AWS Trusted Advisor: EC2 Instance Optimization Report

AWS Trusted Advisor offers insights into your EC2 usage, including recommendations for cost optimization, security, fault tolerance, and performance. While this service focuses more on best practices than raw data reporting, it can provide useful insights.

  • Export reports from Trusted Advisor directly from the AWS Management Console.
  • See more on AWS Trusted Advisor: AWS Trusted Advisor Documentation.

https://docs.aws.amazon.com/awssupport/latest/user/trusted-advisor.html

Alternative Approaches

If the above methods don’t fit your use case, here are some alternative approaches:

Cost Explorer: You can use AWS Cost Explorer to export billing and usage data for EC2 instances. This includes pricing, running hours, and instance types, but may lack detailed instance metadata.

EXPERT
answered a month ago
  • It's a paid service. I am looking for free one

  • Hi, option 2 is free and in my opinion probably the best way to go about this. Using the AWS CLI and running the command will give you a CSV file with the name, instance ID, type, current state, and launch time, you can change this by adjusting the query. From there you can open the file in tools like Excel and export as PDF.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions