0Pricing
AWS for Backend Developers (EC2, S3, RDS, Lambda) · 강의

서버리스 애플리케이션 모델(SAM)

AWS Serverless Application Model(SAM) 프레임워크를 사용해 서버리스 애플리케이션을 정의하고 개발하며 배포합니다.

서버리스 애플리케이션 모델(SAM)은(는) CoddyKit의 무료 AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 AWS for Backend Developers (EC2, S3, RDS, Lambda) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

What is AWS SAM?

Welcome to the AWS Serverless Application Model (SAM)! SAM is an open-source framework that helps you build, test, and deploy serverless applications on AWS faster and easier.

Think of it as a simplified way to define your serverless resources like Lambda functions and API Gateway endpoints.

SAM: CloudFormation's Helper

At its core, SAM is an extension of AWS CloudFormation. It provides a shorthand syntax for common serverless components.

When you deploy a SAM application, SAM transforms your simplified template into a full AWS CloudFormation template, ensuring you get all the benefits of CloudFormation's robust deployment capabilities.

SAM Template Structure

SAM applications are defined in a SAM template, typically a YAML file named template.yaml. Key sections include:

  • AWSTemplateFormatVersion: Standard CloudFormation version.
  • Transform: AWS::Serverless-2016-10-31: This line tells CloudFormation to process the template using SAM.
  • Resources: Where you define your serverless components (functions, APIs, databases).

Defining a Serverless Function

The primary resource for a Lambda function in SAM is AWS::Serverless::Function. This resource simplifies defining a Lambda function and its related configurations.

You specify properties like Handler (the function entry point), Runtime (e.g., python3.9), and CodeUri (the path to your function's code).

Integrating with API Gateway

To expose your Lambda function via an HTTP endpoint, you can directly define Events within your AWS::Serverless::Function resource.

Using the Api event type automatically provisions an Amazon API Gateway endpoint. You specify the Path and Method for your API route.

Your First SAM Template

Here's a basic template.yaml that defines a Python Lambda function triggered by an API Gateway GET request on the /hello path.

The CodeUri: hello_world/ indicates that the Lambda code is in a local directory named hello_world.

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: hello_world/
      MemorySize: 128
      Timeout: 30
      Events:
        HelloWorldApi:
          Type: Api
          Properties:
            Path: /hello
            Method: GET

The Lambda Function Code

This is the Python code (app.py) that resides inside the hello_world/ directory. This function will be executed when the API Gateway endpoint is invoked.

It simply returns a JSON response with a "Hello from SAM Lambda!" message.

import json

def lambda_handler(event, context):
    """
    Handles API Gateway requests and returns a simple greeting.
    """
    print("Received an event:", event) # For logging
    return {
        "statusCode": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "body": json.dumps({
            "message": "Hello from SAM Lambda!"
        }),
    }

# Example local invocation (for direct script testing)
if __name__ == "__main__":
    test_event = {
        "httpMethod": "GET",
        "path": "/hello",
        "requestContext": {"requestId": "test-id-123"},
        "headers": {"User-Agent": "test-client"}
    }
    response = lambda_handler(test_event, None)
    print("Local Response:", response)

Building Your SAM Application

Before you can deploy or even test your application locally, you need to build it. The sam build command processes your template, gathers dependencies, and prepares your code for deployment.

It creates a .aws-sam/build directory containing the processed artifacts.

sam build

Testing Locally with SAM CLI

The SAM CLI provides powerful tools for local testing, saving you time and money by avoiding repeated deployments to AWS.

  • sam local invoke: Invokes a single Lambda function locally with a given event.
  • sam local start-api: Starts a local HTTP server that emulates API Gateway, allowing you to interact with your serverless API from your browser or curl.

sam local start-api

Deploying Your Serverless App

Once your application is built and tested locally, you can deploy it to AWS using the sam deploy command.

The first time you deploy, it's recommended to use the --guided flag. This provides an interactive prompt to configure settings like stack name, AWS Region, and S3 bucket for deployment artifacts.

sam deploy --guided

SAM CLI Quick Check

Which SAM CLI command is used to test your serverless API Gateway locally, allowing you to interact with it from your browser or curl?

Recap & Next Steps

Congratulations! You've learned the fundamentals of the AWS Serverless Application Model (SAM).

  • SAM simplifies serverless development by extending CloudFormation.
  • You can define Lambda functions and API Gateway endpoints easily in a template.yaml.
  • The SAM CLI allows you to build, test locally, and deploy your serverless applications efficiently.

SAM is a powerful tool for developing modern, event-driven applications on AWS!

자주 묻는 질문

“서버리스 애플리케이션 모델(SAM)” 강의는 무료인가요?

네 — “서버리스 애플리케이션 모델(SAM)” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의 전체를 잠금 해제할 수 있습니다. AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의에는 총 4개의 강의가 포함되어 있습니다.

“서버리스 애플리케이션 모델(SAM)”에서 뭘 배우나요?

AWS Serverless Application Model(SAM) 프레임워크를 사용해 서버리스 애플리케이션을 정의하고 개발하며 배포합니다. 브라우저에서 직접 실행하는 실습 코드로 AWS for Backend Developers (EC2, S3, RDS, Lambda)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

AWS for Backend Developers (EC2, S3, RDS, Lambda)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 AWS for Backend Developers (EC2, S3, RDS, Lambda)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“서버리스 애플리케이션 모델(SAM)” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 AWS for Backend Developers (EC2, S3, RDS, Lambda) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. CodeCommit과 CodeBuild 기초
  2. EC2/Lambda용 CodeDeploy
  3. 서버리스 애플리케이션 모델(SAM)
  4. CloudFormation을 활용한 코드형 인프라
← AWS for Backend Developers (EC2, S3, RDS, Lambda)(으)로 돌아가기