Use GenerateCredentialReport with an AWS SDK or command line tool - AWS SDK Code Examples

There are more AWS SDK examples available in the AWS Doc SDK Examples GitHub repo.

Use GenerateCredentialReport with an AWS SDK or command line tool

The following code examples show how to use GenerateCredentialReport.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

CLI
AWS CLI

To generate a credential report

The following example attempts to generate a credential report for the AWS account.

aws iam generate-credential-report

Output:

{ "State": "STARTED", "Description": "No report exists. Starting a new report generation task" }

For more information, see Getting credential reports for your AWS account in the AWS IAM User Guide.

PowerShell
Tools for PowerShell

Example 1: This example requests generation of a new report, which can be done every four hours. If the last report is still recent the State field reads COMPLETE. Use Get-IAMCredentialReport to view the completed report.

Request-IAMCredentialReport

Output:

Description State ----------- ----- No report exists. Starting a new report generation task STARTED
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

def generate_credential_report(): """ Starts generation of a credentials report about the current account. After calling this function to generate the report, call get_credential_report to get the latest report. A new report can be generated a minimum of four hours after the last one was generated. """ try: response = iam.meta.client.generate_credential_report() logger.info( "Generating credentials report for your account. " "Current state is %s.", response["State"], ) except ClientError: logger.exception("Couldn't generate a credentials report for your account.") raise else: return response