1

I need to get response from sending request to the AWS. I have the secretkey/AccessKey of AWS. What is the method/syntax to access the aws APi, for example GetCredentialReport is an API of AWS, How to access this api?

5
  • 1
    What do you mean? You can use AWS CLI, SDK, API. In CLI for instance, you use get-credential-report. Commented May 4, 2020 at 6:03
  • I meant how can you access the getcredentialreport using rest-api with python Commented May 4, 2020 at 6:06
  • 1
    In boto3 there is get_credential_report. Commented May 4, 2020 at 6:07
  • 1
    do you know boto3 library? Check if you don't they might have some way Commented May 4, 2020 at 6:07
  • I have'nt used boat library@sandeshdaundkar Commented May 4, 2020 at 6:14

2 Answers 2

2

Check boto3, which is the aws SDK for Python.

To install it, run in your terminal:

pip install boto3

In order to get the credentials report, try:

import boto3
client = boto3.client(service_name='iam', aws_access_key_id="your_access_key",
                              aws_secret_access_key="your_secret_key")
print(client.get_credential_report())

If you haven't created the report before, generate it first:

client.generate_credential_report()
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks@Gabip. But this error pops up when I execute : "botocore.errorfactory.CredentialReportNotPresentException: An error occurred (ReportNotPresent) when calling the GetCredentialReport operation: Unknown "
This is not an error in your code but it indicates that the credentials error doesn't exist and if you haven't done it so far, you should generate the report first. Read here for more details: docs.aws.amazon.com/IAM/latest/APIReference/…
@Navi I've added it to my post
@Navi what do you mean by json format? write it to json file?
So just import json and do: print(json.dumps(client.get_credential_report()))
|
1

You can use get_credential_report() API in boto3 for credential repot

get_credential_report() Retrieves a credential report for the AWS account. For more information about the credential report, see Getting Credential Reports in the IAM User Guide .

See also: AWS API Documentation

Request Syntax

response = client.get_credential_report()

Response Structure

(dict) -- Contains the response to a successful GetCredentialReport request.

Content (bytes) -- Contains the credential report. The report is Base64-encoded.

ReportFormat (string) -- The format (MIME type) of the credential report.

GeneratedTime (datetime) -- The date and time when the credential report was created, in ISO 8601 date-time format.

Try this code

import os
import boto3
from dotenv import load_dotenv

load_dotenv()


AWS_ACCESS_KEY_ID = os.getenv('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = os.getenv('AWS_SECRET_ACCESS_KEY')

client = boto3.client( 'iam', aws_access_key_id=AWS_ACCESS_KEY_ID, aws_secret_access_key=AWS_SECRET_ACCESS_KEY )

response = client.generate_credential_report()

2 Comments

tried, but the dotenv is not installing in my working environment
How to generate for assume_role?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.