0

I want to ask if it is possible to get default values from boto3 method. For example, I want to call client.get_object() boto3 method.
To call this method, the code will be:

client = boto3.client('s3')
response = client.get_object(
    Bucket='string',
    IfMatch='string',
    IfModifiedSince=datetime(2015, 1, 1),
    IfNoneMatch='string',
    IfUnmodifiedSince=datetime(2015, 1, 1),
    Key='string',
    Range='string',
    ResponseCacheControl='string',
    ResponseContentDisposition='string',
    ResponseContentEncoding='string',
    ResponseContentLanguage='string',
    ResponseContentType='string',
    ResponseExpires=datetime(2015, 1, 1),
    VersionId='string',
    SSECustomerAlgorithm='string',
    SSECustomerKey='string',
    RequestPayer='requester',
    PartNumber=123,
    ExpectedBucketOwner='string'
)

If I make a function to call the method, I can pass **kwargs as argument but, how do I verify these arguments?

def call_s3_get_object(**kwargs):
  client = boto3.client('s3')
  response = client.get_object(
    **kwargs
    )

I want to ensure that users can't call call_s3_get_object() and pass any argument that can make it fail.
I see this post post where it is indicated to use inspect.getfullargspec(method) but it is not working with boto3 methods as this class creates the methods dynamically.
Do you know how can I get arguments verified? Thanks

vll1990
  • 311
  • 3
  • 17
  • 1
    You probably should not pass *user supplied* values straight through?! Have a set of allowed kwargs which you define yourself…? – deceze Mar 09 '21 at 15:27
  • In the end, if the user does pass invalid parameters, you'll want that to fail somehow, right? Does it make a big difference whether you make it fail yourself through whatever you're attempting here, or whether the actual boto call fails in itself? – deceze Mar 09 '21 at 15:44
  • Are you talking simply about validating the list of parameters provided or the content of provided parameter values or something more than that? – jarmod Mar 09 '21 at 17:10
  • 1
    "pass any argument that can make it fail" It's always possible for an AWS API to fail, even if you pass it the right params. You need to handle failures and react accordingly. – Anon Coward Mar 10 '21 at 03:15

0 Answers0