Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Support for nested state reference #13

Open
serverlessguru opened this issue Dec 4, 2019 · 2 comments
Open

Support for nested state reference #13

serverlessguru opened this issue Dec 4, 2019 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@serverlessguru
Copy link

Currently it appears to not be possible to reference a nested state object inside the serverless.yml file.

serverless.yml:

cognitoUserPool:
  component: '@serverless/aws-cognito'
  inputs:
    region: us-east-1
    authTemplate: COGNITO_USER_POOL

myAppSyncApi:
  component: "@serverless/aws-app-sync"
  inputs:
    name: appApi

    # Amazon Cognito Authentication
    authenticationType: AMAZON_COGNITO_USER_POOLS
    userPoolConfig:
      awsRegion: us-east-1
      defaultAction: ALLOW
      userPoolId: ${cognitoUserPool.app.poolId}

state file (Template.cognitoUserPool.json):

{
  "app": {
    "poolId": "us-east-1sxxxxxxx",
    "poolArn": "xxxxxxxxxxxxx",
    "clientId": "xxxxxxxxxxxxxxx"
  },
  "region": "us-east-1"
}

Error:

error:
  Error: invalid reference ${cognitoUserPool.app.poolId}
    at Object.<anonymous> (/usr/local/lib/node_modules/serverless/node_modules/@serverless/template/utils.js:59:17)
    at walker (/usr/local/lib/node_modules/serverless/node_modules/traverse/index.js:190:22)
    at /usr/local/lib/node_modules/serverless/node_modules/traverse/index.js:208:29
    at Array.forEach (<anonymous>)
    at forEach (/usr/local/lib/node_modules/serverless/node_modules/traverse/index.js:298:31)
    at walker (/usr/local/lib/node_modules/serverless/node_modules/traverse/index.js:203:13)
    at /usr/local/lib/node_modules/serverless/node_modules/traverse/index.js:208:29
    at Array.forEach (<anonymous>)
    at forEach (/usr/local/lib/node_modules/serverless/node_modules/traverse/index.js:298:31)
    at walker (/usr/local/lib/node_modules/serverless/node_modules/traverse/index.js:203:13)

  4s › usersLambda › Error: invalid reference ${cognitoUserPool.app.poolId}

Why would you want to do this?
When creating Serverless Components, you need to save state (e.g. this.save()) and it's much easier to logically group things together (by a key) than to have it all be flat inside the Template.cognitoUserPool.json object.

@medikoo
Copy link

medikoo commented Dec 4, 2019

Variable revolvers need to start with service token (as e.g. self:). In you're case I think you need to refer to file:service. See https://serverless.com/framework/docs/providers/aws/guide/variables/ for more info

@medikoo medikoo added the question Further information is requested label Dec 4, 2019
@medikoo
Copy link

medikoo commented Dec 4, 2019

Sorry, ignore my comment, I was referring to SLS v1

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants