mirror of
https://github.com/projecthorus/sondehub-infra.git
synced 2024-12-19 05:07:55 +00:00
Add redirect ham, fix ws, switch to weeks for query
This commit is contained in:
parent
a16e076cb6
commit
6cc3804bb2
44
cdn.tf
44
cdn.tf
@ -14,6 +14,25 @@ resource "aws_lambda_function" "redirect" {
|
||||
source_code_hash = data.archive_file.lambda.output_base64sha256
|
||||
}
|
||||
|
||||
resource "aws_lambda_function" "ham_redirect" {
|
||||
function_name = "ham-sondehub-redirect"
|
||||
handler = "redirect_ham.handler"
|
||||
s3_bucket = aws_s3_bucket_object.lambda.bucket
|
||||
s3_key = aws_s3_bucket_object.lambda.key
|
||||
publish = true
|
||||
memory_size = 128
|
||||
role = aws_iam_role.basic_lambda_role.arn
|
||||
runtime = "python3.9"
|
||||
timeout = 3
|
||||
source_code_hash = data.archive_file.lambda.output_base64sha256
|
||||
}
|
||||
|
||||
resource "aws_lambda_permission" "ham_redirect" {
|
||||
action = "lambda:InvokeFunction"
|
||||
function_name = aws_lambda_function.ham_redirect.arn
|
||||
principal = "edgelambda.amazonaws.com"
|
||||
}
|
||||
|
||||
|
||||
|
||||
resource "aws_route53_record" "testing_A" {
|
||||
@ -515,6 +534,31 @@ resource "aws_cloudfront_distribution" "amateur" {
|
||||
smooth_streaming = false
|
||||
target_origin_id = "S3-${local.domain_name}/amateur"
|
||||
viewer_protocol_policy = "redirect-to-https"
|
||||
lambda_function_association {
|
||||
event_type = "viewer-request"
|
||||
lambda_arn = aws_lambda_function.ham_redirect.qualified_arn
|
||||
}
|
||||
}
|
||||
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}/amateur"
|
||||
viewer_protocol_policy = "redirect-to-https"
|
||||
}
|
||||
comment = ""
|
||||
price_class = "PriceClass_All"
|
||||
|
@ -122,7 +122,7 @@ def get_telem(event, context):
|
||||
lt = requested_time + timedelta(0, 1)
|
||||
gte = requested_time - timedelta(0, duration)
|
||||
|
||||
path = f"telm-{lt.year:2}-{lt.month:02},telm-{gte.year:2}-{gte.month:02}/_search"
|
||||
path = f"telm-*/_search"
|
||||
payload = {
|
||||
"timeout": "30s",
|
||||
"size": 0,
|
||||
|
30
lambda/redirect_ham/__init__.py
Normal file
30
lambda/redirect_ham/__init__.py
Normal file
@ -0,0 +1,30 @@
|
||||
import re
|
||||
def redirect(location):
|
||||
return {
|
||||
"status": '302',
|
||||
"statusDescription": 'Found',
|
||||
"headers": {
|
||||
"location": [{
|
||||
"key": 'Location',
|
||||
"value": location
|
||||
}],
|
||||
},
|
||||
}
|
||||
|
||||
def handler(event, context):
|
||||
request = event["Records"][0]["cf"]["request"]
|
||||
uri = request["uri"]
|
||||
if uri.startswith('/aprs/'):
|
||||
sonde = uri.replace("/aprs/","")
|
||||
return redirect('https://aprs.fi/#!call=' + sonde + '&timerange=36000&tail=36000')
|
||||
if uri.startswith('/site/'):
|
||||
site = uri.replace("/site/", "")
|
||||
return redirect('https://amateur.sondehub.org/#!site=' + site)
|
||||
if uri.startswith('/go/donate'):
|
||||
return redirect('https://www.paypal.com/donate/?hosted_button_id=4V7L43MD5CQ52')
|
||||
if uri.startswith('/go/status'):
|
||||
return redirect("https://cloudwatch.amazonaws.com/dashboard.html?dashboard=SondeHub&context=eyJSIjoidXMtZWFzdC0xIiwiRCI6ImN3LWRiLTE0Mzg0MTk0MTc3MyIsIlUiOiJ1cy1lYXN0LTFfZ2NlT3hwUnp0IiwiQyI6IjNuOWV0Y2ZxZm9zdm11aTc0NTYwMWFzajVzIiwiSSI6InVzLWVhc3QtMTo0ODI5YmQ4MC0yZmYzLTQ0MDktYjI1ZS0yOTE4MTM5YTgwM2MiLCJNIjoiUHVibGljIn0%3D")
|
||||
if uri != '/':
|
||||
uri = re.sub(r"^\/","", uri)
|
||||
return redirect('https://amateur.sondehub.org/?sondehub=1#!f=' + sonde + '&mz=9&qm=All&q=' + sonde)
|
||||
return request
|
39
lambda/redirect_ham/__main__.py
Normal file
39
lambda/redirect_ham/__main__.py
Normal file
@ -0,0 +1,39 @@
|
||||
from . import *
|
||||
|
||||
print(handler({
|
||||
"Records": [
|
||||
{
|
||||
"cf": {
|
||||
"config": {
|
||||
"distributionId": "EXAMPLE"
|
||||
},
|
||||
"request": {
|
||||
"uri": "/MRZ-S1234",
|
||||
"querystring": "auth=test&foo=bar",
|
||||
"method": "GET",
|
||||
"clientIp": "2001:cdba::3257:9652",
|
||||
"headers": {
|
||||
"host": [
|
||||
{
|
||||
"key": "Host",
|
||||
"value": "d123.cf.net"
|
||||
}
|
||||
],
|
||||
"user-agent": [
|
||||
{
|
||||
"key": "User-Agent",
|
||||
"value": "Test Agent"
|
||||
}
|
||||
],
|
||||
"user-name": [
|
||||
{
|
||||
"key": "User-Name",
|
||||
"value": "aws-cloudfront"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}, None))
|
@ -2,10 +2,10 @@ import json
|
||||
import es
|
||||
import zlib
|
||||
import base64
|
||||
|
||||
import datetime
|
||||
|
||||
def lambda_handler(event, context):
|
||||
payloads = {}
|
||||
payloads = []
|
||||
for record in event['Records']:
|
||||
sns_message = json.loads(record["body"])
|
||||
try:
|
||||
@ -16,17 +16,12 @@ def lambda_handler(event, context):
|
||||
incoming_payloads = [decoded]
|
||||
else:
|
||||
incoming_payloads = decoded
|
||||
for payload in incoming_payloads:
|
||||
index = payload['datetime'][:7]
|
||||
year, week = datetime.datetime.now().isocalendar()[:2]
|
||||
index = f"{year}-{week}"
|
||||
payloads += incoming_payloads
|
||||
|
||||
if index not in payloads: # create index if not exists
|
||||
payloads[index] = []
|
||||
|
||||
payloads[index].append(payload)
|
||||
|
||||
for index in payloads:
|
||||
body=""
|
||||
for payload in payloads[index]:
|
||||
for payload in payloads:
|
||||
body += "{\"index\":{}}\n" + json.dumps(payload) + "\n"
|
||||
body += "\n"
|
||||
|
||||
|
@ -541,7 +541,7 @@ resource "aws_ecs_service" "ws_reader_ec2" {
|
||||
task_definition = aws_ecs_task_definition.ws_reader_ec2.arn
|
||||
enable_ecs_managed_tags = true
|
||||
launch_type = "EC2"
|
||||
desired_count = 3
|
||||
desired_count = 6
|
||||
placement_constraints {
|
||||
type = "distinctInstance"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user