-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
68 lines (50 loc) · 2.1 KB
/
fabfile.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Fab file"""
import os
from fabric.operations import local, settings, put, env, run, sudo
lambdas = {
'ts_rollup': {'handler': 'lambda_database.process_stream_event'},
'ts_db': {'handler': 'lambda_database.handler'},
'ts_conf': {'handler': 'timeserie_configuration.handler'},
}
zip_file_name = 'lambda.zip'
def get_zip_file():
return os.path.join(os.path.dirname(__file__), zip_file_name)
def package_zip():
"""Packs the current code onto a zip"""
cur_dir = os.path.dirname(__file__)
zip_file = get_zip_file()
lambda_database_files = os.path.join(cur_dir, 'rollup/*.py')
# Generate zip
local("zip -r -9 -j %s %s " % (zip_file, lambda_database_files))
def upload_lambdas(use_case):
"""Upload the zip to AWS and perform the deploy of the lambda"""
for lamba_func in lambdas:
handler = lambdas[lamba_func]['handler']
lamba_func = use_case + "_" + lamba_func
print 'Upload %s' % lamba_func
environment = {"TABLE_PREFIX": use_case}
environment = "Variables={" + ",".join(
[k + "=" + str(v) for k, v in environment.iteritems()]) + "}"
local(
"aws lambda update-function-code --function-name %s --zip-file fileb://%s" % (
lamba_func, get_zip_file()))
local(
"aws lambda update-function-configuration --function-name %s --handler %s --environment %s" % (
lamba_func, handler, environment))
def clean():
"""Clean the packaged zip"""
with settings(warn_only=True):
local('rm %s' % get_zip_file())
def publishlambdas(use_case):
"""Build and upload the lambdas"""
clean()
package_zip()
upload_lambdas(use_case)
def publishweb():
"""Publish the contents of the web to an ec2 instance"""
sudo('mkdir -p /var/www/html/ddbtime')
sudo('chmod 0777 /var/www/html/ddbtime')
put('web/chartjs.html', '/var/www/html/ddbtime/web')
put('web/echarts.html', '/var/www/html/ddbtime/web')
put('web/configuration.html', '/var/www/html/ddbtime/web')
# put('web/bower_components/*','/var/www/html/ddbtime/web/bower_components')