File tree 4 files changed +21
-29
lines changed 4 files changed +21
-29
lines changed Original file line number Diff line number Diff line change 1
- index.py
2
1
db_migrate_lambda.zip
Original file line number Diff line number Diff line change
1
+ import os , json
2
+ from urllib import request
3
+
4
+ def handler (event , context ):
5
+ response = {}
6
+ status_endpoint = "{}/db_schema_status" .format (os .environ .get ('MD_LB_ADDRESS' ))
7
+ upgrade_endpoint = "{}/upgrade" .format (os .environ .get ('MD_LB_ADDRESS' ))
8
+
9
+ with request .urlopen (status_endpoint ) as status :
10
+ response ['init-status' ] = json .loads (status .read ())
11
+
12
+ upgrade_patch = request .Request (upgrade_endpoint , method = 'PATCH' )
13
+ with request .urlopen (upgrade_patch ) as upgrade :
14
+ response ['upgrade-result' ] = upgrade .read ().decode ()
15
+
16
+ with request .urlopen (status_endpoint ) as status :
17
+ response ['final-status' ] = json .loads (status .read ())
18
+
19
+ print (response )
20
+ return (response )
Original file line number Diff line number Diff line change @@ -78,38 +78,11 @@ resource "aws_iam_role_policy" "grant_lambda_ecs_vpc" {
78
78
policy = data. aws_iam_policy_document . lambda_ecs_task_execute_policy_vpc . json
79
79
}
80
80
81
- resource "local_file" "db_migrate_lambda" {
82
- content = << EOF
83
- import os, json
84
- from urllib import request
85
-
86
- def handler(event, context):
87
- response = {}
88
- status_endpoint = "{}/db_schema_status".format(os.environ.get('MD_LB_ADDRESS'))
89
- upgrade_endpoint = "{}/upgrade".format(os.environ.get('MD_LB_ADDRESS'))
90
-
91
- with request.urlopen(status_endpoint) as status:
92
- response['init-status'] = json.loads(status.read())
93
-
94
- upgrade_patch = request.Request(upgrade_endpoint, method='PATCH')
95
- with request.urlopen(upgrade_patch) as upgrade:
96
- response['upgrade-result'] = upgrade.read().decode()
97
-
98
- with request.urlopen(status_endpoint) as status:
99
- response['final-status'] = json.loads(status.read())
100
-
101
- print(response)
102
- return(response)
103
- EOF
104
- filename = local. db_migrate_lambda_source_file
105
- }
106
-
107
81
data "archive_file" "db_migrate_lambda" {
108
82
type = " zip"
109
83
source_file = local. db_migrate_lambda_source_file
110
84
output_file_mode = " 0666"
111
85
output_path = local. db_migrate_lambda_zip_file
112
- depends_on = [local_file . db_migrate_lambda ]
113
86
}
114
87
115
88
resource "aws_lambda_function" "db_migrate_lambda" {
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ locals {
22
22
api_gateway_stage_name = " api"
23
23
api_gateway_usage_plan_name = " ${ var . resource_prefix } usage-plan${ var . resource_suffix } "
24
24
25
- db_migrate_lambda_source_file = " ${ path . module } /index.py"
25
+ db_migrate_lambda_source_file = " ${ path . module } /db_migrate/ index.py"
26
26
db_migrate_lambda_zip_file = " ${ path . module } /db_migrate_lambda.zip"
27
27
db_migrate_lambda_name = " ${ var . resource_prefix } db_migrate${ var . resource_suffix } "
28
28
lambda_ecs_execute_role_name = " ${ var . resource_prefix } lambda_ecs_execute${ var . resource_suffix } "
You can’t perform that action at this time.
0 commit comments