File tree Expand file tree Collapse file tree 4 files changed +21
-29
lines changed
Expand file tree Collapse file tree 4 files changed +21
-29
lines changed Original file line number Diff line number Diff line change 1- index.py
21db_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" {
7878 policy = data. aws_iam_policy_document . lambda_ecs_task_execute_policy_vpc . json
7979}
8080
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-
10781data "archive_file" "db_migrate_lambda" {
10882 type = " zip"
10983 source_file = local. db_migrate_lambda_source_file
11084 output_file_mode = " 0666"
11185 output_path = local. db_migrate_lambda_zip_file
112- depends_on = [local_file . db_migrate_lambda ]
11386}
11487
11588resource "aws_lambda_function" "db_migrate_lambda" {
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ locals {
2222 api_gateway_stage_name = " api"
2323 api_gateway_usage_plan_name = " ${ var . resource_prefix } usage-plan${ var . resource_suffix } "
2424
25- db_migrate_lambda_source_file = " ${ path . module } /index.py"
25+ db_migrate_lambda_source_file = " ${ path . module } /db_migrate/ index.py"
2626 db_migrate_lambda_zip_file = " ${ path . module } /db_migrate_lambda.zip"
2727 db_migrate_lambda_name = " ${ var . resource_prefix } db_migrate${ var . resource_suffix } "
2828 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