Access AWS API Gateway with IAM roles from Python

后端 未结 3 1626
孤独总比滥情好
孤独总比滥情好 2021-02-19 17:57

I have an AWS API Gateway that I would like to secure using IAM Roles .

I am looking for a package to help me accessing it using Python. I am trying to avoid implementin

3条回答
  •  别那么骄傲
    2021-02-19 18:21

    If you want to make a call using the IAM role, you should use BotoAWSRequestsAuth from aws-requests-auth:

    import requests
    from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
    auth = BotoAWSRequestsAuth(
        aws_host="API_ID.execute-api.us-east-1.amazonaws.com",
        aws_region="us-east-1",
        aws_service="execute-api"
    )
    response = requests.get("https://API_ID.execute-api.us-east-1.amazonaws.com/STAGE/RESOURCE", auth=auth)
    

    This will use botocore to retrieve a key and secret from the AWS metadata service rather than you needing to pass them yourself.

    Thanks to Ka Hou Leong for the suggestion of the aws-requests-auth library.

提交回复
热议问题