0Pricing
Serverless Backend with AWS Lambda & API Gateway · Aula

Introdução ao AWS SAM

Descubra os benefícios do AWS SAM para definir recursos sem servidor e simplificar implantações em comparação com o CloudFormation bruto.

Introdução ao AWS SAM é uma aula grátis de Serverless Backend with AWS Lambda & API Gateway no CoddyKit. Esta é a aula 1 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Serverless Backend with AWS Lambda & API Gateway, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Serverless Backend with AWS Lambda & API Gateway inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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: 30

Deconstructing 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:

  1. Write your Lambda function code (e.g., Python, Node.js).
  2. Define your application's resources in a SAM template (YAML/JSON).
  3. Use sam build to prepare your application for deployment.
  4. Use sam deploy to 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!

Perguntas Frequentes

A aula “Introdução ao AWS SAM” é grátis?

Sim — o texto completo de “Introdução ao AWS SAM” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Serverless Backend with AWS Lambda & API Gateway, atualize para CoddyKit PRO. O curso de Serverless Backend with AWS Lambda & API Gateway inclui 4 aulas no total.

O que vou aprender em “Introdução ao AWS SAM”?

Descubra os benefícios do AWS SAM para definir recursos sem servidor e simplificar implantações em comparação com o CloudFormation bruto. Você pratica Serverless Backend with AWS Lambda & API Gateway com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Serverless Backend with AWS Lambda & API Gateway?

Nenhuma experiência prévia é necessária. Serverless Backend with AWS Lambda & API Gateway no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 1 de 4.

Quanto tempo leva a aula “Introdução ao AWS SAM”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Serverless Backend with AWS Lambda & API Gateway?

Sim. Cada aula de Serverless Backend with AWS Lambda & API Gateway inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Introdução ao AWS SAM
  2. Definição de recursos sem servidor
  3. Implantação de aplicações SAM
  4. Testes e depuração locais com o SAM CLI
← Voltar para Serverless Backend with AWS Lambda & API Gateway