forked from aws/aws-lambda-runtime-interface-emulator
-
Notifications
You must be signed in to change notification settings - Fork 2
fix: HOME fallback for custom container user #88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,85 @@ | ||
| # Test: Home Directory Fix (Node.js 22, --user=1000:1000) | ||
|
|
||
| ## Step 1 — Build the binary | ||
|
|
||
| ```bash | ||
| make compile-with-docker | ||
| # produces bin/aws-lambda-rie-x86_64 | ||
| ``` | ||
|
|
||
| ## Step 2 — Create the function file | ||
|
|
||
| ```bash | ||
| mkdir -p /tmp/fn-homedir | ||
| cat > /tmp/fn-homedir/index.js << 'EOF' | ||
| exports.handler = async () => { | ||
| const os = require("os"); | ||
| const homeEnv = process.env.HOME; | ||
| const debug = { | ||
| HOME_env: homeEnv === undefined ? null : homeEnv, | ||
| has_HOME_key: Object.prototype.hasOwnProperty.call(process.env, "HOME"), | ||
| }; | ||
| try { | ||
| const h = os.homedir(); | ||
| return { statusCode: 200, body: JSON.stringify({ ok: true, ...debug, homedir: h }) }; | ||
| } catch (e) { | ||
| return { | ||
| statusCode: 500, | ||
| body: JSON.stringify({ | ||
| ok: false, ...debug, | ||
| name: e.name, code: e.code, message: e.message, | ||
| syscall: e.syscall, errno: e.errno, info: e.info, | ||
| }), | ||
| }; | ||
| } | ||
| }; | ||
| EOF | ||
| ``` | ||
|
|
||
| ## Step 3 — Start LocalStack with your binary and --user=1000:1000 | ||
|
|
||
| The binary path must be mounted into the LocalStack container via `DOCKER_FLAGS`, then | ||
| referenced via `LAMBDA_INIT_BIN_PATH` using the in-container path. | ||
|
|
||
| ```bash | ||
| DOCKER_FLAGS="-v $(pwd)/bin:/lambda-bin" \ | ||
| LAMBDA_DOCKER_FLAGS="--user=1000:1000" \ | ||
| LAMBDA_INIT_BIN_PATH=/lambda-bin/aws-lambda-rie-x86_64 \ | ||
| localstack start -d | ||
|
|
||
| localstack wait -t 60 | ||
| ``` | ||
|
|
||
| > **Note:** LocalStack warns to use `LOCALSTACK_`-prefixed env vars — both forms work. | ||
|
|
||
| ## Step 4 — Deploy and invoke | ||
|
|
||
| ```bash | ||
| # Zip the function | ||
| cd /tmp/fn-homedir && zip function.zip index.js && cd - | ||
|
|
||
| # Create the function | ||
| awslocal lambda create-function \ | ||
| --function-name homedir-test \ | ||
| --runtime nodejs22.x \ | ||
| --handler index.handler \ | ||
| --role arn:aws:iam::000000000000:role/lambda-role \ | ||
| --zip-file fileb:///tmp/fn-homedir/function.zip | ||
|
|
||
| # Wait for it to be active | ||
| awslocal lambda wait function-active --function-name homedir-test | ||
|
|
||
| # Invoke and pretty-print the response | ||
| awslocal lambda invoke \ | ||
| --function-name homedir-test \ | ||
| --payload '{}' \ | ||
| /tmp/fn-homedir/response.json && cat /tmp/fn-homedir/response.json | ||
| ``` | ||
|
|
||
| ## Expected output (with the EnsureHome() fix) | ||
|
|
||
| ```json | ||
| {"statusCode":200,"body":"{\"ok\":true,\"HOME_env\":\"/tmp\",\"has_HOME_key\":true,\"homedir\":\"/tmp\"}"} | ||
| ``` | ||
|
|
||
| Without the fix you'd get `statusCode: 500` with `"code":"ENOENT"`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.