Past 5 Solutions Inc.

Leverage managed infrastructure

Serverless vs SAM: Deploy a Scalable Web App in Five Minutes

To validate your market idea, you want to develop and deploy your prototype as soon as possible and iterate on it. When building a proof of concept or minimally viable version of your product, the last thing you want is to be slowed down by infrastructure and operations. Worry about that after you validate your idea and have paying customers.

The serverless model has transformed software development by eliminating the need to manage your application infrastructure. Serverless leverages your cloud provider data center capabilities to manage your infrastructure. Adopting a serverless model means faster application development and deployment while leaving scaling and securing your infrastructure to your cloud partner.

According to the State of Serverless studies done by Datadog in 2021 and 2022, over 70 percent of organizations running in AWS cloud adopted serverless functionality.

The two frameworks that help the development of serverless infrastructure are Serverless by Serverless Inc. and Serverless Application Model (SAM) by Amazon Web Services (AWS). These frameworks enable you to deploy and get started with your application in minutes.

Both Serverless and SAM act as shorthand for complex declarative infrastructure templates. In addition, they give you CLI tools that allow you to deploy and manage your application from the command line.

Serverless supports different cloud platforms, such as Google Cloud and Microsoft Azure Cloud, in addition to Amazon Web Services (AWS), and gives a web-accessible UI and dashboards.

AWS SAM provides a local Lambda-like execution environment and integrates with AWS SAR (Serverless Application Repository) for publishing serverless applications in AWS.

Here's how you can deploy your app using Serverless in five minutes:

  1. Install the Serverless Framework using npm, which is the Node.js package manager. Run the following command: npm install -g serverless
  2. Create a new directory for your Serverless project and navigate to it in your terminal.
  3. Initialize your project by running the serverless command and following the prompts. This will create a serverless.yml file, which is the main configuration file for your Serverless app.
  4. In your serverless.yml file, define your app's service, provider, and functions. A service represents your entire app, the provider is the cloud provider you are deploying to (e.g. AWS), and a function represents a specific piece of functionality in your app.
  5. Set up your cloud provider credentials by following the provider's instructions. This will typically involve creating an account, creating a new IAM user with appropriate permissions, and storing the IAM user's access key and secret key in a local file or environment variables.
  6. Deploy your app by running the serverless deploy command in your terminal. This will create all necessary resources on your cloud provider and deploy your app.
  7. Test your app by calling its various functions using the provided URLs or by using the provider's API gateway.

Here's how you can deploy your app using SAM in five minutes:

  1. Install the SAM CLI by running the npm install -g aws-sam-local command. This will allow you to locally test and debug your application before deploying it to AWS.
  2. Create a template.yaml file that defines the AWS resources that your application will use. This file should include information about your application's code, any necessary IAM roles, and the AWS Lambda functions that will be triggered by incoming requests.
  3. Install the necessary Node.js dependencies for your application by running the npm install command. This will add the required packages to the node_modules directory and update the package.json file with the dependencies.
  4. Test your application locally using the SAM CLI by running the sam local start-api command. This will spin up a local server that you can use to test your application.
  5. Once you are satisfied with the local version of your application, you can deploy it to AWS by running the sam deploy --guidedcommand. This will guide you through the process of creating a new AWS CloudFormation stack and deploying your application to it.
  6. After the deployment is complete, you can access your application at the provided URL.