CloudFormation stack reference: Invalid syntax

Hi, I’m referencing the outputs of a cloudformation stack but I’m getting an invalid syntax error, and I can’t understand why.

provider:
  name: aws
  region: us-west-2
  stage: ${opt:stage, self:custom.default_stage}
  runtime: nodejs6.10
  environment:
    stage: ${self:provider.stage}
    userPoolId: ${cf:MyStack.${self:provider.stage}CustomerPool}
    userPoolClient: ${cf:MyStack.${self:provider.stage}CustomerPoolClient}

custom:
  default_stage: dev

When I do this, I get the following error: Invalid variable reference syntax for variable cf:MyStack.devCustomerPool. Which, of course, is the correct way to reference stack outputs as defined in the docs. I have double checked that indeed MyStack does exist, and it does have an output with the key devCustomerPool. So why am I getting this error?

Addendum:
This still does’t work even if I remove nested variables:

provider:
  name: aws
  region: us-west-2
  stage: ${opt:stage, self:custom.default_stage}
  runtime: nodejs6.10
  environment:
    stage: ${self:provider.stage}
    devUserPoolId: ${cf:MyStack.devCustomerPool}
    devUserPoolClient: ${cf:MyStack.devCustomerPoolClient}

custom:
  default_stage: dev

Still throws invalid variable reference syntax for variable cf:MyStack.devCustomerPoolClient.

Did you ever figure this out? I thought I had this working and returned to my code after a while and am now am getting the above error.

I ended up using ‘Fn::ImportValue’. E.g.:

provider:
  name: aws
  region: us-west-2
  stage: ${opt:stage, self:custom.default_stage}
  runtime: nodejs6.10
  memorySize: 128
  environment:
    stage: ${self:provider.stage}
    userPoolId:
      'Fn::ImportValue': '${self:provider.stage}-CustomerPool'
1 Like

My problem ended up being easier/stupider :slight_smile: I was using a global install of sls that was an old version. Once I ran the local, updated, version it worked.

Looks like an older version of Serverless didn’t parse environment variables - the syntax was being passed directly to CFN, and it obviously didn’t like it.