from tos.models2 import CloudFunctionConfiguration, Filter, FilterKey, FilterRule
ak = os.getenv('TOS_ACCESS_KEY')
sk = os.getenv('TOS_SECRET_KEY')
endpoint = "your endpoint"
bucket_name = "bucket-test"
cloudFunction = 'your cloud function'
client = tos.TosClientV2(ak, sk, endpoint, region)
config = CloudFunctionConfiguration(
events=['tos:ObjectCreated:Put', 'tos:ObjectCreated:Post'],
FilterRule(name='prefix', value='your prefix'),
FilterRule(name='suffix', value='your suffix'),
cloud_function=cloudFunction
out = client.put_bucket_notification(bucket_name, [config])
except tos.exceptions.TosClientError as e:
print('fail with client error, message:{}, cause: {}'.format(e.message, e.cause))
except tos.exceptions.TosServerError as e:
print('fail with server error, code: {}'.format(e.code))
print('error with request id: {}'.format(e.request_id))
print('error with message: {}'.format(e.message))
print('error with http code: {}'.format(e.status_code))
print('error with ec: {}'.format(e.ec))
print('error with request url: {}'.format(e.request_url))
print('fail with unknown error: {}'.format(e))