]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | #!/usr/bin/python |
2 | from __future__ import print_function | |
3 | ||
4 | import boto3 | |
5 | import sys | |
6 | import json | |
7 | ||
8 | def js_print(arg): | |
9 | print(json.dumps(arg, indent=2)) | |
10 | ||
11 | if len(sys.argv) != 3: | |
12 | print('Usage: ' + sys.argv[0] + ' <bucket> <key>') | |
13 | sys.exit(1) | |
14 | ||
15 | # bucket name as first argument | |
16 | bucketname = sys.argv[1] | |
17 | keyname = sys.argv[2] | |
18 | # endpoint and keys from vstart | |
19 | endpoint = 'http://127.0.0.1:8000' | |
20 | access_key='0555b35654ad1656d804' | |
21 | secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==' | |
22 | ||
23 | client = boto3.client('s3', | |
24 | endpoint_url=endpoint, | |
25 | aws_access_key_id=access_key, | |
26 | aws_secret_access_key=secret_key) | |
27 | ||
28 | print('deleting object first') | |
29 | js_print(client.delete_object(Bucket=bucketname, Key=keyname)) | |
30 | print('appending at position 0') | |
31 | resp = client.put_object(Bucket=bucketname, Key=keyname, | |
32 | Append=True, | |
33 | AppendPosition=0, | |
34 | Body='8letters') | |
35 | ||
36 | js_print(resp) | |
37 | append_pos = resp['AppendPosition'] | |
38 | print('appending at position %d' % append_pos) | |
39 | js_print(client.put_object(Bucket=bucketname, Key=keyname, | |
40 | Append=True, | |
41 | AppendPosition=append_pos, | |
42 | Body='8letters')) |