0Pricing
Serverless AWS Lambda Development · 강의

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

AWS에서 구축하기 위한 오픈 소스 프레임워크인 AWS SAM을 사용하여 서버리스 애플리케이션을 정의하고 개발하고 배포하는 방법을 학습합니다.

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

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

Simplify Serverless with AWS SAM

AWS Serverless Application Model (SAM) is an open-source framework that simplifies building and deploying serverless applications on AWS.

It extends AWS CloudFormation, giving you a special, easier syntax for defining serverless resources like Lambda functions, API Gateways, and DynamoDB tables. SAM helps you manage your entire serverless app as a single unit.

SAM Template: The Blueprint

At the core of every SAM application is the template.yaml file. This YAML (or JSON) file acts as the blueprint, describing all the serverless resources that make up your application.

SAM templates are essentially AWS CloudFormation templates, but they include a crucial Transform property that unlocks SAM's simplified, serverless-specific syntax.

Anatomy of a SAM Template

Let's look at the key sections you'll find in a template.yaml file:

  • AWSTemplateFormatVersion: Standard CloudFormation version.
  • Transform: AWS::Serverless-2016-10-31: This is vital! It tells CloudFormation to use SAM's simplified syntax.
  • Description: A short explanation of your application.
  • Resources: This is where you define all your serverless components like Lambda functions, APIs, and databases.

Defining a Serverless Function

In SAM, you define a Lambda function using the AWS::Serverless::Function resource type. You specify essential properties like its runtime, entry point (handler), memory, and how it gets triggered.

  • Type: AWS::Serverless::Function: Identifies it as a Lambda.
  • Handler: The function within your code that AWS Lambda calls to begin execution (e.g., app.lambda_handler).
  • Runtime: The programming language environment (e.g., python3.9, nodejs16.x).
  • CodeUri: The local path to your function's source code.
  • Events: Specifies how your function is invoked (e.g., an API Gateway endpoint).

Our 'Hello World' Lambda Handler

Here's a simple Python Lambda function. It will be the code executed when our serverless function is invoked. It just returns a 'Hello from Lambda!' message.

import json

def lambda_handler(event, context):
    # Log the event for debugging purposes
    print("Received event: " + json.dumps(event))

    # Basic response for API Gateway
    response = {
        "statusCode": 200,
        "body": json.dumps("Hello from Lambda!")
    }
    return response

SAM Template for Our Function

Now, let's define our 'Hello World' Lambda function in a template.yaml. We'll set it up to be triggered by an API Gateway GET request at the /hello path.

This template assumes your Python code (app.py) is in a folder named hello_world/ next to this template.yaml file.

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A simple "Hello World" serverless application.

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 SAM CLI: Your Deployment Tool

The AWS SAM Command Line Interface (CLI) is your main tool for developing and deploying SAM applications. It provides commands to initialize projects, build dependencies, test locally, and deploy your application to AWS.

  • sam init: Start a new serverless project.
  • sam build: Package your application code and dependencies.
  • sam deploy: Deploy your application to AWS CloudFormation.

Building Your SAM Application

Before you can deploy your application, you need to 'build' it. The sam build command collects your code, bundles any dependencies (like Python packages), and prepares everything into a deployable package.

This command creates a .aws-sam directory containing the processed artifacts.

sam build

Deploying Your SAM Application

Once built, use sam deploy to push your application to AWS. This command creates or updates a CloudFormation stack based on your SAM template, provisioning all the necessary resources.

You'll need to specify a unique stack name and an S3 bucket for code artifacts. The --capabilities CAPABILITY_IAM argument acknowledges that your template creates IAM roles.

sam deploy --stack-name my-hello-app \
           --s3-bucket your-unique-s3-bucket-name \
           --capabilities CAPABILITY_IAM \
           --region us-east-1

Quick Check: SAM Template Components

Which of the following are essential components or sections found within a typical AWS SAM template (template.yaml)?

Recap: Your SAM Journey Begins!

You've just learned the fundamentals of AWS SAM!

  • SAM simplifies serverless application development and deployment using a CloudFormation-based template.
  • Key components include the template.yaml with its Transform property and Resources section.
  • The SAM CLI provides commands like sam init, sam build, and sam deploy to manage your applications.

With SAM, you can efficiently define, build, and deploy complex serverless architectures, making it a powerful tool for serverless development.

자주 묻는 질문

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

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

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

AWS에서 구축하기 위한 오픈 소스 프레임워크인 AWS SAM을 사용하여 서버리스 애플리케이션을 정의하고 개발하고 배포하는 방법을 학습합니다. 브라우저에서 직접 실행하는 실습 코드로 Serverless AWS Lambda Development을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Serverless AWS Lambda Development을(를) 시작하는 데 경험이 필요한가요?

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

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

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

이 Serverless AWS Lambda Development 강의에서 코드를 작성하고 실행할 수 있나요?

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

이 강의의 모든 강의

  1. AWS 서버리스 애플리케이션 모델(SAM)
  2. 서버리스 프레임워크 소개
  3. 서버리스 앱을 위한 CI/CD
  4. SAM CLI를 활용한 로컬 테스트
← Serverless AWS Lambda Development(으)로 돌아가기