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
locals { | |
function_name = replace(var.name, "-", "_") | |
} | |
resource "aws_ecr_repository" "lambda_repo" { | |
name = var.name | |
# TODO: these provisioners will only run when the | |
# repo is created for the first time. Find a better | |
# way to build and push containers as code changes. |
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
terraform { | |
required_providers { | |
mongodbatlas = { | |
source = "mongodb/mongodbatlas" | |
version = "0.9.1" | |
} | |
random = { | |
source = "hashicorp/random" | |
version = "3.1.0" |
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
resource "aws_vpc" "iot_events" { | |
cidr_block = "10.0.0.0/16" | |
tags = { | |
Name = "iot-events" | |
} | |
} | |
resource "aws_subnet" "subnet_a" { | |
vpc_id = aws_vpc.iot_events.id |
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
terraform { | |
required_providers { | |
aws = { | |
source = "hashicorp/aws" | |
version = "3.49.0" | |
} | |
} | |
required_version = "~> 1.0.0" | |
} |
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
$ curl -XGET \ | |
-H "Content-Type: application/json" \ | |
"http://localhost:8080/events?deviceID=8f188304-e7b3-4a16-a243-b9470468478a&eventType=temp_celcius&date=$(date -u +%F)" |
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
'use strict'; | |
function invoke(r) { | |
var payload = { | |
body: r.requestText, | |
queryStringParameters: r.args, | |
}; | |
r.subrequest('/integration', { | |
method: 'POST', |
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
load_module /usr/lib/nginx/modules/ngx_http_js_module.so; | |
events {} | |
http { | |
js_import integration.js; | |
map $downstream_method $handler_host { | |
POST "add-event"; | |
GET "get-events"; |
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
version: '3' | |
services: | |
get-events: | |
build: | |
context: ./handlers | |
args: | |
handler: get-events | |
environment: | |
MONGODB_URI: mongodb://db:27017 |
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
'use strict'; | |
const { getDBConnection, createRes } = require('../common'); | |
exports.handler = async ({ queryStringParameters }) => { | |
const connection = await getDBConnection(); | |
const { deviceID, date, eventType } = queryStringParameters; | |
try { | |
const events = await connection |
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
FROM amazon/aws-lambda-nodejs:14 | |
ARG handler | |
COPY ./package.json ./package-lock.json /var/task/ | |
COPY ./common /var/task/common | |
COPY ./${handler} /var/task/handler | |
WORKDIR /var/task | |
RUN ["npm", "i", "--production"] |