4

I have troubles to upload my output which is dict from organizations describe_policy to s3. here is my code

paginator = org.get_paginator('list_policies')
page_iterator = paginator.paginate(Filter='SERVICE_CONTROL_POLICY', PaginationConfig={'MaxItems': 10000})
for page in page_iterator:
    for id in page['Policies']:
        policyid = id['Id']
        describe = org.describe_policy(PolicyId=policyid)
        s3.put_object(Body=describe,Bucket='cf-asr-demo',Key=day_month_year+policyid+'/describe-scp.csv')

The error says that my output is dict class

botocore.exceptions.ParamValidationError: Parameter validation failed:
type: <class 'dict'>, valid types: <class 'bytes'>, <class 'bytearray'>, file-like object

How do I upload this output that is basically just a description of a policy to the bucket?

  • Can you check using [upload_file](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.upload_file) instead of `put_object`? – Marcin Apr 27 '20 at 09:05
  • `ValueError('Filename must be a string')` when I use this command `s3.upload_file(describe,Bucket='cf-asr-demo',Key=day_month_year+policyid+'/describe-scp.csv')` – githubnoobieme Apr 27 '20 at 09:18

1 Answers1

2

So I just fixed it myself, I dumped into a json

policy = json.dumps(describe)

and than it worked