Skip to content

Instantly share code, notes, and snippets.

View jamesseanwright's full-sized avatar
🤔

James Wright jamesseanwright

🤔
View GitHub Profile
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.
terraform {
required_providers {
mongodbatlas = {
source = "mongodb/mongodbatlas"
version = "0.9.1"
}
random = {
source = "hashicorp/random"
version = "3.1.0"
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
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "3.49.0"
}
}
required_version = "~> 1.0.0"
}
$ curl -XGET \
-H "Content-Type: application/json" \
"http://localhost:8080/events?deviceID=8f188304-e7b3-4a16-a243-b9470468478a&eventType=temp_celcius&date=$(date -u +%F)"
'use strict';
function invoke(r) {
var payload = {
body: r.requestText,
queryStringParameters: r.args,
};
r.subrequest('/integration', {
method: 'POST',
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";
version: '3'
services:
get-events:
build:
context: ./handlers
args:
handler: get-events
environment:
MONGODB_URI: mongodb://db:27017
'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
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"]