8000 Revert "lambda: supports python3" · brpapa/recursion-tree-visualizer@35515f3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 35515f3

Browse files
committed
Revert "lambda: supports python3"
This reverts commit 58094f5.
1 parent 58094f5 commit 35515f3

20 files changed

+137
-331
lines changed

.gitignore

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,5 @@
44
**/coverage
55
.vscode
66
*.DS_Store
7-
.env
8-
**/logs
9-
*.log
10-
npm-debug.log*
11-
yarn-debug.log*
12-
yarn-error.log*
137
**/_*
8+
packages/lambda/Dockerfile.alpine

packages/lambda/.gitignore

Lines changed: 0 additions & 5 deletions
This file was deleted.

packages/lambda/Dockerfile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# This base image already contains the Amazon Lambda Runtime Interface Client (RIC) for run server in production, and the Runtime Interface Emulator (RIE) for run server locally
22

33
FROM amazon/aws-lambda-nodejs:14
4-
RUN yum -y install python3.x86_64
5-
ENV DEBUG 'app:*'
6-
7-
COPY ["package.json", "package-lock.json*", "${LAMBDA_TASK_ROOT}/"]
8-
RUN npm install
94

105
COPY . ${LAMBDA_TASK_ROOT}
6+
7+
RUN npm install
118
RUN npm run build
129

1310
CMD ["dist/index.handler"]

packages/lambda/package-lock.json

Lines changed: 15 additions & 100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lambda/package.json

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
{
2-
"name": "lambda-function",
3-
"version": "1.0.0",
4-
"author": "Bruno Papa <bruno.papa@hotmail.com>",
5-
"private": true,
2+
"name": "lambda",
3+
"version": "0.0.1",
64
"license": "MIT",
75
"scripts": {
8-
"build": "npx tsc",
9-
"test": "DEBUG=app:*,test:* npx jest --config jest.config.js",
10-
"test:cov": "npx jest --config jest.config.js --coverage"
6+
"build": "tsc",
7+
"test": "DEBUG=* npx jest --config jest.config.js",
8+
"test:cov": "npx jest --config jest.config.js --coverage",
9+
"dev": "docker build -t dev-image . && docker run --rm -p 8080:8080 --env DEBUG='*' dev-image"
1110
},
1211
"dependencies": {
1312
"debug": "^2.6.9",
1413
"dotenv": "^8.2.0",
15-
"fp-ts": "^2.9.5",
16-
"joi": "^17.4.0"
14+
"fp-ts": "^2.9.5"
1715
},
1816
"devDependencies": {
1917
"@types/aws-lambda": "^8.10.72",
2018
"@types/debug": "^4.1.5",
2119
"@types/jest": "^26.0.10",
22-
"@types/node": "^14.14.35",
20+
"@types/node": "^14.10.1",
2321
"ts-jest": "^26.4.4",
2422
"ts-node": "^9.0.0",
2523
"typescript": "^4.1.5"

packages/lambda/src/errors/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export enum ChildProcessError {
1818
export const runtimeError = (
1919
stderr: string
2020
): Error<ChildProcessError.RuntimeError> => {
21-
const rawMessages = stderr.split('\n').filter(m => !!m)
21+
const rawMessages = stderr.split('\n')
2222

2323
try {
24-
const rawMessage = rawMessages[3]
24+
const rawMessage = rawMessages[4]
2525
const errorType = rawMessage.split(':')[0]
2626
const errorMessage = rawMessage.split(':').splice(1).join('')
2727
// const errorLocal = rawMessages.slice(1, 3)

packages/lambda/src/index.ts

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { APIGatewayProxyHandler } from 'aws-lambda'
2-
import debug from 'debug'
3-
import joi from 'joi'
41
import buildRunner from './runner'
52
import { FunctionData, SupportedLanguages, TreeViewerData } from './types'
6-
import { safeParse, safeStringify, isJson } from './utils/safe-json'
7-
import { supportedLanguages } from './settings'
3+
import { APIGatewayProxyHandler } from 'aws-lambda'
4+
import debug from 'debug'
5+
import { safeParse, safeStringify } from './utils/safe-json'
86

9-
const log = debug('app:handler')
7+
const log = debug('handler')
108

119
type EventBody = {
1210
lang: SupportedLanguages
@@ -15,59 +13,35 @@ type EventBody = {
1513
}
1614

1715
export const handler: APIGatewayProxyHandler = async (event) => {
18-
//////////////////////////////////////////// dynamic object validation
16+
const body = safeParse(event.body!) as EventBody
1917

20-
log('Event received: %O', event)
18+
// request validations
2119

22-
const eventSchema = joi.object({
23-
body: joi.string().custom((value) => {
24-
if (!isJson(value))
25-
throw new Error('it should be an encoded json string')
26-
return value
27-
}).required()
28-
})
29-
const eventValidated = eventSchema.validate(event)
30-
if (eventValidated.error)
31-
return badRequest(eventValidated.error.message)
20+
if (!body)
21+
return badRequest(
22+
'Provide a body object containing the encoded json string'
23+
)
3224

33-
const eventBody = safeParse(event.body!) as EventBody
34-
35-
const eventBodySchema = joi.object({
36-
lang: joi.string().valid(...supportedLanguages).required(),
37-
functionData: joi.object({
38-
body: joi.string().required(),
39-
params: joi.array().items(joi.object({
40-
name: joi.string().required(),
41-
initialValue: joi.string().required()
42-
})),
43-
globalVariables: joi.array().items(joi.object({
44-
name: joi.string().required(),
45-
value: joi.string().required()
46-
}))
47-
}).required(),
48-
options: joi.object({
49-
memoize: joi.bool().required()
50-
})
51-
}).required()
25+
log(`Event body: ${safeStringify(body)}`)
5226

53-
const eventBodyValidated = eventBodySchema.validate(eventBody)
54-
// eventBody = eventBodyValidated.value
27+
const supportedLanguages = ['node', 'python']
28+
if (!supportedLanguages.includes(body.lang))
29+
return badRequest('Unsupported language')
5530

56-
if (eventBodyValidated.error)
57-
return badRequest(eventBodyValidated.error.message)
31+
if (!body.functionData) return badRequest('Bad function object')
5832

5933
///////////////////////////////////////////
6034

6135
try {
62-
const run = buildRunner(eventBody.lang, eventBody.options)
63-
const treeViewerData = await run(eventBody.functionData)
36+
const run = buildRunner(body.lang, body.options)
37+
const treeViewerData = await run(body.functionData)
6438

6539
if (treeViewerData.isError())
6640
return unprocessableEntity(treeViewerData.value.reason)
6741

6842
return ok(treeViewerData.value)
6943
} catch (e) {
70-
log('Unexpected error: %O', e)
44+
log(`Unexpected error: ${e}`)
7145
return internalServerError('Internal server error')
7246
}
7347
}

packages/lambda/tests/runner/index.test.ts renamed to packages/lambda/src/runner/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { describe, test, expect } from '@jest/globals'
2-
import buildRunner from '../../src/runner'
3-
import { FunctionData } from '../../src/types'
2+
import buildRunner from '.'
3+
import { FunctionData } from '../types'
44

55
const bc: FunctionData = {
66
params: [

0 commit comments

Comments
 (0)
0