add redirect and CDN parts

This commit is contained in:
Michaela Wheeler 2021-11-12 21:08:18 +11:00
parent 9cf9289f8f
commit 831da1cfc3
6 changed files with 847 additions and 92 deletions

618
cdn.tf Normal file
View File

@ -0,0 +1,618 @@
# manages the short codes
data "archive_file" "redirect" {
type = "zip"
source_file = "redirect/index.js"
output_path = "${path.module}/build/redirect.zip"
}
resource "aws_lambda_function" "redirect" {
function_name = "sondehub-redirect"
handler = "index.handler"
filename = "${path.module}/build/redirect.zip"
source_code_hash = data.archive_file.redirect.output_base64sha256
publish = true
memory_size = 128
role = aws_iam_role.basic_lambda_role.arn
runtime = "nodejs14.x"
timeout = 3
}
resource "aws_route53_record" "testing_A" {
name = "testing"
type = "A"
alias {
name = aws_cloudfront_distribution.testing.domain_name
zone_id = aws_cloudfront_distribution.testing.hosted_zone_id
evaluate_target_health = false
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "testing_AAAA" {
name = "testing"
type = "AAAA"
alias {
name = aws_cloudfront_distribution.testing.domain_name
zone_id = aws_cloudfront_distribution.testing.hosted_zone_id
evaluate_target_health = false
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "root_A" {
name = ""
allow_overwrite = true
type = "A"
alias {
name = aws_cloudfront_distribution.sondehub.domain_name
zone_id = aws_cloudfront_distribution.sondehub.hosted_zone_id
evaluate_target_health = false
}
zone_id = "Z0756308IVLVF48G6G1S"
}
resource "aws_route53_record" "root_AAAA" {
name = ""
allow_overwrite = true
type = "AAAA"
alias {
name = aws_cloudfront_distribution.sondehub.domain_name
zone_id = aws_cloudfront_distribution.sondehub.hosted_zone_id
evaluate_target_health = false
}
zone_id = "Z0756308IVLVF48G6G1S"
}
resource "aws_route53_record" "predict_A" {
name = "predict"
type = "A"
alias {
name = aws_cloudfront_distribution.predict.domain_name
zone_id = aws_cloudfront_distribution.predict.hosted_zone_id
evaluate_target_health = false
}
zone_id = "Z0756308IVLVF48G6G1S"
}
resource "aws_route53_record" "predict_AAAA" {
name = "predict"
type = "AAAA"
alias {
name = aws_cloudfront_distribution.predict.domain_name
zone_id = aws_cloudfront_distribution.predict.hosted_zone_id
evaluate_target_health = false
}
zone_id = "Z0756308IVLVF48G6G1S"
}
resource "aws_route53_record" "tracker_A" {
name = "tracker"
type = "A"
alias {
name = aws_cloudfront_distribution.sondehub.domain_name
zone_id = aws_cloudfront_distribution.sondehub.hosted_zone_id
evaluate_target_health = false
}
zone_id = "Z0756308IVLVF48G6G1S"
}
resource "aws_route53_record" "tracker_AAAA" {
name = "tracker"
type = "AAAA"
alias {
name = aws_cloudfront_distribution.sondehub.domain_name
zone_id = aws_cloudfront_distribution.sondehub.hosted_zone_id
evaluate_target_health = false
}
zone_id = "Z0756308IVLVF48G6G1S"
}
resource "aws_route53_record" "www_A" {
name = "www"
type = "A"
alias {
name = aws_cloudfront_distribution.sondehub.domain_name
zone_id = aws_cloudfront_distribution.sondehub.hosted_zone_id
evaluate_target_health = false
}
zone_id = "Z0756308IVLVF48G6G1S"
}
resource "aws_route53_record" "www_AAAA" {
name = "www"
type = "AAAA"
alias {
name = aws_cloudfront_distribution.sondehub.domain_name
zone_id = aws_cloudfront_distribution.sondehub.hosted_zone_id
evaluate_target_health = false
}
zone_id = "Z0756308IVLVF48G6G1S"
}
resource "aws_route53_record" "v2_A" {
name = ""
allow_overwrite = true
type = "A"
alias {
name = aws_cloudfront_distribution.sondehub.domain_name
zone_id = aws_cloudfront_distribution.sondehub.hosted_zone_id
evaluate_target_health = false
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "v2_AAAA" {
name = ""
allow_overwrite = true
type = "AAAA"
alias {
name = aws_cloudfront_distribution.sondehub.domain_name
zone_id = aws_cloudfront_distribution.sondehub.hosted_zone_id
evaluate_target_health = false
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "api_raw" {
name = "api-raw"
type = "CNAME"
ttl = 300
records = [
aws_apigatewayv2_domain_name.ApiGatewayV2DomainName.domain_name_configuration[0].target_domain_name
]
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "api_A" {
name = "api"
type = "A"
alias {
name = aws_cloudfront_distribution.api.domain_name
zone_id = aws_cloudfront_distribution.api.hosted_zone_id
evaluate_target_health = false
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "api_AAAA" {
name = "api"
type = "AAAA"
alias {
name = aws_cloudfront_distribution.api.domain_name
zone_id = aws_cloudfront_distribution.api.hosted_zone_id
evaluate_target_health = false
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_cloudfront_distribution" "sondehub" {
aliases = [
local.domain_name,
"sondehub.org",
"tracker.sondehub.org",
"www.sondehub.org"
]
default_root_object = "index.html"
origin {
custom_origin_config {
http_port = 80
https_port = 443
origin_keepalive_timeout = 5
origin_protocol_policy = "https-only"
origin_read_timeout = 30
origin_ssl_protocols = [
"TLSv1",
"TLSv1.1",
"TLSv1.2"
]
}
domain_name = aws_cloudfront_distribution.card.domain_name
origin_id = "card"
origin_path = ""
}
origin {
domain_name = aws_s3_bucket.v2.bucket_regional_domain_name
origin_id = "S3-${local.domain_name}"
origin_path = ""
}
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = [
"HEAD",
"GET"
]
compress = true
default_ttl = 120
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
lambda_function_association {
event_type = "viewer-request"
lambda_arn = aws_lambda_function.redirect.qualified_arn
}
max_ttl = 120
min_ttl = 120
smooth_streaming = false
target_origin_id = "S3-${local.domain_name}"
viewer_protocol_policy = "redirect-to-https"
}
ordered_cache_behavior {
allowed_methods = [ "GET", "HEAD"]
cached_methods = [
"HEAD",
"GET"
]
compress = true
default_ttl = 120
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
max_ttl = 120
min_ttl = 120
path_pattern = "card/*"
smooth_streaming = false
target_origin_id = "card"
viewer_protocol_policy = "redirect-to-https"
}
ordered_cache_behavior {
allowed_methods = [ "GET", "HEAD", "OPTIONS"]
cached_methods = [
"HEAD",
"GET"
]
compress = true
default_ttl = 120
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
max_ttl = 120
min_ttl = 120
path_pattern = "*.*"
smooth_streaming = false
target_origin_id = "S3-${local.domain_name}"
viewer_protocol_policy = "redirect-to-https"
}
custom_error_response {
error_caching_min_ttl = 10
error_code = 403
response_code = "200"
response_page_path = "/card/index.html"
}
custom_error_response {
error_caching_min_ttl = 10
error_code = 404
response_code = "200"
response_page_path = "/card/index.html"
}
comment = ""
price_class = "PriceClass_All"
enabled = true
viewer_certificate {
acm_certificate_arn = aws_acm_certificate.CertificateManagerCertificate_root.arn
minimum_protocol_version = "TLSv1.2_2019"
ssl_support_method = "sni-only"
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
http_version = "http2"
is_ipv6_enabled = true
}
resource "aws_cloudfront_distribution" "testing" {
aliases = [
"testing.${local.domain_name}"
]
default_root_object = "index.html"
origin {
domain_name = aws_s3_bucket.v2.bucket_regional_domain_name
origin_id = "S3-${local.domain_name}/testing"
origin_path = "/testing"
}
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = [
"HEAD",
"GET"
]
compress = true
default_ttl = 5
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
max_ttl = 5
min_ttl = 0
smooth_streaming = false
target_origin_id = "S3-${local.domain_name}/testing"
viewer_protocol_policy = "redirect-to-https"
}
comment = ""
price_class = "PriceClass_All"
enabled = true
viewer_certificate {
acm_certificate_arn = aws_acm_certificate_validation.CertificateManagerCertificate.certificate_arn
minimum_protocol_version = "TLSv1.2_2021"
ssl_support_method = "sni-only"
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
http_version = "http2"
is_ipv6_enabled = true
}
resource "aws_cloudfront_distribution" "card" {
origin {
domain_name = aws_s3_bucket.card.bucket_regional_domain_name
origin_id = aws_s3_bucket.card.bucket_regional_domain_name
origin_path = ""
}
default_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = [
"HEAD",
"GET"
]
compress = false
default_ttl = 120
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
max_ttl = 120
min_ttl = 120
smooth_streaming = false
target_origin_id = aws_s3_bucket.card.bucket_regional_domain_name
viewer_protocol_policy = "redirect-to-https"
}
comment = ""
default_root_object = "index.html"
price_class = "PriceClass_100"
enabled = true
viewer_certificate {
cloudfront_default_certificate = true
minimum_protocol_version = "TLSv1"
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
http_version = "http2"
is_ipv6_enabled = true
}
resource "aws_cloudfront_distribution" "predict" {
aliases = [
"predict.sondehub.org"
]
origin {
domain_name = aws_s3_bucket.predict.bucket_regional_domain_name
origin_id = aws_s3_bucket.predict.bucket_regional_domain_name
origin_path = ""
}
default_root_object = "index.html"
default_cache_behavior {
allowed_methods = ["GET", "HEAD", "OPTIONS"]
cached_methods = [
"HEAD",
"GET"
]
compress = true
default_ttl = 120
forwarded_values {
cookies {
forward = "none"
}
query_string = false
}
max_ttl = 120
min_ttl = 120
smooth_streaming = false
target_origin_id = aws_s3_bucket.predict.bucket_regional_domain_name
viewer_protocol_policy = "redirect-to-https"
}
comment = ""
price_class = "PriceClass_100"
enabled = true
viewer_certificate {
acm_certificate_arn = aws_acm_certificate.CertificateManagerCertificate_root.arn
minimum_protocol_version = "TLSv1.2_2021"
ssl_support_method = "sni-only"
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
http_version = "http2"
is_ipv6_enabled = true
}
resource "aws_cloudfront_distribution" "api" {
aliases = [
"api.${local.domain_name}"
]
origin {
custom_origin_config {
http_port = 80
https_port = 443
origin_keepalive_timeout = 5
origin_protocol_policy = "https-only"
origin_read_timeout = 60
origin_ssl_protocols = [
"TLSv1.2"
]
}
domain_name = aws_apigatewayv2_domain_name.ApiGatewayV2DomainName.domain_name
origin_id = "Custom-api.${local.domain_name}"
origin_path = ""
}
default_cache_behavior {
allowed_methods = ["DELETE", "GET", "HEAD", "OPTIONS", "PATCH", "POST", "PUT"]
cached_methods = [
"HEAD",
"GET"
]
compress = true
default_ttl = 60
forwarded_values {
cookies {
forward = "none"
}
headers = [
"Origin",
"Access-Control-Request-Method",
"Access-Control-Request-Headers"
]
query_string = true
}
max_ttl = 120
min_ttl = 60
smooth_streaming = false
target_origin_id = "Custom-api.${local.domain_name}"
viewer_protocol_policy = "allow-all"
}
ordered_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = [
"HEAD",
"GET"
]
compress = true
default_ttl = 30
forwarded_values {
cookies {
forward = "none"
}
headers = [
"Origin",
"Access-Control-Request-Method",
"Access-Control-Request-Headers"
]
query_string = true
}
max_ttl = 30
min_ttl = 30
path_pattern = "predictions"
smooth_streaming = false
target_origin_id = "Custom-api.${local.domain_name}"
viewer_protocol_policy = "redirect-to-https"
}
ordered_cache_behavior {
allowed_methods = ["GET", "HEAD"]
cached_methods = [
"HEAD",
"GET"
]
compress = true
default_ttl = 300
forwarded_values {
cookies {
forward = "none"
}
headers = [
"Origin",
"Access-Control-Request-Method",
"Access-Control-Request-Headers"
]
query_string = false
}
max_ttl = 300
min_ttl = 300
path_pattern = "pledges"
smooth_streaming = false
target_origin_id = "Custom-api.${local.domain_name}"
viewer_protocol_policy = "redirect-to-https"
}
comment = ""
price_class = "PriceClass_100"
enabled = true
viewer_certificate {
acm_certificate_arn = aws_acm_certificate_validation.CertificateManagerCertificate.certificate_arn
minimum_protocol_version = "TLSv1.2_2019"
ssl_support_method = "sni-only"
}
restrictions {
geo_restriction {
restriction_type = "none"
}
}
http_version = "http2"
is_ipv6_enabled = true
}
resource "aws_s3_bucket" "v2" {
bucket = local.domain_name
}
resource "aws_s3_bucket" "cf_logs" {
bucket = "sondehub-cloudfront-logs"
}
resource "aws_s3_bucket" "history" {
bucket = "sondehub-history"
cors_rule {
allowed_headers = [
"*",
]
allowed_methods = [
"GET",
]
allowed_origins = [
"*",
]
expose_headers = []
max_age_seconds = 0
}
website {
index_document = "index.html"
}
}
resource "aws_s3_bucket" "predict" {
bucket = "sondehub-predict"
}
resource "aws_s3_bucket" "card" {
bucket = "sondehub-v2-card"
}
resource "aws_s3_bucket_policy" "S3BucketPolicy" {
bucket = aws_s3_bucket.v2.bucket
policy = "{\"Version\":\"2012-10-17\",\"Id\":\"Policy1615627853229\",\"Statement\":[{\"Sid\":\"Stmt1615627852247\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::${local.domain_name}/*\"}]}"
}
resource "aws_s3_bucket_policy" "S3BucketPolicy2" {
bucket = aws_s3_bucket.history.bucket
policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"PublicRead\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":[\"s3:GetObject\",\"s3:GetObjectVersion\",\"s3:ListBucket\",\"s3:GetObjectTorrent\"],\"Resource\":[\"arn:aws:s3:::sondehub-history/*\",\"arn:aws:s3:::sondehub-history\"]}]}"
}

View File

@ -78,10 +78,10 @@ resource "aws_lambda_function" "historic_to_s3" {
filename = "${path.module}/build/historic_to_s3.zip"
source_code_hash = data.archive_file.historic_to_s3.output_base64sha256
publish = true
memory_size = 2048
memory_size = 3096
role = aws_iam_role.historic.arn
runtime = "python3.9"
timeout = 60
timeout = 120
reserved_concurrent_executions = 2
environment {
variables = {

18
main.tf
View File

@ -30,6 +30,13 @@ resource "aws_iam_role" "basic_lambda_role" {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
},
{
"Effect": "Allow",
"Principal": {
"Service": "edgelambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}]
}
EOF
@ -108,3 +115,14 @@ resource "aws_acm_certificate" "CertificateManagerCertificate" {
]
validation_method = "DNS"
}
resource "aws_acm_certificate" "CertificateManagerCertificate_root" {
domain_name = local.domain_name
subject_alternative_names = [
"*.${local.domain_name}",
"sondehub.org",
"*.sondehub.org"
]
validation_method = "DNS"
}

View File

@ -211,7 +211,16 @@ resource "aws_ecs_task_definition" "tawhiri" {
container_definitions = jsonencode(
[
{
command = []
command = [
"/root/.local/bin/gunicorn",
"-b",
"0.0.0.0:8000",
"--workers=20",
"--timeout=30",
"--keep-alive=65",
"--threads=1",
"tawhiri.api:app"
]
cpu = 0
environment = []
essential = true
@ -229,6 +238,10 @@ resource "aws_ecs_task_definition" "tawhiri" {
containerPath = "/srv"
sourceVolume = "srv"
},
{
containerPath = "/srv/tawhiri-datasets"
sourceVolume = "downloader"
}
]
name = "tawhiri"
portMappings = [
@ -240,6 +253,34 @@ resource "aws_ecs_task_definition" "tawhiri" {
]
volumesFrom = []
},
{
command = ["daemon"]
cpu = 0
environment = [
{
name = "TZ"
value = "UTC"
}
]
essential = true
image = "${data.aws_caller_identity.current.account_id}.dkr.ecr.us-east-1.amazonaws.com/tawhiri-downloader:latest"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/tawhiri"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/srv/tawhiri-datasets"
sourceVolume = "downloader"
},
]
name = "downloader"
volumesFrom = []
},
]
)
cpu = "512"
@ -251,6 +292,7 @@ resource "aws_ecs_task_definition" "tawhiri" {
]
tags = {}
task_role_arn = aws_iam_role.ecs_execution.arn
volume {
@ -266,69 +308,11 @@ resource "aws_ecs_task_definition" "tawhiri" {
}
}
}
}
resource "aws_ecs_task_definition" "tawhiri_downloader" {
family = "tawhiri-downloader"
container_definitions = jsonencode(
[
{
command = [
"daemon",
]
cpu = 0
environment = [
{
name = "TZ"
value = "UTC"
},
]
essential = true
image = "${data.aws_caller_identity.current.account_id}.dkr.ecr.us-east-1.amazonaws.com/tawhiri-downloader:latest"
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "/ecs/tawhiri-downloader"
awslogs-region = "us-east-1"
awslogs-stream-prefix = "ecs"
}
}
mountPoints = [
{
containerPath = "/srv"
sourceVolume = "srv"
},
]
name = "tawhiri-downloader"
portMappings = []
volumesFrom = []
},
]
)
cpu = "256"
execution_role_arn = aws_iam_role.ecs_execution.arn
memory = "512"
network_mode = "awsvpc"
requires_compatibilities = [
"FARGATE",
]
tags = {}
task_role_arn = aws_iam_role.ecs_execution.arn
volume {
name = "srv"
efs_volume_configuration {
file_system_id = aws_efs_file_system.tawhiri.id
root_directory = "srv"
transit_encryption = "DISABLED"
authorization_config {
iam = "DISABLED"
}
}
volume {
name = "downloader"
}
}
resource "aws_ecs_task_definition" "tawhiri_ruaumoko" {
@ -431,10 +415,10 @@ resource "aws_lb_target_group" "tawhiri" {
target_type = "ip"
health_check {
enabled = true
healthy_threshold = 5
interval = 30
matcher = "400"
path = "/api/v1/"
healthy_threshold = 2
interval = 10
matcher = "200"
path = "/api/datasetcheck"
port = "traffic-port"
protocol = "HTTP"
timeout = 5
@ -447,7 +431,7 @@ resource "aws_ecs_service" "tawhiri" {
cluster = aws_ecs_cluster.tawhiri.id
task_definition = aws_ecs_task_definition.tawhiri.arn
enable_ecs_managed_tags = true
health_check_grace_period_seconds = 60
health_check_grace_period_seconds = 600
iam_role = "aws-service-role"
launch_type = "FARGATE"
platform_version = "LATEST"
@ -472,29 +456,6 @@ resource "aws_ecs_service" "tawhiri" {
subnets = [aws_subnet.public["us-east-1b"].id]
}
}
resource "aws_ecs_service" "tawhiri_downloader" {
name = "tawhiri-downloader"
cluster = aws_ecs_cluster.tawhiri.id
task_definition = aws_ecs_task_definition.tawhiri_downloader.arn
enable_ecs_managed_tags = true
iam_role = "aws-service-role"
launch_type = "FARGATE"
platform_version = "LATEST"
desired_count = 1
lifecycle {
ignore_changes = [desired_count]
}
network_configuration {
assign_public_ip = true
security_groups = [
aws_security_group.tawhiri_efs.id
]
subnets = [aws_subnet.public["us-east-1b"].id]
}
}
resource "aws_appautoscaling_target" "tawhiri" {
@ -630,4 +591,28 @@ resource "aws_security_group" "tawhiri_alb" {
ignore_changes = [description, name]
}
}
resource "aws_route53_record" "tawhiri_A" {
name = "tawhiri"
type = "A"
alias {
name = "dualstack.${aws_lb.ws.dns_name}."
zone_id = aws_lb.ws.zone_id
evaluate_target_health = true
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "tawhiri_AAAA" {
name = "tawhiri"
type = "AAAA"
alias {
name = "dualstack.${aws_lb.ws.dns_name}."
zone_id = aws_lb.ws.zone_id
evaluate_target_health = true
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}

88
redirect/index.js Normal file
View File

@ -0,0 +1,88 @@
'use strict';
exports.handler = (event, context, callback) => {
/*
* Generate HTTP redirect response with 302 status code and Location header.
*/
const request = event.Records[0].cf.request;
if (request.uri.startsWith('/aprs/')) {
var sonde = request.uri.replace(/^\/aprs\//, "");
var specific_response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://aprs.fi/#!call=' + sonde + '&timerange=36000&tail=36000'
}],
},
};
callback(null, specific_response);
return;
}
if (request.uri.startsWith('/go/')) {
var name = request.uri.replace(/^\/go\//, "");
if (name == "donate") {
var specific_response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://www.paypal.com/donate?business=YK2WHT6RNSYH8&item_name=SondeHub+Database+funding&currency_code=USD'
}],
},
};
callback(null, specific_response);
return;
}
if (name == "status") {
var specific_response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://cloudwatch.amazonaws.com/dashboard.html?dashboard=SondeHub&context=eyJSIjoidXMtZWFzdC0xIiwiRCI6ImN3LWRiLTE0Mzg0MTk0MTc3MyIsIlUiOiJ1cy1lYXN0LTFfZ2NlT3hwUnp0IiwiQyI6IjNuOWV0Y2ZxZm9zdm11aTc0NTYwMWFzajVzIiwiSSI6InVzLWVhc3QtMTo0ODI5YmQ4MC0yZmYzLTQ0MDktYjI1ZS0yOTE4MTM5YTgwM2MiLCJNIjoiUHVibGljIn0%3D'
}],
},
};
callback(null, specific_response);
return;
}
var specific_response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://tinyurl.com/' + name
}],
},
};
callback(null, specific_response);
return;
}
if (request.uri !== '/') {
var sonde = request.uri.replace(/^\//, "").replace(/^(DFM|M10|M20|IMET|IMET54|MRZ|LMS6)-/, "");
var specific_response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'https://sondehub.org/?sondehub=1#!f=' + sonde + '&mz=9&qm=All&q=' + sonde
}],
},
};
callback(null, specific_response);
return;
}
if (request.querystring !== '' && request.querystring !== undefined) {
// do not process if this is not an A-B test request
callback(null, request);
return;
}
callback(null, request);
};

View File

@ -669,3 +669,49 @@ resource "aws_appautoscaling_policy" "ws_reader" {
# TODO
# s3 config bucket
resource "aws_route53_record" "ws_reader_A" {
name = "ws-reader"
type = "A"
alias {
name = "dualstack.${aws_lb.ws.dns_name}."
zone_id = aws_lb.ws.zone_id
evaluate_target_health = true
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "ws_reader_AAAA" {
name = "ws-reader"
type = "AAAA"
alias {
name = "dualstack.${aws_lb.ws.dns_name}."
zone_id = aws_lb.ws.zone_id
evaluate_target_health = true
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "ws_A" {
name = "ws"
type = "A"
alias {
name = "dualstack.${aws_lb.ws.dns_name}."
zone_id = aws_lb.ws.zone_id
evaluate_target_health = true
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}
resource "aws_route53_record" "ws_AAAA" {
name = "ws"
type = "AAAA"
alias {
name = "dualstack.${aws_lb.ws.dns_name}."
zone_id = aws_lb.ws.zone_id
evaluate_target_health = true
}
zone_id = aws_route53_zone.Route53HostedZone.zone_id
}