You can achieve this using Outputs
section of SAM template.
You can check the AWS SAM template anatomy to understand better.
Outputs (optional)
The values that are returned whenever you view your stack's properties. For example, you can declare an output for an S3 bucket
name, and then call the aws cloudformation describe-stacks AWS Command
Line Interface (AWS CLI) command to view the name. This section corresponds directly with the Outputs section of AWS CloudFormation templates.
You will need to make use of Intrinsic functions within your Outputs
section to print out the final resolved value at runtime.
Outputs:
BackupLoadBalancerDNSName:
Description: The DNSName of the backup load balancer
Value: !GetAtt BackupLoadBalancer.DNSName
Condition: CreateProdResources
InstanceID:
Description: The Instance ID
Value: !Ref EC2Instance
If you just wish to validate if your SAM
is correct or not you could use the following command:
$ sam validate
Posting the answer here so that it may help others in future!