No, it’s not a bug; How can you reference a variable variable that doesn’t exist?
When you first deploy the stack there are no outputs to reference, so it fails. These kinds of variables are useful if you first deploy your resource (i.e. RDS in this case) and then - in a separate stack/service - reference it in your function.
@rowanu How would you setup automated deploy of such service, then? (If I didn’t get the advice from @buggy.) I thought Serverless creates the resources first and then resolves the variables. I found few more similar problems (one of them was a policy on some resource for the lambda role which I had to remove for the first deploy, but I don’t remember exactly), maybe Serverless could distinguish between some setup deploy and the subsequent ones?
If it had to make that distinction between setup/not-setup deployments, then it wouldn’t be idempotent.
While what you’re describing would be convenient, there are many strange and wonderful ways such an approach can fail e.g. What if there was bug in the logic and SLS thought it was doing the setup run, and it wasn’t? What if some of your setup process completed successfully, but not all of it - should SLS do the setup run because some dependencies are missing, or should it do no setup because some are present?
The key is to separate your service and its dependencies, and not to deploy them all at once; Deploy you dependencies first, and then the thing that depends on them.
This has the added benefit that by calling out your dependencies explicitly (i.e. by putting them in another stack/service), you make things much easier to maintain and troubleshoot in the future.