0Pricing
Serverless Backend with AWS Lambda & API Gateway · 강의

SAM 애플리케이션 배포

SAM CLI를 사용하여 서버리스 애플리케이션을 빌드하고 로컬에서 테스트한 후 AWS에 배포하며 다양한 환경을 관리합니다.

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

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

Introduction to SAM CLI

Welcome to deploying SAM applications! The AWS Serverless Application Model Command Line Interface (SAM CLI) is your best friend for building and managing serverless projects.

It extends AWS CloudFormation to simplify defining serverless resources. The SAM CLI provides commands to build, test, and deploy your serverless applications.

Building Your Application

Before deploying, your SAM application needs to be built. The sam build command takes your application code and dependencies, then prepares them for deployment.

  • It packages dependencies (e.g., Python libraries).
  • It transpiles code if needed (e.g., TypeScript to JavaScript).
  • It creates a deployable artifact in a .aws-sam/build directory.

Example Lambda Function

Let's look at a simple Python Lambda function and its template.yaml. The sam build command processes this to create deployable code.

After running sam build, the packaged code would be ready for local testing or deployment.

import json

def lambda_handler(event, context):
    """
    A simple Lambda handler.
    """
    return {
        "statusCode": 200,
        "headers": {
            "Content-Type": "application/json"
        },
        "body": json.dumps({
            "message": "Hello from your SAM Lambda!"
        })
    }

Local Testing with `sam local invoke`

The SAM CLI allows you to test your Lambda functions locally without deploying them to AWS, saving time and costs. Use sam local invoke to simulate a Lambda invocation.

You can pass event data directly to your function, just like how AWS services (like API Gateway or S3) would trigger it.

Running a Lambda Locally

To test the Lambda function from the previous scene, you'd use sam local invoke with the logical ID of your function and an event file.

For example, sam local invoke MyHelloWorldFunction --event event.json would test a function named 'MyHelloWorldFunction' using the data in event.json.

{
  "httpMethod": "GET",
  "path": "/hello",
  "queryStringParameters": null,
  "headers": {
    "Accept": "*/*"
  },
  "body": null
}

Local API Testing with `sam local start-api`

If your SAM application includes an API Gateway, you can simulate the entire API locally using sam local start-api. This command starts a local web server that mimics API Gateway.

You can then send HTTP requests to http://127.0.0.1:3000 and test your API endpoints end-to-end, locally.

Preparing for Deployment: `sam deploy`

Once your application is built and tested locally, you're ready to deploy it to AWS. The sam deploy command is used for this.

It packages your application artifacts, uploads them to an S3 bucket, and then uses AWS CloudFormation to deploy your serverless resources.

Your First Guided Deployment

For your first deployment, using the --guided flag is highly recommended. It will walk you through setting up necessary parameters interactively.

  • Stack Name: Unique identifier for your CloudFormation stack.
  • AWS Region: Where to deploy your resources.
  • S3 Bucket: For storing deployment artifacts.
  • Capabilities: Acknowledging IAM resource creation.

Example: sam deploy --guided

Managing Multiple Environments

In real-world scenarios, you'll often have development, staging, and production environments. SAM CLI helps manage this by allowing you to specify different stack names and parameters.

  • Use distinct Stack Names (e.g., my-app-dev, my-app-prod).
  • Use --parameter-overrides to pass different values for environment-specific configurations (e.g., database names, API keys).

Quick Check

Which SAM CLI command is used to test your API Gateway endpoints locally?

Recap & Next Steps

Congratulations! You've learned the essential steps for building, testing, and deploying serverless applications using the SAM CLI.

  • sam build: Packages and prepares your application.
  • sam local invoke: Tests individual Lambda functions locally.
  • sam local start-api: Simulates API Gateway for local API testing.
  • sam deploy: Deploys your application to AWS CloudFormation.

Mastering these commands is key to efficient serverless development!

자주 묻는 질문

“SAM 애플리케이션 배포” 강의는 무료인가요?

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

“SAM 애플리케이션 배포”에서 뭘 배우나요?

SAM CLI를 사용하여 서버리스 애플리케이션을 빌드하고 로컬에서 테스트한 후 AWS에 배포하며 다양한 환경을 관리합니다. 브라우저에서 직접 실행하는 실습 코드로 Serverless Backend with AWS Lambda & API Gateway을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Serverless Backend with AWS Lambda & API Gateway을(를) 시작하는 데 경험이 필요한가요?

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

“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(으)로 돌아가기