summaryrefslogtreecommitdiffstats
path: root/examples/rgw/boto3/bucket_logging.py
blob: fdc219c57650a3313dc6a965d1aaafc9f04e6ed8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/python

import boto3
import sys

if len(sys.argv) != 3:
    print('Usage: ' + sys.argv[0] + ' <bucket> <target bucket>')
    sys.exit(1)

# bucket name as first argument
bucket = sys.argv[1]
# target bucket name as the 2nd argument
target_bucket = sys.argv[2]

# endpoint and keys from vstart
endpoint = 'http://127.0.0.1:8000'
access_key='0555b35654ad1656d804'
secret_key='h7GhxuBLTrlhVUyxSPUKUV8r/2EI4ngqJxD7iBdBYLhwluN30JaT3Q==' # notsecret

client = boto3.client('s3',
        endpoint_url=endpoint,
        aws_access_key_id=access_key,
        aws_secret_access_key=secret_key)


# create the source bucket
response = client.create_bucket(Bucket=bucket)
print(response)

# create the target bucket
response = client.create_bucket(Bucket=target_bucket)
print(response)

bucket_logging_conf = {'LoggingEnabled': {
    'TargetBucket': target_bucket,
    'TargetPrefix': 'log/',
    'TargetObjectKeyFormat': {
      'SimplePrefix': {}
    },
    'ObjectRollTime': 60,
    'LoggingType': 'Journal',
  }
}

response = client.put_bucket_logging(Bucket=bucket, BucketLoggingStatus=bucket_logging_conf)
print(response)

response = client.get_bucket_logging(Bucket=bucket)
print(response)