0Pricing
Serverless Backend with AWS Lambda & API Gateway · レッスン

AWS SAM入門

CloudFormationを直接利用する場合と比較しながら、サーバーレスリソースの定義とデプロイを簡単にするAWS SAMのメリットを学びます。

「AWS SAM入門」はCoddyKit上の無料Serverless Backend with AWS Lambda & API Gatewayレッスンです。 これはレッスン1/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはServerless Backend with AWS Lambda & API Gateway学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Serverless Backend with AWS Lambda & API Gatewayコースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

Welcome to AWS SAM!

Hello! Today we'll explore AWS SAM, the Serverless Application Model. It's an open-source framework designed to help you build serverless applications on AWS more efficiently.

Think of SAM as a powerful extension to AWS CloudFormation, specifically tailored for serverless resources.

CloudFormation's Verbosity

AWS CloudFormation is a robust service for defining infrastructure as code. However, building serverless applications directly with CloudFormation can be quite verbose.

  • A simple AWS Lambda function often requires defining the Lambda resource itself, an IAM role with permissions, and possibly an API Gateway endpoint.
  • This can lead to many lines of configuration for even basic setups.

SAM to the Rescue!

AWS SAM aims to simplify this complexity. It provides a shorthand syntax to define common serverless resources.

Instead of defining multiple CloudFormation resources for a single serverless component, SAM lets you define it with just one simplified resource type.

Key Benefits of Using SAM

Using AWS SAM brings several advantages to your serverless development workflow:

  • Reduced Boilerplate: Define serverless functions, APIs, and databases with fewer lines of code.
  • Local Testing: Test your Lambda functions and API Gateway locally before deploying to AWS.
  • Simplified Deployments: The SAM CLI handles packaging, uploading, and deploying your application seamlessly.
  • CloudFormation Power: It's built on CloudFormation, so you still get its reliability and features.

SAM Template Basics

Your serverless application's infrastructure is defined in a SAM template, which is typically a YAML or JSON file. The most crucial part that tells CloudFormation to use SAM's simplified syntax is the Transform section.

This Transform line instructs CloudFormation to expand SAM's shorthand into full CloudFormation resources before deployment.

Your First SAM Template

Let's look at a very basic SAM template. This YAML defines a simple 'Hello World' Lambda function. Notice how concise it is compared to what raw CloudFormation would require for the same setup!

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A simple 'Hello World' SAM app.

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: app.lambda_handler
      Runtime: python3.9
      CodeUri: ./
      MemorySize: 128
      Timeout: 30

Deconstructing the Template

Let's break down that template:

  • Transform: AWS::Serverless-2016-10-31: This tells CloudFormation to process the SAM specific syntax.
  • Type: AWS::Serverless::Function: This is a SAM resource type. It automatically creates the Lambda function, an execution IAM role, and necessary permissions.
  • Handler, Runtime, CodeUri: These are standard AWS Lambda properties, specifying where your code is, its language, and the entry point.

SAM CLI - Your Serverless Sidekick

While SAM templates define your resources, the SAM Command Line Interface (CLI) is your primary tool for interacting with your serverless application.

The SAM CLI allows you to:

  • Build your application (e.g., package dependencies).
  • Test your Lambda functions locally.
  • Deploy your application to AWS.

The SAM Workflow (High-Level)

A typical SAM development workflow involves these high-level steps:

  1. Write your Lambda function code (e.g., Python, Node.js).
  2. Define your application's resources in a SAM template (YAML/JSON).
  3. Use sam build to prepare your application for deployment.
  4. Use sam deploy to push your application to AWS.

The SAM CLI handles all the underlying CloudFormation magic!

Quick Check on SAM

Based on what we've learned, what is the primary purpose of AWS SAM?

Recap & Next Steps

You've just been introduced to AWS SAM! We learned that SAM simplifies serverless development by providing a concise way to define resources, building on top of CloudFormation.

You also saw a basic SAM template and learned about the powerful SAM CLI.

Next, we'll dive deeper into defining various serverless resources within your SAM templates, including functions, APIs, and databases!

よくある質問

「AWS SAM入門」レッスンは無料ですか?

はい。「AWS SAM入門」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Serverless Backend with AWS Lambda & API Gatewayコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Serverless Backend with AWS Lambda & API Gatewayコースには全4レッスンが含まれています。

「AWS SAM入門」で何を学びますか?

CloudFormationを直接利用する場合と比較しながら、サーバーレスリソースの定義とデプロイを簡単にするAWS SAMのメリットを学びます。 ブラウザで直接実行するハンズオンコードでServerless Backend with AWS Lambda & API Gatewayを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Serverless Backend with AWS Lambda & API Gatewayを始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのServerless Backend with AWS Lambda & API Gatewayは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン1/4です。

「AWS SAM入門」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このServerless Backend with AWS Lambda & API Gatewayレッスンでコードを書いて実行できますか?

はい。すべてのServerless Backend with AWS Lambda & API Gatewayレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. AWS SAM入門
  2. サーバーレスリソースの定義
  3. SAMアプリケーションのデプロイ
  4. SAM CLIによるローカルテストとデバッグ
← Serverless Backend with AWS Lambda & API Gatewayに戻る