Skip to content

Commit 46977dd

Browse files
committed
remove loader scripts
1 parent 023e55a commit 46977dd

File tree

5 files changed

+36
-101
lines changed

5 files changed

+36
-101
lines changed

lambda-layer/packages/layer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"lint:fix": "eslint . --ext .ts --fix",
2222
"prepare": "npm run compile",
2323
"compile": "webpack && ./install-externals.sh",
24-
"postcompile": "copyfiles -f 'src/**/*.mjs' build/workspace && copyfiles -f 'scripts/*' build/workspace && copyfiles -f 'build/src/*' build/workspace && cd build/workspace && bestzip ../layer.zip *"
24+
"postcompile": "copyfiles -f 'scripts/*' build/workspace && copyfiles -f 'build/src/*' build/workspace && cd build/workspace && bestzip ../layer.zip *"
2525
},
2626
"keywords": [
2727
"awsdistroopentelemetry",

lambda-layer/packages/layer/scripts/otel-instrument

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,39 @@
11
#!/bin/bash
2+
_is_esm_handler() {
3+
# Lambda function root directory
4+
TASK_DIR="/var/task"
25

3-
export NODE_OPTIONS="${NODE_OPTIONS} --import /opt/init.mjs"
6+
# Flag variables to track conditions
7+
local found_mjs=false
8+
local is_module=false
9+
10+
# Check for any files ending with `.mjs`
11+
if ls "$TASK_DIR"/*.mjs &>/dev/null; then
12+
found_mjs=true
13+
fi
14+
15+
# Check if `package.json` exists and if it contains `"type": "module"`
16+
if [ -f "$TASK_DIR/package.json" ]; then
17+
# Check for the `"type": "module"` attribute in `package.json`
18+
if grep -q '"type": *"module"' "$TASK_DIR/package.json"; then
19+
is_module=true
20+
fi
21+
fi
22+
23+
# Return true if both conditions are met
24+
if $found_mjs || $is_module; then
25+
return 0 # 0 in bash means true
26+
else
27+
return 1 # 1 in bash means false
28+
fi
29+
}
30+
31+
if _is_esm_handler || [[ ${HANDLER_IS_ESM} == true ]]; then
32+
export NODE_OPTIONS="${NODE_OPTIONS} --import /opt/wrapper.js --experimental-loader=import-in-the-middle/hook.mjs"
33+
export HANDLER_IS_ESM=true
34+
else
35+
export NODE_OPTIONS="${NODE_OPTIONS} --require /opt/wrapper.js"
36+
fi
437

538
export LAMBDA_RESOURCE_ATTRIBUTES="cloud.region=$AWS_REGION,cloud.provider=aws,faas.name=$AWS_LAMBDA_FUNCTION_NAME,faas.version=$AWS_LAMBDA_FUNCTION_VERSION,faas.instance=$AWS_LAMBDA_LOG_STREAM_NAME,aws.log.group.names=$AWS_LAMBDA_LOG_GROUP_NAME";
639

lambda-layer/packages/layer/src/init.mjs

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

lambda-layer/packages/layer/src/loader.mjs

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

lambda-layer/packages/layer/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = {
1717
}
1818
},
1919
resolve: {
20-
extensions: ['.ts', '.js', '.mjs'],
20+
extensions: ['.ts', '.js'],
2121
modules: [
2222
path.resolve('./src'),
2323
'node_modules',

0 commit comments

Comments
 (0)