บทนำสู่ AWS SAM
ค้นพบประโยชน์ของ AWS SAM สำหรับกำหนดทรัพยากรไร้เซิร์ฟเวอร์และทำให้การนำไปใช้งานง่ายขึ้นเมื่อเทียบกับ CloudFormation โดยตรง
บทนำสู่ AWS SAM เป็นบทเรียน Serverless Backend with AWS Lambda & API Gateway ฟรีบน CoddyKit นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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: 30Deconstructing 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:
- Write your Lambda function code (e.g., Python, Node.js).
- Define your application's resources in a SAM template (YAML/JSON).
- Use
sam buildto prepare your application for deployment. - Use
sam deployto 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” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Serverless Backend with AWS Lambda & API Gateway ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Serverless Backend with AWS Lambda & API Gateway มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “บทนำสู่ AWS SAM”
ค้นพบประโยชน์ของ AWS SAM สำหรับกำหนดทรัพยากรไร้เซิร์ฟเวอร์และทำให้การนำไปใช้งานง่ายขึ้นเมื่อเทียบกับ CloudFormation โดยตรง คุณปฏิบัติ Serverless Backend with AWS Lambda & API Gateway ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Serverless Backend with AWS Lambda & API Gateway หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Serverless Backend with AWS Lambda & API Gateway บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 1 จากทั้งหมด 4 บทเรียน
บทเรียน “บทนำสู่ AWS SAM” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Serverless Backend with AWS Lambda & API Gateway นี้ได้ไหม
ได้ บทเรียน Serverless Backend with AWS Lambda & API Gateway ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- บทนำสู่ AWS SAM
- การกำหนดทรัพยากรไร้เซิร์ฟเวอร์
- การนำแอปพลิเคชัน SAM ไปใช้งาน
- การทดสอบและแก้ไขข้อบกพร่องภายในเครื่องด้วย SAM CLI