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.

  2. Setup AWS credentials.

    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

    • At Step 1: Specify user details page.

      • Enter user name, such as: sam-admin.
      • 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. IAMConsole
      • Uncheck the User must create a new password at next sign-in.
      • Click Next. IAMConsole
    • At Step 2: Set permissions page.

      • Select Attach policies directly.
      • Select AdministratorAccess policy to the user has full access to the services.
      • Click Next. IAMConsole
    • At Step 3: Review and create page.

      • Review configuration, and click Create user. IAMConsole
    • At Step 4: Review and create page, click Return to users list.

    • At sam-admin page.

      • Click Create access key. IAMConsole
    • At Step 1: Access key best practices & alternatives.

      • For Use case, select Command Line Interface(CLI). IAMConsole
      • Scroll down to the bottom, check the I understand the above recommendation ….
      • Click Next. IAMConsole
    • At Step 2: Set description tag.

      • Click Create access key. IAMConsole
    • At Step 3: Retrieve access keys.

      • Click Download .csv file.
      • Then, click Done. 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.
  3. 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.