-
Notifications
You must be signed in to change notification settings - Fork 163
/
generate-trigger-file.py
executable file
·46 lines (36 loc) · 1.48 KB
/
generate-trigger-file.py
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
#!/usr/bin/env python
# Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Amazon Software License (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
#
# http://aws.amazon.com/asl/
#
# or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and limitations under the License.
import boto
import sys
import tempfile
def main(args):
if len(args) != 5:
sys.stdout.write("generate-trigger-file.py <region> <input bucket> <input prefix> <local directory>\n");
sys.exit(-1)
# connect to s3
s3 = boto.s3.connect_to_region(args[1])
# get the rest of the required arguments
inputBucket = args[2]
prefix = args[3]
localDir = args[4]
bucket = s3.get_bucket(inputBucket)
# create the dummy file
filename = "lambda-redshift-trigger-file.dummy";
f = open(localDir + "/" + filename, 'w')
f.write("\n")
f.flush()
f.close()
# upload the dummy to S3
f = open(localDir + "/" + filename, 'r')
key = bucket.new_key(prefix + "/" + filename)
key.set_contents_from_file(f)
f.close()
sys.stdout.write("Wrote Dummy Trigger File to " + bucket.name + "/" + key.name);
if __name__ == "__main__":
main(sys.argv)