Use case description
Considering the following function configuration :
myFunction:
handler: myHandler.main
environment:
stringEnv: 'myEnv'
importValueEnv:
Fn::ImportValue: 'import-key'
getAttEnv:
Get::Att: ['resource', 'arn']
Invoking this function locally will not resolve AWS functions before inserting those in lambda env context : process.env.importValueEnv and process.env.getAttEnv will be object. In order for this function to be invoked locally properly, one would have to run the following command :
sls invoke local -f myFunction -e importValueEnv="import-value" -e getAttEnv="resourceArn"
where import-value and resourceArn have to be manually retrieved (through the AWS web console for exemple).
Proposed solution
Resolving AWS magical functions when found within function or provider environment configuration.
Modifying existing getConfiguredEnvVars function at
|
getConfiguredEnvVars() { |
|
const providerEnvVars = this.serverless.service.provider.environment || {}; |
|
const functionEnvVars = this.options.functionObj.environment || {}; |
|
return _.merge(providerEnvVars, functionEnvVars); |
|
} |
by using
/Users/Frederic/Sites/serverless/lib/plugins/aws/utils/resolveCfImportValue.js
After such feature, it won't be needed to override manually AWS resolvable env variable and the following command sls invoke local -f myFunction will work out of the box.
The issue could be split in :
- implementing this solution for Fn::ImportValue
- implementing the util for GetAtt resolution and implementing it in invoke local env resolution
- implementing the util for any other required AWS magical function resolution ( Ref especially ? ) and implementing it in invoke local env resolution
Use case description
Considering the following function configuration :
Invoking this function locally will not resolve AWS functions before inserting those in lambda env context :
process.env.importValueEnvandprocess.env.getAttEnvwill be object. In order for this function to be invoked locally properly, one would have to run the following command :sls invoke local -f myFunction -e importValueEnv="import-value" -e getAttEnv="resourceArn"where
import-valueandresourceArnhave to be manually retrieved (through the AWS web console for exemple).Proposed solution
Resolving AWS magical functions when found within function or provider environment configuration.
Modifying existing
getConfiguredEnvVarsfunction atserverless/lib/plugins/aws/invokeLocal/index.js
Lines 146 to 150 in ffd1b36
/Users/Frederic/Sites/serverless/lib/plugins/aws/utils/resolveCfImportValue.jsAfter such feature, it won't be needed to override manually AWS resolvable env variable and the following command
sls invoke local -f myFunctionwill work out of the box.The issue could be split in :