Unable to reference CloudFormation resource in serverless.yml. Invalid variable reference syntax for variable UserPoolId Unable to reference CloudFormation resource in serverless.yml. Invalid variable reference syntax for variable UserPoolId node.js node.js

Unable to reference CloudFormation resource in serverless.yml. Invalid variable reference syntax for variable UserPoolId


After taking some time off the computer, I thought that the problem could be somewhere else which is what the case here.

I was using ${UserPoolId} under environment variables and realized that this is where the problem lies. I changed to the following way and the problem got solved. I was not referencing user pool ID correctly (it was referencing serverless.yml local variable named UserPoolId which didn't exist)

userPoolId:       Ref: UserPool

This was just my mistake and is now solved.


I found whilst writing my template it sometimes would do incorrect syntax highlighting and I would have to write it so that it couldn't check.

Ref: UserPool

Fn::Sub: '${UserPool}'

By swapping it with Substitute, it cannot check that the contents of the string are valid and then it will construct a string containing the Ref to the UserPool, or the user pool id

Fn::Sub documentation