AWS

How to Use AWS SAM (Serverless Application Model)?

AWS Serverless Application Model is used to build application models that are serverless on the cloud using SAM commands. The serverless application does not mean that there are no servers involved in deploying the application. Whereas the platform is responsible for managing these servers and other provisioning of the application.

This guide will demonstrate the use of AWS SAM.

How to Use AWS SAM (Serverless Application Model)?

To use AWS SAM, open the “Terminal” from the local system:

It is required to install AWS SAM CLI on the local system to start using it. Run the following command to check the installation of the SAM:

sam --version

Running the above command will display the installed version of the SAM CLI which in this scenario is “1.68.0”:

Initialize the SAM application by using the following command:

sam init

Executing the above command will prompt the user to select the “Templates” for the application:

After that, the terminal will inquire to set the default runtime and package type or change it. The default configurations differ for different systems and the user can choose accordingly:

Enter the name of the “Project” for the SAM:

Once the project directory is created, simply head into it by using the following command:

cd sam-app-test

Inside the directory, use the following command to display the list of files:

ls

Build the application by running the below-mentioned command:

sam build

The following screenshot displays that the SAM application has been built successfully:

Deploy the SAM application using the following command:

sam deploy --guided

Configure the stack to deploy the application:

The application has been deployed successfully:

Visit the “CloudFormation” service from the AWS Console and click on the “Stacks” page:

Click on the name of the stack:

Head into the “Output” section and copy the link for the API:

Paste the copied link on the web browser to access the deployed SAM application on the cloud as displayed in the screenshot below:

That’s all about the use of AWS SAM.

Conclusion

To use AWS SAM, it is necessary to install SAM CLI on the local system to use it on the terminal. Initiate the SAM project and configure it according to the requirements and head inside the project directory. Build the SAM project inside the directory and then deploy it by configuring the stack. Visit the CloudFormation stack to access the SAM project using the link provided by the service. This guide has explained the use of the AWS Serverless Application Model.

About the author

Talha Mahmood

As a technical author, I am eager to learn about writing and technology. I have a degree in computer science which gives me a deep understanding of technical concepts and the ability to communicate them to a variety of audiences effectively.