diff --git a/src/lambda/LambdaFunction.js b/src/lambda/LambdaFunction.js index 148c8ed46..f0a3bd8bc 100644 --- a/src/lambda/LambdaFunction.js +++ b/src/lambda/LambdaFunction.js @@ -15,7 +15,7 @@ import { } from '../config/index.js' import { createUniqueId, splitHandlerPathAndName } from '../utils/index.js' -const { entries } = Object +const { entries, fromEntries } = Object const { ceil } = Math export default class LambdaFunction { @@ -97,7 +97,12 @@ export default class LambdaFunction { this.#verifySupportedRuntime() const env = { - ...(options.localEnvironmentVariables && process.env), + ...(options.localEnvironmentVariables + ? process.env + : // we always copy all AWS_xxxx environment variables over from local env + fromEntries( + entries(process.env).filter(([key]) => key.startsWith('AWS_')), + )), ...this.#getAwsEnvVars(), ...provider.environment, ...functionDefinition.environment, diff --git a/tests/lambda-run-mode/worker-threads/env-vars/worker-threads-env-vars.test.js b/tests/lambda-run-mode/worker-threads/env-vars/worker-threads-env-vars.test.js index e725d4d78..f01693674 100644 --- a/tests/lambda-run-mode/worker-threads/env-vars/worker-threads-env-vars.test.js +++ b/tests/lambda-run-mode/worker-threads/env-vars/worker-threads-env-vars.test.js @@ -10,6 +10,8 @@ describe('run mode with worker threads', function desc() { beforeEach(() => setup({ env: { + AWS_ACCESS_KEY_ID: 'SHOULD_BE_SHARED', + AWS_FOOBAR: 'SHOULD_BE_SHARED', ENV_SHOULD_NOT_BE_SHARED: 'ENV_SHOULD_NOT_BE_SHARED', }, servicePath: resolve(__dirname), @@ -25,6 +27,9 @@ describe('run mode with worker threads', function desc() { assert.equal(response.status, 200) const json = await response.json() + + assert.equal(json.env.AWS_ACCESS_KEY_ID, 'SHOULD_BE_SHARED') + assert.equal(json.env.AWS_FOOBAR, 'SHOULD_BE_SHARED') assert.equal(json.env.ENV_FUNCTIONS_FOO, 'ENV_FUNCTIONS_BAR') assert.equal(json.env.ENV_PROVIDER_FOO, 'ENV_PROVIDER_BAR') assert.equal(json.env.ENV_SHOULD_NOT_BE_SHARED, undefined) diff --git a/tests/lambda-run-mode/worker-threads/local-env-vars/worker-threads-local-env-vars.test.js b/tests/lambda-run-mode/worker-threads/local-env-vars/worker-threads-local-env-vars.test.js index f18ad0e6a..6d01cbdb8 100644 --- a/tests/lambda-run-mode/worker-threads/local-env-vars/worker-threads-local-env-vars.test.js +++ b/tests/lambda-run-mode/worker-threads/local-env-vars/worker-threads-local-env-vars.test.js @@ -10,6 +10,8 @@ describe('run mode with worker threads and --localEnvironmentVariables flag', fu beforeEach(() => setup({ env: { + AWS_ACCESS_KEY_ID: 'SHOULD_BE_SHARED', + AWS_FOOBAR: 'SHOULD_BE_SHARED', ENV_SHOULD_BE_SHARED: 'ENV_SHOULD_BE_SHARED', }, servicePath: resolve(__dirname), @@ -25,6 +27,9 @@ describe('run mode with worker threads and --localEnvironmentVariables flag', fu assert.equal(response.status, 200) const json = await response.json() + + assert.equal(json.env.AWS_ACCESS_KEY_ID, 'SHOULD_BE_SHARED') + assert.equal(json.env.AWS_FOOBAR, 'SHOULD_BE_SHARED') assert.equal(json.env.ENV_FUNCTIONS_FOO, 'ENV_FUNCTIONS_BAR') assert.equal(json.env.ENV_PROVIDER_FOO, 'ENV_PROVIDER_BAR') assert.equal(json.env.ENV_SHOULD_BE_SHARED, 'ENV_SHOULD_BE_SHARED')