From fe07475c82f84ec8b03dc90f78f1f7f0ff228636 Mon Sep 17 00:00:00 2001 From: Richard Tan Date: Mon, 15 Jun 2020 22:36:53 +1000 Subject: [PATCH 1/2] feat: Resolve Fn::Join in environment variables --- src/lambda/LambdaFunction.js | 3 ++- src/utils/resolveJoins.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/utils/resolveJoins.js diff --git a/src/lambda/LambdaFunction.js b/src/lambda/LambdaFunction.js index cc3fecda2..8a4f92692 100644 --- a/src/lambda/LambdaFunction.js +++ b/src/lambda/LambdaFunction.js @@ -6,6 +6,7 @@ import jszip from 'jszip' import HandlerRunner from './handler-runner/index.js' import LambdaContext from './LambdaContext.js' import serverlessLog from '../serverlessLog.js' +import resolveJoins from '../utils/resolveJoins.js' import { DEFAULT_LAMBDA_MEMORY_SIZE, DEFAULT_LAMBDA_RUNTIME, @@ -77,7 +78,7 @@ export default class LambdaFunction { this._verifySupportedRuntime() const env = this._getEnv( - provider.environment, + resolveJoins(provider.environment), functionDefinition.environment, handler, ) diff --git a/src/utils/resolveJoins.js b/src/utils/resolveJoins.js new file mode 100644 index 000000000..1a57483b8 --- /dev/null +++ b/src/utils/resolveJoins.js @@ -0,0 +1,20 @@ +// Used to resolve Fn::Join in environment variables +export default function resolveJoins(environment) { + const newEnv = {} + + Object.keys(environment).forEach((key) => { + const value = environment[key] + const joinArray = value['Fn::Join'] + const isJoin = Boolean(joinArray) + + if (isJoin) { + const separator = joinArray[0] + const joined = joinArray[1].join(separator) + newEnv[key] = joined + } else { + newEnv[key] = value + } + }) + + return newEnv +} From f089c13987580ef5d7ebb85e1f7c27d53a17590b Mon Sep 17 00:00:00 2001 From: Richard Tan Date: Wed, 24 Jun 2020 00:18:43 +1000 Subject: [PATCH 2/2] Handle undefined --- src/utils/resolveJoins.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/utils/resolveJoins.js b/src/utils/resolveJoins.js index 1a57483b8..8b81b39f1 100644 --- a/src/utils/resolveJoins.js +++ b/src/utils/resolveJoins.js @@ -1,5 +1,9 @@ // Used to resolve Fn::Join in environment variables export default function resolveJoins(environment) { + if (!environment) { + return undefined + } + const newEnv = {} Object.keys(environment).forEach((key) => {