From 6153931c7a424b6c7030a1ba6b3fb4b1f3baed35 Mon Sep 17 00:00:00 2001 From: xss Date: Wed, 11 Oct 2023 08:37:35 +1100 Subject: [PATCH] Scaffholding for ttn --- .gitignore | 6 ++ ham_helium.tf | 44 ---------- ham_ttn_helium.tf | 90 ++++++++++++++++++++ lambda/{helium => ttn_helium}/__init__.py | 4 + lambda/{helium => ttn_helium}/__main__.py | 2 +- lambda/{helium => ttn_helium}/test_data.json | 0 6 files changed, 101 insertions(+), 45 deletions(-) create mode 100644 .gitignore delete mode 100644 ham_helium.tf create mode 100644 ham_ttn_helium.tf rename lambda/{helium => ttn_helium}/__init__.py (97%) rename lambda/{helium => ttn_helium}/__main__.py (97%) rename lambda/{helium => ttn_helium}/test_data.json (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7be8558 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +build +.DS_Store +swagger.md +__pycache__ +.terraform +.vscode \ No newline at end of file diff --git a/ham_helium.tf b/ham_helium.tf deleted file mode 100644 index a5fcf3b..0000000 --- a/ham_helium.tf +++ /dev/null @@ -1,44 +0,0 @@ - -resource "aws_lambda_function" "ham_helium_upload_telem" { - function_name = "ham-helium-put-api" - handler = "helium.lambda_handler" - s3_bucket = aws_s3_bucket_object.lambda.bucket - s3_key = aws_s3_bucket_object.lambda.key - source_code_hash = data.archive_file.lambda.output_base64sha256 - publish = true - memory_size = 128 - role = aws_iam_role.basic_lambda_role.arn - runtime = "python3.9" - timeout = 30 - architectures = ["arm64"] - environment { - variables = { - "HAM_SNS_TOPIC" = aws_sns_topic.ham_telem.arn - } - } -} - -resource "aws_lambda_permission" "ham_helium_upload_telem" { - action = "lambda:InvokeFunction" - function_name = aws_lambda_function.ham_helium_upload_telem.arn - principal = "apigateway.amazonaws.com" - source_arn = "arn:aws:execute-api:us-east-1:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.main.id}/*/*/helium" -} - -resource "aws_apigatewayv2_route" "ham_helium_upload_telem" { - api_id = aws_apigatewayv2_api.main.id - api_key_required = false - authorization_type = "NONE" - route_key = "POST /helium" - target = "integrations/${aws_apigatewayv2_integration.ham_helium_upload_telem.id}" -} - -resource "aws_apigatewayv2_integration" "ham_helium_upload_telem" { - api_id = aws_apigatewayv2_api.main.id - connection_type = "INTERNET" - integration_method = "POST" - integration_type = "AWS_PROXY" - integration_uri = aws_lambda_function.ham_helium_upload_telem.arn - timeout_milliseconds = 30000 - payload_format_version = "2.0" -} diff --git a/ham_ttn_helium.tf b/ham_ttn_helium.tf new file mode 100644 index 0000000..02ca667 --- /dev/null +++ b/ham_ttn_helium.tf @@ -0,0 +1,90 @@ + +resource "aws_lambda_function" "ham_helium_upload_telem" { + function_name = "ham-helium-put-api" + handler = "ttn_helium.lambda_handler_helium" + s3_bucket = aws_s3_bucket_object.lambda.bucket + s3_key = aws_s3_bucket_object.lambda.key + source_code_hash = data.archive_file.lambda.output_base64sha256 + publish = true + memory_size = 128 + role = aws_iam_role.basic_lambda_role.arn + runtime = "python3.9" + timeout = 30 + architectures = ["arm64"] + environment { + variables = { + "HAM_SNS_TOPIC" = aws_sns_topic.ham_telem.arn + } + } +} + +resource "aws_lambda_permission" "ham_helium_upload_telem" { + action = "lambda:InvokeFunction" + function_name = aws_lambda_function.ham_helium_upload_telem.arn + principal = "apigateway.amazonaws.com" + source_arn = "arn:aws:execute-api:us-east-1:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.main.id}/*/*/helium" +} + +resource "aws_apigatewayv2_route" "ham_helium_upload_telem" { + api_id = aws_apigatewayv2_api.main.id + api_key_required = false + authorization_type = "NONE" + route_key = "POST /helium" + target = "integrations/${aws_apigatewayv2_integration.ham_helium_upload_telem.id}" +} + +resource "aws_apigatewayv2_integration" "ham_helium_upload_telem" { + api_id = aws_apigatewayv2_api.main.id + connection_type = "INTERNET" + integration_method = "POST" + integration_type = "AWS_PROXY" + integration_uri = aws_lambda_function.ham_helium_upload_telem.arn + timeout_milliseconds = 30000 + payload_format_version = "2.0" +} + + + +resource "aws_lambda_function" "ham_ttn_upload_telem" { + function_name = "ham-ttn-put-api" + handler = "ttn_helium.lambda_handler_ttn" + s3_bucket = aws_s3_bucket_object.lambda.bucket + s3_key = aws_s3_bucket_object.lambda.key + source_code_hash = data.archive_file.lambda.output_base64sha256 + publish = true + memory_size = 128 + role = aws_iam_role.basic_lambda_role.arn + runtime = "python3.9" + timeout = 30 + architectures = ["arm64"] + environment { + variables = { + "HAM_SNS_TOPIC" = aws_sns_topic.ham_telem.arn + } + } +} + +resource "aws_lambda_permission" "ham_ttn_upload_telem" { + action = "lambda:InvokeFunction" + function_name = aws_lambda_function.ham_ttn_upload_telem.arn + principal = "apigateway.amazonaws.com" + source_arn = "arn:aws:execute-api:us-east-1:${data.aws_caller_identity.current.account_id}:${aws_apigatewayv2_api.main.id}/*/*/ttn" +} + +resource "aws_apigatewayv2_route" "ham_ttn_upload_telem" { + api_id = aws_apigatewayv2_api.main.id + api_key_required = false + authorization_type = "NONE" + route_key = "POST /ttn" + target = "integrations/${aws_apigatewayv2_integration.ham_ttn_upload_telem.id}" +} + +resource "aws_apigatewayv2_integration" "ham_ttn_upload_telem" { + api_id = aws_apigatewayv2_api.main.id + connection_type = "INTERNET" + integration_method = "POST" + integration_type = "AWS_PROXY" + integration_uri = aws_lambda_function.ham_ttn_upload_telem.arn + timeout_milliseconds = 30000 + payload_format_version = "2.0" +} diff --git a/lambda/helium/__init__.py b/lambda/ttn_helium/__init__.py similarity index 97% rename from lambda/helium/__init__.py rename to lambda/ttn_helium/__init__.py index 41f1bb4..07a3d61 100644 --- a/lambda/helium/__init__.py +++ b/lambda/ttn_helium/__init__.py @@ -182,3 +182,7 @@ def lambda_handler(event, context): else: return {"statusCode": 200, "body": "^v^ telm logged"} +def lambda_handler_helium(event, context): + return lambda_handler(event, context) +def lambda_handler_ttn(event, context): + return lambda_handler(event, context) \ No newline at end of file diff --git a/lambda/helium/__main__.py b/lambda/ttn_helium/__main__.py similarity index 97% rename from lambda/helium/__main__.py rename to lambda/ttn_helium/__main__.py index ca41b81..937eaab 100644 --- a/lambda/helium/__main__.py +++ b/lambda/ttn_helium/__main__.py @@ -62,4 +62,4 @@ payload = { "body": bbody, "isBase64Encoded": True, } -print(lambda_handler(payload, {})) +print(lambda_handler_helium(payload, {})) diff --git a/lambda/helium/test_data.json b/lambda/ttn_helium/test_data.json similarity index 100% rename from lambda/helium/test_data.json rename to lambda/ttn_helium/test_data.json