Skip to content

Commit 88d291d

Browse files
init (#2)
1 parent 659d340 commit 88d291d

13 files changed

+252
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
layer.zip

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
11
# aws-lambda-abap-runtime
22
AWS Lambda ABAP custom runtime
3+
4+
# Usage
5+
6+
Add a Node.Js layer from this repository https://github.com/lambci/node-custom-lambda to the lambda function
7+
8+
Run this commands to create the abap runtime layer as zip file.
9+
10+
```sh
11+
npm install
12+
sh /scripts/create_layer.sh
13+
```
14+
15+
Add this layer as second layer to the lambda function. Via manual Upload or with the command from /scripts/publich_layer.sh.
16+
17+
Create a file with the name `zcl_handler.clas.abap` in the lambda function. It could looks like the the file in the test folder.

abaplint.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"global": {
3+
"files": "/src/*.*",
4+
"skipGeneratedGatewayClasses": true,
5+
"skipGeneratedPersistentClasses": true,
6+
"skipGeneratedFunctionGroups": true
7+
},
8+
"syntax": {
9+
"version": "v702",
10+
"errorNamespace": "."
11+
},
12+
"rules": {
13+
"when_others_last": true,
14+
"avoid_use": {
15+
"define": true,
16+
"execSQL": true,
17+
"kernelCall": true,
18+
"communication": true,
19+
"systemCall": true,
20+
"break": true,
21+
"statics": true
22+
},
23+
"parser_error": true,
24+
"unknown_types": true,
25+
"check_syntax": true,
26+
"functional_writing": true,
27+
"obsolete_statement": {
28+
"refresh": true,
29+
"compute": true,
30+
"requested": true,
31+
"setExtended": true,
32+
"occurs": true
33+
}
34+
}
35+
}

bootstrap

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
set -euo pipefail
4+
5+
# Initialization - load function handler
6+
sourcecode=$(cat $LAMBDA_TASK_ROOT/$_HANDLER)
7+
8+
# Processing
9+
while true
10+
do
11+
HEADERS="$(mktemp)"
12+
# Get an event. The HTTP request will block until one is received
13+
EVENT_DATA=$(curl -sS -LD "$HEADERS" -X GET "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/next")
14+
15+
# Extract request ID by scraping response headers received above
16+
REQUEST_ID=$(grep -Fi Lambda-Runtime-Aws-Request-Id "$HEADERS" | tr -d '[:space:]' | cut -d: -f2)
17+
18+
# Execute the handler function from the script
19+
cd /opt/
20+
RESPONSE=$(sourcecode=$sourcecode event=$EVENT_DATA _HANDLER='zcl_handler.clas.abap' node runtime.js)
21+
22+
# Send the response
23+
curl -X POST "http://${AWS_LAMBDA_RUNTIME_API}/2018-06-01/runtime/invocation/$REQUEST_ID/response" -d "$RESPONSE"
24+
done

package-lock.json

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

package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"private": true,
3+
"name": "aws-lambda-abap-runtime",
4+
"version": "0.0.1",
5+
"description": "AWS Lambda ABAP custom runtime",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "{{ authors }}",
11+
"license": "MIT",
12+
"devDependencies": {
13+
"@abaplint/transpiler": "^0.4.4"
14+
},
15+
"dependencies": {
16+
"@abaplint/runtime": "^0.4.4"
17+
}
18+
}

runtime.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const transpiler = require('./transpiler');
2+
3+
async function start_runtime() {
4+
const handlerClassString = await transpiler.transpile(process.env._HANDLER, process.env.sourcecode);
5+
const requireString = "const abap = require('@abaplint/runtime');\n";
6+
const event = process.env.event;
7+
const evalString = 'new (' + handlerClassString + ')().run(' + event + ')';
8+
const response = eval(requireString + evalString);
9+
console.log(response);
10+
}
11+
12+
start_runtime();

scripts/create_layer.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
zip layer.zip -r node_modules bootstrap runtime.js transpiler.js abaplint.json package.json

scripts/publish_layer.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
3+
aws lambda publish-layer-version --layer-name abap-runtime --compatible-runtimes provided --zip-file fileb://layer.zip

test/bootstrap.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
echo "start"
4+
sourcecode=$(cat ./test/zcl_handler.clas.abap)
5+
event='{"event":"eventdata"}'
6+
response=$(sourcecode=$sourcecode event=$event _HANDLER='zcl_handler.clas.abap' node ./test/runtime.js)
7+
echo $response
8+
echo "ende"

0 commit comments

Comments
 (0)