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?
-
1What do you mean? You can use AWS CLI, SDK, API. In CLI for instance, you use get-credential-report.Marcin– Marcin2020-05-04 06:03:09 +00:00Commented May 4, 2020 at 6:03
-
I meant how can you access the getcredentialreport using rest-api with pythonNavi– Navi2020-05-04 06:06:03 +00:00Commented May 4, 2020 at 6:06
-
1In boto3 there is get_credential_report.Marcin– Marcin2020-05-04 06:07:19 +00:00Commented May 4, 2020 at 6:07
-
1do you know boto3 library? Check if you don't they might have some waysandeshdaundkar– sandeshdaundkar2020-05-04 06:07:30 +00:00Commented May 4, 2020 at 6:07
-
I have'nt used boat library@sandeshdaundkarNavi– Navi2020-05-04 06:14:06 +00:00Commented May 4, 2020 at 6:14
2 Answers
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()
6 Comments
import json and do: print(json.dumps(client.get_credential_report()))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()