AWS SAM template is an abstraction layer, runs on the top of CloudFormation, for creating serverless resources. So, when you run a SAM template to create a Lambda function or an API gateway, it generates a CloudFormation stack behind the scene. The main purpose is ease-of-management of serverless resources in AWS.