Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference Variable in JavaScript returned Resolved Promise Failing #6022

Open
gregl83 opened this issue Apr 16, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@gregl83
Copy link

commented Apr 16, 2019

This is a Bug Report

Description

Following the instruction from: Serverless Variables

Implemented the returned Promise (async); however, an error is thrown whereas the same function works if just a string is returned.

Logging from getValueFromSource shows that each time a Promise is returned there are additional calls for AWS variables that didn't exist when just a string was returned:

variable AWS::Partition property arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/undefined:*
variable AWS::Region property arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/undefined:*
variable AWS::AccountId property arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/undefined:*
variable AWS::Partition property arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/undefined:*:*
variable AWS::Region property arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/undefined:*:*
variable AWS::AccountId property arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/undefined:*:*

Additionally, several of the _fulfillmentHandler0 properties of getValueFromFile results have various errors the first being the one reported below.

function.js

module.exports.FN = () => {
    const val = "value";
    //return val;
    return Promise.resolve(val);
};

serverless.yml

service: example
frameworkVersion: ">=1.28.0 <2.0.0"
provider:
  name: aws
  runtime: go1.x
environment:
  FN: ${self:custom.FN}
package:
 exclude:
   - ./**
 include:
   - ./bin/**
functions:
   read:
     handler: bin/read
plugins:
  - serverless-sam
custom:
  stage: ${opt:stage, self:provider.stage}
  FN: ${file(function.js):FN}

Similar or dependent issues:

Additional Data

  • Serverless Framework Version you're using: 1.40.0
  • Operating System: Ubuntu 18.04.2 LTS
  • Stack Trace:
ServerlessError: Invalid variable reference syntax for variable AWS::Partition. You can only reference env vars, options, & files. You can check our docs for more info.
    at Variables.getValueFromSource (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:546:32)
    at Variables.splitAndGet (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:397:17)
    at _.map (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:334:43)
    at arrayMap (/home/gregl83/n/lib/node_modules/serverless/node_modules/lodash/lodash.js:639:23)
    at Function.map (/home/gregl83/n/lib/node_modules/serverless/node_modules/lodash/lodash.js:9556:14)
    at Variables.populateMatches (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:334:14)
    at Variables.populateValue (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:365:30)
    at _.map.variable (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:249:24)
    at arrayMap (/home/gregl83/n/lib/node_modules/serverless/node_modules/lodash/lodash.js:639:23)
    at Function.map (/home/gregl83/n/lib/node_modules/serverless/node_modules/lodash/lodash.js:9556:14)
    at Variables.populateVariables (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:248:14)
    at Variables.populateObjectImpl (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:277:30)
    at assignProperties.then (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:282:24)
From previous event:
    at Variables.populateObjectImpl (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:282:8)
    at prepopulateService.then (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:161:26)
From previous event:
    at initialCall (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:161:10)
    at Variables.initialCall (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:67:12)
    at Variables.populateService (/home/gregl83/n/lib/node_modules/serverless/lib/classes/Variables.js:159:17)
    at SamPlugin.prepareTemplate (/home/gregl83/Code/go/src/github.com/gregl83/serverless-template-build/node_modules/serverless-sam/index.js:153:31)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)
  • Provider Error messages:
    Invalid variable reference syntax for variable AWS::Partition. You can only reference env vars, options, & files. You can check our docs for more info.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.