Setting environmental variables with !Ref in AWS SAM?


I’m using SAM CLI v0.8.1. I’m trying to set environmental variable MY_TABLE_VAR as name of the table in my resources (MyTableResource). However, while running my app locally, the MY_TABLE_VAR is undefined. Can you tell me what’s wrong in my template and how can I set it properly? Following is my SAM template:


From my understanding, the Globals section cannot reference resources in the Resources section (the dependency is in the other direction, since whatever is added to the Globals section is added to all Serverless Functions and APIs in the Resourcessection). To work around this, I suggest that you use either Mappings or Parameters, e.g.

Leave a Reply