Skip to content

Deploy Airflow DAGs after OGC API deployment is complete #422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 25, 2025
Merged
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,17 @@ data "aws_security_groups" "venue_proxy_sg" {
Service = "U-CS"
}
}

data "aws_region" "current" {}

data "aws_ssm_parameter" "unity_client_id" {
name = "/sps/processing/workflows/unity_client_id"
}

data "aws_ssm_parameter" "unity_password" {
name = "/sps/processing/workflows/unity_password"
}

data "aws_ssm_parameter" "unity_username" {
name = "/sps/processing/workflows/unity_username"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ locals {
Stack = ""
}
load_balancer_port = 5001
region = data.aws_region.current.name
}
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ resource "aws_ssm_parameter" "ogc_processes_api_health_check_endpoint" {
description = "The URL of the OGC Processes REST API."
type = "String"
value = jsonencode({
"componentCategory": "processing"
"componentCategory" : "processing"
"componentName" : "OGC API"
"componentType" : "api"
"description" : "A standards-compliant programming interface for Application deployment, job execution and job tracking. May be used to execute jobs in batches."
Expand Down Expand Up @@ -510,3 +510,33 @@ resource "aws_lambda_invocation" "unity_proxy_lambda_invocation" {
]))
}
}

resource "null_resource" "check_ogc_api_status" {
provisioner "local-exec" {
command = "./check_ogc_api_status.sh"
working_dir = "${path.module}/../../../utils"
environment = {
OGC_PROCESSES_API = nonsensitive(aws_ssm_parameter.ogc_processes_api_url.value)
TOKEN_URL = "https://cognito-idp.${local.region}.amazonaws.com"
UNITY_CLIENTID = nonsensitive(data.aws_ssm_parameter.unity_client_id.value)
UNITY_PASSWORD = nonsensitive(data.aws_ssm_parameter.unity_password.value)
UNITY_USERNAME = nonsensitive(data.aws_ssm_parameter.unity_username.value)
}
}
depends_on = [aws_api_gateway_deployment.ogc-api-gateway-deployment, aws_ssm_parameter.ogc_processes_api_url]
}

resource "null_resource" "register_ogc_processes" {
provisioner "local-exec" {
command = "./post_deployment_terraform.sh"
working_dir = "${path.module}/../../../utils"
environment = {
OGC_PROCESSES_API = nonsensitive(aws_ssm_parameter.ogc_processes_api_url.value)
TOKEN_URL = "https://cognito-idp.${local.region}.amazonaws.com"
UNITY_CLIENTID = nonsensitive(data.aws_ssm_parameter.unity_client_id.value)
UNITY_PASSWORD = nonsensitive(data.aws_ssm_parameter.unity_password.value)
UNITY_USERNAME = nonsensitive(data.aws_ssm_parameter.unity_username.value)
}
}
depends_on = [null_resource.check_ogc_api_status]
}
29 changes: 29 additions & 0 deletions utils/check_ogc_api_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Remove trailing slash from API URL if present
OGC_PROCESSES_API="${OGC_PROCESSES_API%/}"
echo $OGC_PROCESSES_API
echo $TOKEN_URL

# Retrieve limited-lifetime token
echo "Fetching Cognito token..."
payload="{\"AuthParameters\":{\"USERNAME\":\"$UNITY_USERNAME\",\"PASSWORD\":\"$UNITY_PASSWORD\"},\"AuthFlow\":\"USER_PASSWORD_AUTH\",\"ClientId\":\"$UNITY_CLIENTID\"}"

token_response=$(curl -X POST \
-H "X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth" \
-H "Content-Type: application/x-amz-json-1.1" \
--data $payload \
$TOKEN_URL)

token=$(echo $token_response | jq -r '.AuthenticationResult.AccessToken')
echo "Cognito token retrieved."

# Poll onto OGC API is available
response_status=0
while [ $response_status -ne 200 ]; do
response_status=$(curl -s -o /dev/null -k -X GET -H "Authorization: Bearer ${token}" -w "%{http_code}" "${OGC_PROCESSES_API}/processes")
echo "response_status=$response_status"
sleep 10
done

exit 0
58 changes: 58 additions & 0 deletions utils/post_deployment_terraform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash
#set -ex

# Script to execute post-deployment operations.
# Pre-Requisites:
# - SPS has been deployed successfully to a given venue
# - The user has valid Cognito credentials for the target venue

# Syntax:
# cd unity-sps/utils
# export UNITY_USERNAME="....."
# export UNITY_PASSWORD="....."
# export UNITY_CLIENTID="...."
# export OGC_PROCESSES_API=https://.........execute-api.us-west-2.amazonaws.com/dev/ogc/api (NO trailing slash!)
# export TOKEN_URL=https://cognito-idp.{region}.amazonaws.com (where region is the AWS region executing in)

# Remove trailing slash from API URL if present
OGC_PROCESSES_API="${OGC_PROCESSES_API%/}"

# Retrieve limited-lifetime token
echo "Fetching Cognito token..."
payload="{\"AuthParameters\":{\"USERNAME\":\"$UNITY_USERNAME\",\"PASSWORD\":\"$UNITY_PASSWORD\"},\"AuthFlow\":\"USER_PASSWORD_AUTH\",\"ClientId\":\"$UNITY_CLIENTID\"}"

token_response=$(curl -X POST \
-H "X-Amz-Target: AWSCognitoIdentityProviderService.InitiateAuth" \
-H "Content-Type: application/x-amz-json-1.1" \
--data $payload \
$TOKEN_URL)

token=$(echo $token_response | jq -r '.AuthenticationResult.AccessToken')
echo "Cognito token retrieved."

# list of processes to be registered
declare -a procs=("cwl_dag.json" "karpenter_test.json" "appgen_dag.json" "cwl_dag_modular.json" "db_cleanup_dag.json")

for proc in "${procs[@]}"
do
echo " "
proc_name=$(echo "$proc" | sed "s/.json//")

# unregister process (in case it was already registered)
echo "Unregistering process: $proc_name"
curl -k -X DELETE \
-H "Authorization: Bearer ${token}" \
-H "Content-Type: application/json; charset=utf-8" \
"${OGC_PROCESSES_API}/processes/${proc_name}"

# register process
echo "Registering process: $proc_name"
curl -k -X POST \
-H "Authorization: Bearer ${token}" \
-H "Expect:" \
-H "Content-Type: application/json; charset=utf-8" \
--data-binary @"../ogc-application-packages/$proc" \
"${OGC_PROCESSES_API}/processes"
echo " "

done