Skip to content

Commit

Permalink
feat: copy all AWS_xxx environment variables from local
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Jul 27, 2022
1 parent fbdb162 commit c6d5546
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/lambda/LambdaFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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')
Expand Down

0 comments on commit c6d5546

Please sign in to comment.