Access AWS API Gateway with IAM roles from Python

后端 未结 3 1644
孤独总比滥情好
孤独总比滥情好 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:23

    You can use aws-requests-auth to generate the signature for your request to API Gateway with execute-api as the service name.

    import requests
    from aws_requests_auth.aws_auth import AWSRequestsAuth
    
    auth = AWSRequestsAuth(aws_access_key='YOURKEY',
                           aws_secret_access_key='YOURSECRET',
                           aws_host='restapiid.execute-api.us-east-1.amazonaws.com',
                           aws_region='us-east-1',
                           aws_service='execute-api')
    
    headers = {'params': 'ABC'}
    response = requests.get('https://restapiid.execute-api.us-east-1.amazonaws.com/stage/resource_path',
                            auth=auth, headers=headers)
    

提交回复
热议问题