forked from HumanCellAtlas/upload-service
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Configure API DNS record set in terraform (HumanCellAtlas#356)
Specify DNS record set in terraform config
- Loading branch information
Showing
11 changed files
with
142 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
usage="usage: $0 [--json] <api_gateway_name> <target_lambda_name>" | ||
|
||
JSON_FORMAT=0 | ||
|
||
if [[ "$#" = 0 ]]; then | ||
echo "$usage" | ||
exit 1 | ||
fi | ||
|
||
format_response() { | ||
api_id="$1" | ||
if [[ "$JSON_FORMAT" = 1 ]]; then | ||
echo "{\"api_id\":\"$api_id\"}" | ||
else | ||
echo $api_id | ||
fi | ||
} | ||
|
||
while (( "$#" )); do | ||
case "$1" in | ||
-j|--json) | ||
eval "$(jq -r '@sh "api_gateway_name=\(.api_gateway_name) lambda_name=\(.lambda_name)"')" | ||
export api_gateway_name | ||
export lambda_name | ||
JSON_FORMAT=1 | ||
shift 1 | ||
break | ||
;; | ||
*) | ||
if [[ "$#" = 2 ]]; then | ||
export api_gateway_name="$1" | ||
export lambda_name="$2" | ||
shift 2 | ||
else | ||
echo "$usage" | ||
exit 1 | ||
fi | ||
;; | ||
esac | ||
done | ||
|
||
lambda_arn=$(aws lambda list-functions | jq -r '.Functions[] | select(.FunctionName==env.lambda_name) | .FunctionArn') | ||
|
||
# Identify the id of our API Gateway by finding a gateway with a REST API with resource with an integration that | ||
# executes our lambda. | ||
for api_id in $(aws apigateway get-rest-apis | jq -r ".items[] | select(.name==\"${api_gateway_name}\") | .id") ; do | ||
for resource_id in $(aws apigateway get-resources --rest-api-id $api_id | jq -r .items[].id); do | ||
aws apigateway get-integration --rest-api-id $api_id --resource-id $resource_id --http-method GET >/dev/null 2>&1 || continue | ||
uri=$(aws apigateway get-integration --rest-api-id $api_id --resource-id $resource_id --http-method GET | jq -r .uri) | ||
if [[ $uri == *"$lambda_arn"* ]]; then | ||
format_response $api_id | ||
exit 0 | ||
fi | ||
done | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
data "aws_route53_zone" "deployment_stage" { | ||
name = "${var.parent_zone_domain_name}." | ||
} | ||
|
||
data "aws_acm_certificate" "deployment_stage" { | ||
domain = "*.${var.parent_zone_domain_name}" | ||
statuses = ["ISSUED"] | ||
types = ["AMAZON_ISSUED"] | ||
most_recent = true | ||
} | ||
|
||
resource "aws_api_gateway_domain_name" "upload" { | ||
certificate_arn = "${data.aws_acm_certificate.deployment_stage.arn}" | ||
domain_name = "${var.upload_api_fqdn}" | ||
|
||
endpoint_configuration { | ||
types = ["EDGE"] | ||
} | ||
} | ||
|
||
data "external" "api_gateway" { | ||
program = ["${path.cwd}/../../../scripts/get_api_id", "--json"] | ||
|
||
query = { | ||
api_gateway_name = "upload.lambdas.api_server" | ||
lambda_name = "${aws_lambda_function.upload_api_lambda.function_name}" | ||
} | ||
} | ||
|
||
resource "aws_route53_record" "upload" { | ||
name = "${aws_api_gateway_domain_name.upload.domain_name}" | ||
type = "A" | ||
zone_id = "${data.aws_route53_zone.deployment_stage.id}" | ||
|
||
alias { | ||
evaluate_target_health = false | ||
name = "${aws_api_gateway_domain_name.upload.cloudfront_domain_name}" | ||
zone_id = "${aws_api_gateway_domain_name.upload.cloudfront_zone_id}" | ||
} | ||
} | ||
|
||
resource "aws_api_gateway_base_path_mapping" "status_api" { | ||
api_id = "${lookup(data.external.api_gateway.result, "api_id")}" | ||
stage_name = "${var.deployment_stage}" | ||
domain_name = "${aws_api_gateway_domain_name.upload.domain_name}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters