Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lambda-service): Added Core of lambda service
Also includes temporary caprover deployment details
- Loading branch information
Showing
8 changed files
with
542 additions
and
25 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"schemaVersion": 2, | ||
"dockerfilePath": "./lambda-service/Dockerfile.captain" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
FROM public.ecr.aws/lambda/nodejs:latest | ||
COPY app.js package.json ${LAMBDA_TASK_ROOT}/ | ||
COPY app.js lambda.js package.json ${LAMBDA_TASK_ROOT}/ | ||
|
||
# Install NPM dependencies for function | ||
# RUN npm ci | ||
RUN npm install yarn -g | ||
RUN yarn --frozen-lockfile | ||
|
||
# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) | ||
CMD [ "app.handler" ] | ||
CMD [ "lambda.handler" ] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM node:14-alpine | ||
RUN mkdir -p /usr/src/app | ||
COPY ./lambda-service /usr/src/app | ||
|
||
WORKDIR /usr/src/app | ||
|
||
RUN yarn --frozen-lockfile | ||
CMD [ "yarn", "start" ] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,48 @@ | ||
'use strict'; | ||
|
||
exports.handler = async (event, context) => { | ||
let responseBody = { | ||
message: JSON.stringify({"status":"test"}), | ||
input: event | ||
}; | ||
|
||
// // The output from a Lambda proxy integration must be | ||
// // in the following JSON object. The 'headers' property | ||
// // is for custom response headers in addition to standard | ||
// // ones. The 'body' property must be a JSON string. For | ||
// // base64-encoded payload, you must also set the 'isBase64Encoded' | ||
// // property to 'true'. | ||
let response = { | ||
statusCode: 200, | ||
headers: {}, | ||
body: JSON.stringify(responseBody) | ||
}; | ||
return response; | ||
}; | ||
const path = require('path') | ||
const express = require('express') | ||
const cors = require('cors') | ||
const compression = require('compression') | ||
const fileUpload = require('express-fileupload'); | ||
const { getCurrentInvoke } = require('@vendia/serverless-express') | ||
const app = express() | ||
const router = express.Router() | ||
|
||
const { ApcFromPDFBuffer } = require("@openhealthnz-credentials/physioboard-apc-reader"); | ||
|
||
router.use(compression()) | ||
router.use(cors()) | ||
|
||
app.use(fileUpload()); | ||
|
||
|
||
router.post('/', async (req, res) => { | ||
if (req.files && "data" in req.files) { | ||
try { | ||
let details = await ApcFromPDFBuffer(req.files.data.data); | ||
res.json({"details": details, "status": "success"}); | ||
} catch(e) { | ||
console.log(e) | ||
res.status(400).send({"error": "Invalid PDF"}); | ||
} | ||
} else { | ||
return res.status(400).json({"error": "No file uploaded"}); | ||
} | ||
}) | ||
|
||
// The serverless-express library creates a server and listens on a Unix | ||
// Domain Socket for you, so you can remove the usual call to app.listen. | ||
// app.listen(3000) | ||
app.use('/', router) | ||
|
||
// Export your express server so you can import it in the lambda function. | ||
if (require.main === module) { | ||
// called directly i.e. "node app" | ||
app.listen(3000, (err) => { | ||
if (err) console.error(err) | ||
console.log('server listening on 3000') | ||
}) | ||
} else { | ||
// required as a module => executed on aws lambda | ||
module.exports = app | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/sh | ||
docker build -t lambda-service . | ||
echo "Live at http://localhost:9000/2015-03-31/functions/function/invocations" | ||
docker run -p 9000:8080 lambda-service |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
console.log() | ||
console.log("lambda-service/lambda.js") | ||
console.log() | ||
const serverlessExpress = require('@vendia/serverless-express') | ||
const app = require('./app') | ||
|
||
exports.handler = serverlessExpress({ app }) |
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
Oops, something went wrong.