How to Export EC2 Instances to CSV/Excel Using AWS Systems Manager Explorer

When searching the internet looking for ways of exporting Amazon EC2 instances running within an AWS account, you will get results mostly referencing some CLI or JSON scripts. Well, if you are not into CLI or JSON,  you can accomplish the same goals using the newly added  AWS Systems Manager Operations Management feature called – Explorer. This post will walk you through the step by step process to export the EC2 instances running within an AWS account or an entire AWS Organization and linked accounts. The results are stored in Amazon S3 bucket as a CSV file that can be downloaded. Click on the links to read more about AWS Systems Manager announcement  and  AWS Systems Manager documentation.

Go ahead and get these prerequisites ready prior to configuring Systems Manager Explorer. 

  • Create or use an existing Amazon S3 bucket. The  OpsData queries are exported as comma-seperated value (CSV) files to this Amazon S3 bucket.
  • Enable AWS Config recording. If config is not yet enabled on the account, go ahead and enable it and use the default settings. No rules are required for Explorer. This is require to enable EC2 instance recording to record and view data for the OpsData  EC2 instance source.
  • Create an Amazon SNS topic to notify when the export completes
  • Optionally, Enable and Opt-in for Computer Optimizer if you need to also get compute optimize data for the EC2 instances.

Once the prerequisites and ready, follow the steps below to configure Explorer and Export EC2 instances.

  1.  Go to AWS Systems Manager
  2. Under Operations Management, click on Explorer
  3. Click on Getting started and use the default settings in the Explorer setup page.
  4. If Config and/or Computer Optimizer is not ready, you will see something similar to the below screenshot. Stop and go configure or check on this items as stated in prerequisites.
  5. This is what you should see if those items are properly enabled/configured.
  6. Click on Enable Explorer(located bottom right)
  7. Click on Created resource data sync
  8. Give a friendly name to identify this data sync and select  accounts as appropriate. For individual accounts, the Organization options are not available. 
  9. Select the region(s) that you want this data sync to cover.
  10. Click on create resource data sync (bottom right)
  11. Navigate to AWS Systems Manager, Explorer, and click on Settings (upper right) and validate that all the required sources are set to enabled. If not, click on Edit to disable/enable as needed. For EC2 export, the Amazon EC2 must be Enabled.
  12. Navigate to AWS Systems Manager, Explorer and under OpsData Filter, use the drop down to select the data sync that you created in step 8.
  13. Within the Explorer dashboard, navigate to Instance Count.
  14. For individual AWS account, you will see something similar to below screenshot. The number if total number of EC2 instances running for this account across the regions that were selected for this data sync configuration.
  15. If this was enabled at the AWS Organization level, you will see something similar to below screenshot. The Groups section shows the AWS accounts – master and linked, for the organization with the respective EC2 counts.
  16. Click on the number below the Instance count to view the discovered EC2 instance opsData.
  17. Click on Export.
  18. In the Export Data as CSV pop up box, enter select the S3 bucket and SNS topic that was created in the prerequisites. Enter an optional SNS topic message and click Export.
  19. Click on Status to open the Execution detail. If both the Execution and Execution steps show Success, then data have been successfully exported to the S3 bucket.
  20. Navigate to Amazon S3, select the desired bucket, click on the csv file, click on the object URL and download/download as.
  21. Here is a sample EC2 instance data file in CSV/Excel.

If this was useful, please leave a comment. The AWS Systems Manager Explorer has some additional great features that you may want to explore.


Leave a Reply

Your email address will not be published. Required fields are marked *