forked from cambridge-collection/cudl-data-processing-xslt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish_xslt_to_s3.py
More file actions
executable file
·63 lines (47 loc) · 1.68 KB
/
publish_xslt_to_s3.py
File metadata and controls
executable file
·63 lines (47 loc) · 1.68 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
import boto3
import shutil
import logging
import os
from botocore.exceptions import ClientError
s3bucket = "cudl-artefacts"
s3keyDir = "projects/cudl-data-processing/xslt/"
# Script creates a zip file from the xslt content, uploads to s3, creates a new layer version
# with that zip, and updates the latest version of the lambda to use that layer.
# NB: See publish_xslt_live.py to make the live version of the xslt live.
def main():
# Get version number from file
f = open("VERSION", "r")
version = increment_ver(f.read())
f.close()
# zip up xslt
# zip -r cudl-transform-xslt-<version_number>.zip xslt
shutil.make_archive("cudl-transform-xslt-"+version, 'zip', ".", "xslt")
zip_file = "cudl-transform-xslt-"+version+".zip"
# upload to s3
success = upload_file_s3(zip_file, s3bucket, s3keyDir+zip_file)
if not success:
raise Exception('Zipping Failed, aborting.')
# update the version in file
f = open("VERSION", "w")
f.write(version)
f.close()
# Remove local zip file.
os.remove(zip_file)
print("Uploaded new version: "+s3bucket+"/"+s3keyDir+zip_file)
# upload to s3
# aws s3 cp cudl-transform-xslt.zip s3://cudl-artefacts/projects/cudl-data-processing/xslt/cudl-transform-xslt.zip
def upload_file_s3(file_name, bucket, object_name):
# Upload the file
s3_client = boto3.client('s3')
try:
response = s3_client.upload_file(file_name, bucket, object_name)
except ClientError as e:
logging.error(e)
return False
return True
def increment_ver(version):
version = version.split('.')
version[2] = str(int(version[2]) + 1)
return '.'.join(version)
main()