Preparation

To start building SAM-based applications, we must first install the SAM CLI, install the AWS credentials, and initialize a simple SAM application.

  1. Install SAM CLI for OS:
    • MacOS
      brew tap aws/tap
      brew install aws-sam-cli
      sam --version
      
    • Linux
      pip install aws-sam-cli
      sam --version
      
    • Windows
      • Downloads AWS SAM CLI 64-bit
      • Install file and check version of SAM
        sam --version
        
  1. If you have already installed AWS credentials from previous posts, you can skip this step.
    • Open IAM console

    • Click User on the left menu.

    • Click Create user button IAMConsole

    • Enter user name, such as: AdminSAMUser

    • Check option Provide user access to the AWS Management Console

    • Select I want to create an IAM user

    • Select Custom password, then enter your password

    • Uncheck the User must create a new password at next sign-in

    • Click Next IAMConsole

  • Select Attach existing policies directly

  • Select AdministratorAccess policy to the user has full access to the services

  • Click Next IAMConsole

    • Click Next: Review

    • Review configuration, and click Create user IAMConsole

    • Click Return to users list. IAMConsole

    • Click Create access key IAMConsole

    • For Use case, select Command Line Interface(CLI)

    • Check to Confirmation

    • Click Next IAMConsole

    • Click Create access key IAMConsole

    • Click Download .csv file IAMConsole

    • Run the command using the terminal on your device

      aws configure
      
    • Enter the information corresponding to the columns in the credential file you downloaded

      • AWS Access key ID: Enter access key ID
      • AWS Secret access key: Enter secret access key
      • Default region name: Enter region closest to you
      • Default output format: Can be overlooked
  1. Then, create a sample SAM project
    • Run the below commands at the directory where you want to deploy the application
      #Step 1 - Download a sample application
      sam init
      
    • Then select the options:
      Which template source would you like to use?
      	1 - AWS Quick Start Templates
      	2 - Custom Template Location
      Choice: 1
      
      Choose an AWS Quick Start application template
      	1 - Hello World Example
      	2 - Multi-step workflow
      	3 - Serverless API
      	4 - Scheduled task
      	5 - Standalone function
      	6 - Data processing
      	7 - Infrastructure event management
      	8 - Machine Learning
      Template: 1
      
      Use the most popular runtime and package type? (Python and zip) [y/N]: y
      
      Would you like to enable X-Ray tracing on the function(s) in your application?  [y/N]: n
      
      Project name [sam-app]:  fcj-book-shop
      
      IAMConsole You have created a sample SAM project. Next , we will edit that project according to our application architecture.