okigan / awscurl

curl-like access to AWS resources with AWS Signature Version 4 request signing.
MIT License
755 stars 94 forks source link

awscurl in python script ? #41

Closed ghost closed 6 years ago

ghost commented 6 years ago

is it possible to put it in python script: run command and get output to JSON file (without subprocess)

import requests

headers = {
    'Content-Type': 'application/json',
}
params = (
    ('Action', 'ListUsers'),
    ('Version', '2010-05-08'),
)
response = requests.get('https://iam.amazonaws.com/', headers=headers, params=params)
with open('1.json', 'w') as outfile:
    outfile.write(response.content)

and getting

<ErrorResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
  <Error>
    <Type>Sender</Type>
    <Code>MissingAuthenticationToken</Code>
    <Message>Request is missing Authentication Token</Message>
  </Error>
  <RequestId>bb3695a3-399f-11e8-b6b6-17d7b8ab932d</RequestId>
</ErrorResponse>
okigan commented 6 years ago

@dragan979 check out recent changes to awscurl (not published yet on pipi) to which makes 'make_request' function public -- you could use that in your script. Try that and post your feedback here.

ghost commented 6 years ago

awscurl.py works, how, using python code to write json output, i managed to substitute uri inside a script, but have issues doing same for service (iam)

okigan commented 6 years ago

@dragan979 checkout more info how to use python modules: https://docs.python.org/2/tutorial/modules.html

you should be able to get latest awscurl version and import it and use make_request() with your parameters, similar to: https://github.com/okigan/awscurl/blob/master/awscurl/awscurl.py#L336

ghost commented 6 years ago

@okigan , i only have 2 parameters:service and uri, i hardcoded uri just need same for service (if it's possible) i'm beginner in python

okigan commented 6 years ago

Take your time, find good python tutorial then try integration again.

On Apr 6, 2018, at 5:46 PM, dragan979 notifications@github.com wrote:

@okigan , i only have 2 parameters:service and uri, i hardcoded uri just need same for service (if it's possible) i'm beginner in python

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

ghost commented 6 years ago

@okigan, found alternative; boto3, works like a charm