0Pricing
Serverless AWS Lambda Development · บทเรียน

บทนำสู่เฟรมเวิร์กแบบไร้เซิร์ฟเวอร์

ทำความรู้จักเฟรมเวิร์กแบบไร้เซิร์ฟเวอร์ เครื่องมือที่ไม่ยึดติดกับผู้ให้บริการคลาวด์ ซึ่งช่วยลดความซับซ้อนในการนำไปใช้งานและจัดการแอปพลิเคชันแบบไร้เซิร์ฟเวอร์บนผู้ให้บริการหลายราย

บทนำสู่เฟรมเวิร์กแบบไร้เซิร์ฟเวอร์ เป็นบทเรียน Serverless AWS Lambda Development ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Serverless AWS Lambda Development และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Serverless AWS Lambda Development มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Intro to Serverless Framework

Welcome! In this lesson, we'll get acquainted with the Serverless Framework, a powerful command-line interface (CLI) tool.

It helps you build, deploy, and manage serverless applications across different cloud providers, including AWS Lambda.

Why Use Serverless Framework?

The Serverless Framework simplifies serverless development significantly. Here's why it's popular:

  • Cloud-Agnostic: Works with AWS, Azure, Google Cloud, and more.
  • Simplified Deployment: Automates the creation of cloud resources needed for your functions.
  • Consistency: Provides a standardized way to define and manage your serverless applications.
  • Focus on Code: Lets you concentrate on writing your application logic, not infrastructure setup.

Core Concepts: Services & Functions

Let's understand some key terms:

  • Service: Your project. It's a collection of related functions, events, and resources. Defined in a serverless.yml file.
  • Function: A single Lambda function (or similar compute unit in other clouds). It's your actual code.
  • Event: What triggers your function. Examples include HTTP requests, S3 uploads, or database changes.

Installing the Serverless CLI

First, you'll need Node.js and npm installed on your machine. Then, you can install the Serverless Framework CLI globally using npm:

npm install -g serverless

Creating Your First Service

Once installed, you can create a new serverless service using the serverless create command. You'll specify a template for your desired cloud provider and runtime.

For an AWS Node.js service, you might use:

serverless create --template aws-nodejs --path my-first-service

Understanding serverless.yml

The core of your Serverless Framework project is the serverless.yml file. This YAML file defines your service's configuration, including provider, functions, and events.

Here's a basic structure:

service: my-first-service
frameworkVersion: '3'

provider:
  name: aws
  runtime: nodejs18.x

functions:
  hello:
    handler: handler.hello

Defining a Lambda Function & Event

In serverless.yml, you define your Lambda functions and the events that trigger them. For example, to make our hello function accessible via an HTTP API endpoint:

service: my-first-service
frameworkVersion: '3'

provider:
  name: aws
  runtime: nodejs18.x

functions:
  hello:
    handler: handler.hello
    events:
      - httpApi:
          path: /hello
          method: get

Writing the Handler Code

Now, let's look at the actual Node.js code for our hello function, typically located in handler.js. This code will be executed when the HTTP API event triggers it.

Try running this example:

'use strict';

module.exports.hello = async (event) => {
  return {
    statusCode: 200,
    body: JSON.stringify(
      {
        message: 'Hello from Serverless Framework!',
        input: event,
      },
      null,
      2
    ),
  };
};

Deploying Your Service

Once your serverless.yml and handler code are ready, deploying your serverless application to AWS is as simple as running a single command:

The framework will package your code, create the necessary AWS resources (Lambda function, API Gateway endpoint, IAM roles), and deploy them.

serverless deploy

Quick Check: Serverless Concepts

What is the primary purpose of the serverless.yml file in a Serverless Framework project?

Recap: Serverless Framework Intro

Great job! In this lesson, you've been introduced to the Serverless Framework. You learned:

  • What the Serverless Framework is and why it's useful.
  • Key concepts like services, functions, and events.
  • How to install the CLI and create a new service.
  • The role of serverless.yml in defining your application.
  • How to write a simple Lambda handler and deploy your service.

Next up, we'll dive deeper into more advanced deployment strategies!

คำถามที่พบบ่อย

บทเรียน “บทนำสู่เฟรมเวิร์กแบบไร้เซิร์ฟเวอร์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “บทนำสู่เฟรมเวิร์กแบบไร้เซิร์ฟเวอร์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Serverless AWS Lambda Development ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Serverless AWS Lambda Development มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “บทนำสู่เฟรมเวิร์กแบบไร้เซิร์ฟเวอร์”

ทำความรู้จักเฟรมเวิร์กแบบไร้เซิร์ฟเวอร์ เครื่องมือที่ไม่ยึดติดกับผู้ให้บริการคลาวด์ ซึ่งช่วยลดความซับซ้อนในการนำไปใช้งานและจัดการแอปพลิเคชันแบบไร้เซิร์ฟเวอร์บนผู้ให้บริการหลายราย คุณปฏิบัติ Serverless AWS Lambda Development ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Serverless AWS Lambda Development หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Serverless AWS Lambda Development บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “บทนำสู่เฟรมเวิร์กแบบไร้เซิร์ฟเวอร์” ใช้เวลานานแค่ไหน

บทเรียน 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