Skip to content

Invoke local AWS function ImportValue, GetAtt, Ref resolution #8147

Description

@fredericbarthelet

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions