Skip to content

Instantly share code, notes, and snippets.

@clayg
Created January 22, 2021 22:03
Embed
What would you like to do?
send extra headers to s3
#!/usr/bin/env python
from argparse import ArgumentParser
import sys
import json
import boto3
parser = ArgumentParser()
parser.add_argument('bucket', help='Bucket to make')
parser.add_argument('-H', '--header', action='append', default=[],
help='Extra headers')
def main():
opts = parser.parse_args()
conn = boto3.client('s3', endpoint_url='http://saio:8080',
aws_access_key_id='test:tester',
aws_secret_access_key='testing')
def extra_headers(params, **kwargs):
for header_arg in opts.header:
key, value = (x.strip() for x in header_arg.split(':'))
params['headers'][key] = value
conn.meta.events.register('before-call.s3.CreateBucket', extra_headers)
resp = conn.create_bucket(Bucket=opts.bucket)
print(json.dumps(resp, indent=2))
if __name__ == "__main__":
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment