exlo 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.d.ts +2 -0
- package/dist/cli.mjs +11 -0
- package/dist/config.d.ts +35 -0
- package/dist/defineConfig.d.ts +125 -0
- package/dist/defineConfig.mjs +1 -0
- package/dist/lib/esbuild/buildOptimizer.d.ts +9 -0
- package/dist/lib/esbuild/knownCjs.d.ts +1 -0
- package/dist/lib/esbuild/mergeEsbuildConfig.d.ts +2 -0
- package/dist/lib/esbuild/parseCustomEsbuild.d.ts +2 -0
- package/dist/lib/parseEvents/ddbStream.d.ts +17 -0
- package/dist/lib/parseEvents/endpoints.d.ts +29 -0
- package/dist/lib/parseEvents/funcUrl.d.ts +2 -0
- package/dist/lib/parseEvents/index.d.ts +16 -0
- package/dist/lib/parseEvents/sqs.d.ts +11 -0
- package/dist/lib/runtime/bufferedStreamResponse.d.ts +24 -0
- package/dist/lib/runtime/callDestinations.d.ts +12 -0
- package/dist/lib/runtime/eventSourceMapping/base.d.ts +66 -0
- package/dist/lib/runtime/eventSourceMapping/base.mjs +1 -0
- package/dist/lib/runtime/eventSourceMapping/errors/eventSourceMappingError.d.ts +5 -0
- package/dist/lib/runtime/eventSourceMapping/esmBatch.d.ts +15 -0
- package/dist/lib/runtime/eventSourceMapping/filter/compileFilterPolicy.d.ts +12 -0
- package/dist/lib/runtime/eventSourceMapping/filter/compileFilterPolicy.test.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/compileWildcard.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/compileWildcard.test.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/expandDotPathsWithStrictConflicts.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/expandDotPathsWithStrictConflicts.test.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/filter/matchesFilterPolicy.d.ts +2 -0
- package/dist/lib/runtime/eventSourceMapping/filter/matchesFilterPolicy.test.d.ts +1 -0
- package/dist/lib/runtime/eventSourceMapping/sqs.d.ts +19 -0
- package/dist/lib/runtime/eventSourceMapping/utils.d.ts +6 -0
- package/dist/lib/runtime/rapidApi.d.ts +97 -0
- package/dist/lib/runtime/runners/index.d.ts +25 -0
- package/dist/lib/runtime/runners/node/awslambda.d.ts +11 -0
- package/dist/lib/runtime/runners/node/index.d.ts +1 -0
- package/dist/lib/runtime/runners/node/index.js +19 -0
- package/dist/lib/runtime/runners/node/runner.d.ts +34 -0
- package/dist/lib/runtime/runners/node/streamResponse.d.ts +90 -0
- package/dist/lib/runtime/runners/node/utils.d.ts +39 -0
- package/dist/lib/runtime/runners/python/runner.d.ts +48 -0
- package/dist/lib/runtime/runners/ruby/runner.d.ts +43 -0
- package/dist/lib/server/daemon.d.ts +27 -0
- package/dist/lib/server/handlers.d.ts +13 -0
- package/dist/lib/services/index.d.ts +10 -0
- package/dist/lib/utils/amazonifyHeaders.d.ts +3 -0
- package/dist/lib/utils/colorize.d.ts +12 -0
- package/dist/lib/utils/getPackageInstalledDir.d.ts +1 -0
- package/dist/lib/utils/readDefineConfig.d.ts +6 -0
- package/dist/main.d.ts +80 -0
- package/dist/plugins/lambda/events/alb.d.ts +44 -0
- package/dist/plugins/lambda/events/apg.d.ts +111 -0
- package/dist/plugins/lambda/events/common.d.ts +114 -0
- package/dist/plugins/lambda/functionUrlInvoke.d.ts +3 -0
- package/dist/plugins/lambda/htmlStatusMsg.d.ts +4 -0
- package/dist/plugins/lambda/index.d.ts +3 -0
- package/dist/plugins/lambda/invokeRequests.d.ts +3 -0
- package/dist/plugins/lambda/lambdaApi.d.ts +6 -0
- package/dist/plugins/lambda/responseStreamingInvoke.d.ts +3 -0
- package/dist/plugins/lambda/streamEncoder.d.ts +19 -0
- package/dist/plugins/lambda/utils.d.ts +29 -0
- package/dist/plugins/restApi/compileAjvSchema.d.ts +1 -0
- package/dist/plugins/restApi/errors.d.ts +32 -0
- package/dist/plugins/restApi/findRequestResource.d.ts +9 -0
- package/dist/plugins/restApi/findRequestResource.test.d.ts +1 -0
- package/dist/plugins/restApi/index.d.ts +8 -0
- package/dist/plugins/restApi/index.mjs +1 -0
- package/dist/plugins/restApi/resourcesFromOpenApi.d.ts +4 -0
- package/dist/plugins/restApi/restApiServer.d.ts +265 -0
- package/dist/plugins/restApi/restApiServer.test.d.ts +1 -0
- package/dist/plugins/restApi/utils.d.ts +9 -0
- package/dist/plugins/s3/actions/AbortMultipartUploadAction.d.ts +10 -0
- package/dist/plugins/s3/actions/CompleteMultipartUploadAction.d.ts +15 -0
- package/dist/plugins/s3/actions/CopyObjectAction.d.ts +24 -0
- package/dist/plugins/s3/actions/CreateBucketAction.d.ts +8 -0
- package/dist/plugins/s3/actions/CreateMultipartUploadAction.d.ts +13 -0
- package/dist/plugins/s3/actions/DeleteBucketAction.d.ts +8 -0
- package/dist/plugins/s3/actions/DeleteBucketPolicyAction.d.ts +8 -0
- package/dist/plugins/s3/actions/DeleteBucketTaggingAction.d.ts +8 -0
- package/dist/plugins/s3/actions/DeleteObjectAction.d.ts +10 -0
- package/dist/plugins/s3/actions/DeleteObjectTaggingAction.d.ts +9 -0
- package/dist/plugins/s3/actions/DeleteObjectsAction.d.ts +8 -0
- package/dist/plugins/s3/actions/GetBucketAclAction.d.ts +8 -0
- package/dist/plugins/s3/actions/GetBucketPolicy.d.ts +8 -0
- package/dist/plugins/s3/actions/GetBucketTaggingAction.d.ts +8 -0
- package/dist/plugins/s3/actions/GetObjectAclAction.d.ts +8 -0
- package/dist/plugins/s3/actions/GetObjectAction.d.ts +30 -0
- package/dist/plugins/s3/actions/GetObjectTaggingAction.d.ts +10 -0
- package/dist/plugins/s3/actions/HeadBucketAction.d.ts +8 -0
- package/dist/plugins/s3/actions/HeadObjectAction.d.ts +18 -0
- package/dist/plugins/s3/actions/ListBucketsAction.d.ts +15 -0
- package/dist/plugins/s3/actions/ListMultipartUploadsAction.d.ts +19 -0
- package/dist/plugins/s3/actions/ListObjectsAction.d.ts +31 -0
- package/dist/plugins/s3/actions/ListPartsAction.d.ts +14 -0
- package/dist/plugins/s3/actions/PutBucketAclAction.d.ts +11 -0
- package/dist/plugins/s3/actions/PutBucketCorsAction.d.ts +8 -0
- package/dist/plugins/s3/actions/PutBucketPolicyAction.d.ts +9 -0
- package/dist/plugins/s3/actions/PutBucketTaggingAction.d.ts +8 -0
- package/dist/plugins/s3/actions/PutObjectAclAction.d.ts +8 -0
- package/dist/plugins/s3/actions/PutObjectAction.d.ts +22 -0
- package/dist/plugins/s3/actions/PutObjectTaggingAction.d.ts +9 -0
- package/dist/plugins/s3/actions/UnknownAction.d.ts +7 -0
- package/dist/plugins/s3/actions/UploadPartAction.d.ts +12 -0
- package/dist/plugins/s3/actions/localAction.d.ts +92 -0
- package/dist/plugins/s3/calulcateETag.d.ts +1 -0
- package/dist/plugins/s3/commons/constants.d.ts +6 -0
- package/dist/plugins/s3/commons/utils.d.ts +3 -0
- package/dist/plugins/s3/errors/notFound.d.ts +8 -0
- package/dist/plugins/s3/errors/s3Error.d.ts +65 -0
- package/dist/plugins/s3/getLocalStoragePath.d.ts +1 -0
- package/dist/plugins/s3/index.d.ts +32 -0
- package/dist/plugins/s3/index.mjs +97 -0
- package/dist/plugins/s3/lib/createS3Server.d.ts +38 -0
- package/dist/plugins/s3/parsers/parseDeleteRequest.d.ts +10 -0
- package/dist/plugins/s3/parsers/parseGetRequest.d.ts +14 -0
- package/dist/plugins/s3/parsers/parseHeadRequest.d.ts +5 -0
- package/dist/plugins/s3/parsers/parsePostRequest.d.ts +7 -0
- package/dist/plugins/s3/parsers/parsePutRequest.d.ts +14 -0
- package/dist/plugins/s3/triggerEvent.d.ts +12 -0
- package/dist/plugins/sns/errors.d.ts +26 -0
- package/dist/plugins/sns/filter.d.ts +1 -0
- package/dist/plugins/sns/filter.test.d.ts +1 -0
- package/dist/plugins/sns/index.d.ts +23 -0
- package/dist/plugins/sns/index.mjs +106 -0
- package/dist/plugins/sns/parsers/parseCreateTopic.d.ts +2 -0
- package/dist/plugins/sns/parsers/parseMessage.d.ts +18 -0
- package/dist/plugins/sns/parsers/parsePublishMessage.d.ts +6 -0
- package/dist/plugins/sns/parsers/parsePublishMessageBatch.d.ts +9 -0
- package/dist/plugins/sns/parsers/parseSubscribe.d.ts +17 -0
- package/dist/plugins/sns/parsers/parseSubscriptionArn.d.ts +6 -0
- package/dist/plugins/sns/parsers/parseTopicArn.d.ts +4 -0
- package/dist/plugins/sns/server.d.ts +36 -0
- package/dist/plugins/sns/server.test.d.ts +1 -0
- package/dist/plugins/sns/subscriber/index.d.ts +61 -0
- package/dist/plugins/sns/subscriber/validateConfig.d.ts +0 -0
- package/dist/plugins/sns/topic.d.ts +91 -0
- package/dist/plugins/sns/utils.d.ts +20 -0
- package/dist/plugins/sns/validateFilterPolicy.d.ts +19 -0
- package/dist/plugins/sns/validateFilterPolicy.test.d.ts +1 -0
- package/dist/plugins/sqs/index.d.ts +16 -0
- package/dist/plugins/sqs/index.mjs +1 -0
- package/dist/plugins/sqs/types.d.ts +11 -0
- package/dist/plugins/sqs/utils.d.ts +7 -0
- package/dist/plugins/vitest/coverage.d.ts +6 -0
- package/dist/plugins/vitest/index.d.ts +29 -0
- package/dist/plugins/vitest/index.mjs +1 -0
- package/dist/standalone.d.ts +17 -0
- package/dist/standalone.js +13 -0
- package/dist/standalone.mjs +13 -0
- package/dist/standalone_types.d.ts +190 -0
- package/package.json +119 -0
- package/src/lib/runtime/runners/python/index.py +105 -0
- package/src/lib/runtime/runners/ruby/index.rb +67 -0
package/package.json
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "exlo",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A modular toolkit to emulate cloud services locally using high-quality built-in plugins and custom extensions. Includes support for Lambda, S3, SNS, SQS, REST API Gateway and more.",
|
|
5
|
+
"author": "Inqnuam",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/inqnuam/exlo",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/inqnuam/exlo.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/inqnuam/exlo/issues"
|
|
14
|
+
},
|
|
15
|
+
"main": "./dist/standalone.js",
|
|
16
|
+
"typings": "./dist/standalone.d.ts",
|
|
17
|
+
"module": "./dist/standalone.mjs",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/standalone.d.ts",
|
|
21
|
+
"import": "./dist/standalone.mjs",
|
|
22
|
+
"require": "./dist/standalone.js",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"./defineConfig": {
|
|
26
|
+
"types": "./dist/defineConfig.d.ts",
|
|
27
|
+
"import": "./dist/defineConfig.mjs",
|
|
28
|
+
"default": "./dist/defineConfig.mjs"
|
|
29
|
+
},
|
|
30
|
+
"./sns": {
|
|
31
|
+
"types": "./dist/plugins/sns/index.d.ts",
|
|
32
|
+
"import": "./dist/plugins/sns/index.mjs",
|
|
33
|
+
"default": "./dist/plugins/sns/index.mjs"
|
|
34
|
+
},
|
|
35
|
+
"./sqs": {
|
|
36
|
+
"types": "./dist/plugins/sqs/index.d.ts",
|
|
37
|
+
"import": "./dist/plugins/sqs/index.mjs",
|
|
38
|
+
"default": "./dist/plugins/sqs/index.mjs"
|
|
39
|
+
},
|
|
40
|
+
"./s3": {
|
|
41
|
+
"types": "./dist/plugins/s3/index.d.ts",
|
|
42
|
+
"import": "./dist/plugins/s3/index.mjs",
|
|
43
|
+
"default": "./dist/plugins/s3/index.mjs"
|
|
44
|
+
},
|
|
45
|
+
"./restApi": {
|
|
46
|
+
"types": "./dist/plugins/restApi/index.d.ts",
|
|
47
|
+
"import": "./dist/plugins/restApi/index.mjs",
|
|
48
|
+
"default": "./dist/plugins/restApi/index.mjs"
|
|
49
|
+
},
|
|
50
|
+
"./dynamodb": {
|
|
51
|
+
"types": "./dist/plugins/dynamodb/src/index.d.ts",
|
|
52
|
+
"import": "./dist/plugins/dynamodb/src/index.mjs",
|
|
53
|
+
"default": "./dist/plugins/dynamodb/src/index.mjs"
|
|
54
|
+
},
|
|
55
|
+
"./dynamodbProxy": {
|
|
56
|
+
"types": "./dist/plugins/dynamodb/src/proxy/index.d.ts",
|
|
57
|
+
"import": "./dist/plugins/dynamodb/src/proxy/index.mjs",
|
|
58
|
+
"default": "./dist/plugins/dynamodb/src/proxy/index.mjs"
|
|
59
|
+
},
|
|
60
|
+
"./vitest": {
|
|
61
|
+
"types": "./dist/plugins/vitest/index.d.ts",
|
|
62
|
+
"import": "./dist/plugins/vitest/index.mjs",
|
|
63
|
+
"default": "./dist/plugins/vitest/index.mjs"
|
|
64
|
+
},
|
|
65
|
+
"./internal/esm": {
|
|
66
|
+
"types": "./dist/lib/runtime/eventSourceMapping/base.d.ts",
|
|
67
|
+
"import": "./dist/lib/runtime/eventSourceMapping/base.mjs",
|
|
68
|
+
"default": "./dist/lib/runtime/eventSourceMapping/base.mjs"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"bin": {
|
|
72
|
+
"exlo": "dist/cli.mjs"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@aws-sdk/client-sns": "^3.891.0",
|
|
76
|
+
"@aws-sdk/client-sqs": "^3.891.0",
|
|
77
|
+
"@smithy/eventstream-codec": "^4.1.1",
|
|
78
|
+
"ajv": "^8.17.1",
|
|
79
|
+
"ajv-formats": "^3.0.1",
|
|
80
|
+
"esbuild": "^0.25.10",
|
|
81
|
+
"fast-xml-parser": "^5.2.5",
|
|
82
|
+
"local-aws-sqs": "^2.0.1"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@aws-sdk/client-dynamodb": "^3.891.0",
|
|
86
|
+
"@aws-sdk/client-dynamodb-streams": "^3.891.0",
|
|
87
|
+
"@aws-sdk/client-lambda": "^3.891.0",
|
|
88
|
+
"@aws-sdk/client-s3": "^3.892.0",
|
|
89
|
+
"@biomejs/biome": "2.2.4",
|
|
90
|
+
"@types/node": "^22.13.1",
|
|
91
|
+
"@vitest/coverage-istanbul": "3.2.4",
|
|
92
|
+
"@vitest/coverage-v8": "3.2.4",
|
|
93
|
+
"monocart-coverage-reports": "^2.12.9",
|
|
94
|
+
"typescript": "^5.9.2",
|
|
95
|
+
"vitest": "^3.2.4"
|
|
96
|
+
},
|
|
97
|
+
"keywords": [
|
|
98
|
+
"aws",
|
|
99
|
+
"serverless",
|
|
100
|
+
"local",
|
|
101
|
+
"apg",
|
|
102
|
+
"lambda",
|
|
103
|
+
"sns",
|
|
104
|
+
"sqs",
|
|
105
|
+
"s3",
|
|
106
|
+
"stream",
|
|
107
|
+
"dynamodb",
|
|
108
|
+
"invoke",
|
|
109
|
+
"nodejs",
|
|
110
|
+
"node",
|
|
111
|
+
"python",
|
|
112
|
+
"ruby"
|
|
113
|
+
],
|
|
114
|
+
"scripts": {
|
|
115
|
+
"dev": "DEV=true node ./build.mjs",
|
|
116
|
+
"build": "node ./build.mjs",
|
|
117
|
+
"test": "vitest"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import decimal
|
|
2
|
+
import sys
|
|
3
|
+
import os
|
|
4
|
+
import json
|
|
5
|
+
import importlib.util
|
|
6
|
+
from time import strftime, time
|
|
7
|
+
import traceback
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def decimal_serializer(o):
|
|
11
|
+
if isinstance(o, decimal.Decimal):
|
|
12
|
+
f = float(o)
|
|
13
|
+
if f.is_integer():
|
|
14
|
+
return int(f)
|
|
15
|
+
return f
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
handlerPath = sys.argv[1]
|
|
19
|
+
modulePath = sys.argv[2]
|
|
20
|
+
handlerName = sys.argv[3]
|
|
21
|
+
timeout = int(sys.argv[4])
|
|
22
|
+
sys.path.append(os.path.dirname(handlerPath))
|
|
23
|
+
|
|
24
|
+
class LambdaContext(object):
|
|
25
|
+
def __init__(self, reqId="1234567890"):
|
|
26
|
+
self.name = os.environ["AWS_LAMBDA_FUNCTION_NAME"]
|
|
27
|
+
self.version = "$LATEST"
|
|
28
|
+
self.created = time()
|
|
29
|
+
self.timeout = timeout
|
|
30
|
+
self.reqId = reqId
|
|
31
|
+
|
|
32
|
+
def get_remaining_time_in_millis(self):
|
|
33
|
+
return int(max((self.timeout * 1000) - (int(round(time() * 1000)) - int(round(self.created * 1000))), 0))
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def function_name(self):
|
|
37
|
+
return self.name
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def function_version(self):
|
|
41
|
+
return self.version
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def invoked_function_arn(self):
|
|
45
|
+
return 'arn:aws:lambda:us-east-1:123456789012:function:' + self.name
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def memory_limit_in_mb(self):
|
|
49
|
+
return os.environ["AWS_LAMBDA_FUNCTION_MEMORY_SIZE"]
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def aws_request_id(self):
|
|
53
|
+
return self.reqId
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def log_group_name(self):
|
|
57
|
+
return '/aws/lambda/' + self.name
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def log_stream_name(self):
|
|
61
|
+
return strftime('%Y/%m/%d') + '/[$' + self.version + ']58419525dade4d17a495dceeeed44708'
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def log(self):
|
|
65
|
+
return sys.stdout.write
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
spec = importlib.util.spec_from_file_location(modulePath, handlerPath)
|
|
69
|
+
module = importlib.util.module_from_spec(spec)
|
|
70
|
+
sys.modules[modulePath] = module
|
|
71
|
+
spec.loader.exec_module(module)
|
|
72
|
+
handler = getattr(module, handlerName)
|
|
73
|
+
|
|
74
|
+
_mods = [m.__name__ for m in sys.modules.values() if m]
|
|
75
|
+
|
|
76
|
+
watchFiles = json.dumps([x for x in _mods if x.startswith("src")])
|
|
77
|
+
print(f"__|watch|__{watchFiles}__|watchEnd|__", flush=True)
|
|
78
|
+
sys.stdout.flush()
|
|
79
|
+
|
|
80
|
+
for line in sys.stdin:
|
|
81
|
+
input = json.loads(line)
|
|
82
|
+
context = LambdaContext(input["awsRequestId"]) # input["context"]
|
|
83
|
+
try:
|
|
84
|
+
response = handler(input["event"], context)
|
|
85
|
+
jsonRes = json.dumps(response, default=decimal_serializer)
|
|
86
|
+
sys.stdout.flush()
|
|
87
|
+
print(f"__|response|__{jsonRes}__|responseEnd|__", flush=True)
|
|
88
|
+
sys.stdout.flush()
|
|
89
|
+
except:
|
|
90
|
+
error, ex_value, ex_traceback = sys.exc_info()
|
|
91
|
+
|
|
92
|
+
errorType = error.__name__
|
|
93
|
+
errorMessage = str(ex_value)
|
|
94
|
+
stackTrace = list()
|
|
95
|
+
trace_back = traceback.extract_tb(ex_traceback)
|
|
96
|
+
|
|
97
|
+
for trace in trace_back:
|
|
98
|
+
stackTrace.append(" File \"%s\", line %d, in %s\n %s\n" % (
|
|
99
|
+
trace[0], trace[1], trace[2], trace[3]))
|
|
100
|
+
|
|
101
|
+
stackTrace.pop(0)
|
|
102
|
+
jsonErr = json.dumps(
|
|
103
|
+
{'errorType': errorType, 'errorMessage': errorMessage, 'stackTrace': stackTrace}, default=decimal_serializer)
|
|
104
|
+
sys.stderr.write(f"__|error|__{jsonErr}")
|
|
105
|
+
sys.stderr.flush()
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
handler_path, handler_name, lambdaName, timeout = ARGV
|
|
4
|
+
require(handler_path)
|
|
5
|
+
|
|
6
|
+
class LambdaContext
|
|
7
|
+
attr_reader :function_name, :function_version, :aws_request_id, :log_stream_name, :memory_limit_in_mb,
|
|
8
|
+
:invoked_function_arn, :log_group_name, :deadline_ms
|
|
9
|
+
|
|
10
|
+
def initialize(lambdaName, timeout, awsRequestId)
|
|
11
|
+
@function_name = lambdaName
|
|
12
|
+
@function_version = "$LATEST"
|
|
13
|
+
@memory_limit_in_mb = ENV['AWS_LAMBDA_FUNCTION_MEMORY_SIZE']
|
|
14
|
+
@timeout = timeout.to_i
|
|
15
|
+
|
|
16
|
+
@aws_request_id = awsRequestId
|
|
17
|
+
@invoked_function_arn = "arn:aws:lambda:aws-region:123456789012:function:#{@function_name}"
|
|
18
|
+
@log_group_name = "/aws/lambda/#{@function_name}"
|
|
19
|
+
@log_stream_name = Time.now.strftime('%Y/%m/%d') +'/[$' + @function_version + ']58419525dade4d17a495dceeeed44708'
|
|
20
|
+
|
|
21
|
+
@created_time = Time.now
|
|
22
|
+
@deadline_ms = (@created_time + @timeout).to_i * 1000
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def get_remaining_time_in_millis
|
|
26
|
+
[@timeout * 1000 - ((Time.now - @created_time) * 1000).round, 0].max
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def log(message)
|
|
30
|
+
puts message
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
handler_method, handler_class = handler_name.split('.').reverse
|
|
36
|
+
handler_class ||= "Kernel"
|
|
37
|
+
|
|
38
|
+
cwd = Dir.pwd
|
|
39
|
+
watchFiles = JSON.generate($LOADED_FEATURES.select { |s| s.start_with?(cwd) })
|
|
40
|
+
puts "__|watch|__#{watchFiles}"
|
|
41
|
+
$stdout.flush
|
|
42
|
+
|
|
43
|
+
input = ""
|
|
44
|
+
while (line = STDIN.gets)
|
|
45
|
+
input += line
|
|
46
|
+
begin
|
|
47
|
+
json_input = JSON.parse(input)
|
|
48
|
+
context = LambdaContext.new(lambdaName, timeout, json_input['awsRequestId'])
|
|
49
|
+
response = Object.const_get(handler_class).send(handler_method, event: json_input['event'], context: context)
|
|
50
|
+
json_response = JSON.generate(response)
|
|
51
|
+
$stdout.flush
|
|
52
|
+
puts "__|response|__#{json_response}"
|
|
53
|
+
$stdout.flush
|
|
54
|
+
rescue Exception => e
|
|
55
|
+
error_type = e.class.to_s
|
|
56
|
+
error_message = e.message
|
|
57
|
+
stack_trace = e.backtrace.join("\n")
|
|
58
|
+
json_err = JSON.generate({
|
|
59
|
+
'errorType' => error_type,
|
|
60
|
+
'errorMessage' => error_message,
|
|
61
|
+
'stackTrace' => stack_trace
|
|
62
|
+
})
|
|
63
|
+
$stderr.puts("__|error|__#{json_err}")
|
|
64
|
+
ensure
|
|
65
|
+
input = ''
|
|
66
|
+
end
|
|
67
|
+
end
|