Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion modules/metadata-service/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
index.py
db_migrate_lambda.zip
20 changes: 20 additions & 0 deletions modules/metadata-service/db_migrate/index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import os, json
from urllib import request

def handler(event, context):
response = {}
status_endpoint = "{}/db_schema_status".format(os.environ.get('MD_LB_ADDRESS'))
upgrade_endpoint = "{}/upgrade".format(os.environ.get('MD_LB_ADDRESS'))

with request.urlopen(status_endpoint) as status:
response['init-status'] = json.loads(status.read())

upgrade_patch = request.Request(upgrade_endpoint, method='PATCH')
with request.urlopen(upgrade_patch) as upgrade:
response['upgrade-result'] = upgrade.read().decode()

with request.urlopen(status_endpoint) as status:
response['final-status'] = json.loads(status.read())

print(response)
return(response)
27 changes: 0 additions & 27 deletions modules/metadata-service/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -78,38 +78,11 @@ resource "aws_iam_role_policy" "grant_lambda_ecs_vpc" {
policy = data.aws_iam_policy_document.lambda_ecs_task_execute_policy_vpc.json
}

resource "local_file" "db_migrate_lambda" {
content = <<EOF
import os, json
from urllib import request

def handler(event, context):
response = {}
status_endpoint = "{}/db_schema_status".format(os.environ.get('MD_LB_ADDRESS'))
upgrade_endpoint = "{}/upgrade".format(os.environ.get('MD_LB_ADDRESS'))

with request.urlopen(status_endpoint) as status:
response['init-status'] = json.loads(status.read())

upgrade_patch = request.Request(upgrade_endpoint, method='PATCH')
with request.urlopen(upgrade_patch) as upgrade:
response['upgrade-result'] = upgrade.read().decode()

with request.urlopen(status_endpoint) as status:
response['final-status'] = json.loads(status.read())

print(response)
return(response)
EOF
filename = local.db_migrate_lambda_source_file
}

data "archive_file" "db_migrate_lambda" {
type = "zip"
source_file = local.db_migrate_lambda_source_file
output_file_mode = "0666"
output_path = local.db_migrate_lambda_zip_file
depends_on = [local_file.db_migrate_lambda]
}

resource "aws_lambda_function" "db_migrate_lambda" {
Expand Down
2 changes: 1 addition & 1 deletion modules/metadata-service/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ locals {
api_gateway_stage_name = "api"
api_gateway_usage_plan_name = "${var.resource_prefix}usage-plan${var.resource_suffix}"

db_migrate_lambda_source_file = "${path.module}/index.py"
db_migrate_lambda_source_file = "${path.module}/db_migrate/index.py"
db_migrate_lambda_zip_file = "${path.module}/db_migrate_lambda.zip"
db_migrate_lambda_name = "${var.resource_prefix}db_migrate${var.resource_suffix}"
lambda_ecs_execute_role_name = "${var.resource_prefix}lambda_ecs_execute${var.resource_suffix}"
Expand Down