Introduction to AWS Serverless Application Model – AWS无服务器应用模式介绍

最后修改: 2018年 7月 6日

中文/混合/英文(键盘快捷键:t)

1. Overview

1.概述

In our previous article, we already implemented a full stack serverless application on AWS, using API Gateway for REST endpoints, AWS Lambda for business logic, as well as a DynamoDB as a database.

我们之前的文章中,我们已经在AWS上实现了一个全栈无服务器应用程序,使用API Gateway来实现REST端点,使用AWS Lambda来实现业务逻辑,以及使用DynamoDB作为数据库。

However, the deployment consists of many manual steps, which might get unhandy with growing complexity and with the number of environments.

然而,部署包括许多手动步骤,随着复杂性的增加和环境数量的增加,这些步骤可能变得不方便。

In this tutorial now, we’ll discuss how to use the AWS Serverless Application Model (SAM), which enables a template-based description and automated deployment of serverless applications on AWS.

在本教程中,我们将讨论如何使用AWS无服务器应用程序模型(SAM),该模型能够在AWS上实现基于模板的描述和无服务器应用程序的自动部署

In detail, we’ll have a look at the following topics:

详细来说,我们将看一下以下主题。

  • Basics of the Serverless Application Model (SAM), as well as of the underlying CloudFormation
  • Definition of a Serverless Application, using the SAM template syntax
  • Automated deployment of the application, using the CloudFormation CLI

2. Basics

2.基础知识

As discussed previously, AWS enables us to implement entirely serverless applications, by using API Gateway, Lambda functions, and DynamoDB. Undoubtedly, that offers already many advantages for performance, cost, and scalability.

正如之前所讨论的那样,AWS 使我们能够通过使用 API Gateway、Lambda 函数和 DynamoDB 来实现完全无服务器的应用程序。毫无疑问,这在性能、成本和可扩展性方面已经提供了许多优势。

However, the downside is, that we need a lot of manual steps in the AWS Console at the moment, like creating each function, uploading code, creating the DynamoDB table, creating IAM roles, creating API and API structure, etc.

然而,缺点是,目前我们需要在AWS控制台中进行大量的手工操作,如创建每个函数、上传代码、创建DynamoDB表、创建IAM角色、创建API和API结构等。

For complex applications and with multiple environments like test, staging, and production, that effort multiplies quickly.

对于复杂的应用程序和多个环境,如测试、暂存和生产,这种努力很快就会成倍增加。

This is where CloudFormation for applications on AWS in general, and Serverless Application Model (SAM) specifically for serverless applications, comes into play.

这就是AWS上一般应用的CloudFormation,以及专门针对无服务器应用的无服务器应用模型(SAM)发挥作用的地方。

2.1. AWS CloudFormation

2.1.AWS CloudFormation

CloudFormation is an AWS service for the automatic provisioning of AWS infrastructure resources. A user defines all required resources in a blueprint (called template), and AWS takes care of the provisioning and configuration.

CloudFormation是一项AWS服务,用于自动配置AWS基础设施资源。用户在一个蓝图(称为模板)中定义所有需要的资源,而AWS则负责供应和配置。

The following terms and concepts are essential for understanding CloudFormation and SAM:

以下术语和概念对于理解CloudFormation和SAM至关重要。

A template is a description of an application, how it should be structured at runtime. We can define a set of required resources, as well as how these resources shall be configured. CloudFormation provides a common language for defining templates, supporting JSON and YAML as a format.

模板是对一个应用程序的描述,它在运行时应该是怎样的结构。我们可以定义一组所需的资源,以及这些资源应如何配置。CloudFormation提供了一种定义模板的通用语言,支持JSON和YAML格式。

Resources are the building blocks in CloudFormation. A resource can be anything, like a RestApi, a Stage of a RestApi, a Batch Job, a DynamoDB table, an EC2 instance, a network interface, an IAM role, and many more. The official documentation currently lists about 300 resource types for CloudFormation.

资源是 CloudFormation 中的构建块。资源可以是任何东西,例如 RestApi、RestApi 的阶段、批量作业、DynamoDB 表、EC2 实例、网络接口、IAM 角色等等。官方文档目前列出了CloudFormation的大约300种资源类型。

A stack is the instantiation of a template. CloudFormation takes care of provisioning and configuration the stack.

堆栈是模板的实例化。CloudFormation负责供应和配置堆栈。

2.2. Serverless Application Model (SAM)

2.2.无服务器应用程序模型(SAM)

As so often, the use of powerful tools can get very complex and unhandy, which is also the case for CloudFormation.

就像很多时候一样,强大的工具的使用会变得非常复杂和不方便,这也是CloudFormation的情况。

That is why Amazon introduced the Serverless Application Model (SAM). SAM started with the claim to provide a clean and straightforward syntax for defining serverless applications. Currently, it has only three resource types, which are Lambda functions, DynamoDB tables, and APIs.

这就是亚马逊推出无服务器应用程序模型(SAM)的原因。SAM一开始就声称要为定义无服务器应用程序提供一个简洁明了的语法。目前,它只有三种资源类型,即Lambda函数、DynamoDB表和API

SAM is based on the CloudFormation template syntax, so we can define our template using the simple SAM syntax, and CloudFormation will further process that template.

SAM是基于CloudFormation模板语法的,所以我们可以使用简单的SAM语法定义我们的模板,而CloudFormation将进一步处理该模板。

More details are available at the official GitHub repository as well as within the AWS documentation.

更多细节可在官方GitHub仓库以及AWS文档中找到。

3. Prerequisites

3.先决条件

For the following tutorial, we’ll need an AWS account. A free tier account should be sufficient.

对于下面的教程,我们需要一个AWS帐户。一个免费层级的帐户应该足够了。

Besides that, we need to have the AWS CLI installed.

除此之外,我们还需要有AWS CLI安装

Finally, we need an S3 Bucket in our region, which can be created via the AWS CLI with the following command:

最后,我们需要在我们的区域内有一个S3 Bucket,可以通过AWS CLI用以下命令创建。

$>aws s3 mb s3://baeldung-sam-bucket

While the tutorial uses baeldung-sam-bucket in the following, be aware that bucket names must be unique, so you have to choose your name.

虽然本教程在下文中使用了baeldung-sam-bucket,但要注意bucket的名字必须是唯一的,所以你必须选择你的名字。

As a demo application, we’ll use the code from Using AWS Lambda with API Gateway.

作为一个演示应用程序,我们将使用Using AWS Lambda with API Gateway中的代码。

4. Creating the Template

4.创建模板

In this section, we’ll create our SAM template.

在这一部分,我们将创建我们的SAM模板。

We’ll first have a look at the overall structure, before defining the individual resources.

我们首先看一下整体结构,然后再定义各个资源。

4.1. Structure of the Template

4.1.模板的结构

First, let’s have a look at the overall structure of our template:

首先,让我们看一下我们的模板的整体结构。

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Baeldung Serverless Application Model example
 
Resources:
  PersonTable:
    Type: AWS::Serverless::SimpleTable
    Properties:
      # Define table properties here
  StorePersonFunction:
    Type: AWS::Serverless::Function
    Properties:
      # Define function properties here
  GetPersonByHTTPParamFunction:
    Type: AWS::Serverless::Function
    Properties:
      # Define function properties here
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      # Define API properties here

As we can see, the template consists of a header and a body:

正如我们所看到的,该模板由一个标题和一个主体组成。

The header specifies the version of the CloudFormation template (AWSTemplateFormatVersion) as well as the version of our SAM template (Transform). We can also specify a Description.

头部指定了CloudFormation模板的版本(AWSTemplateFormatVersion)以及我们SAM模板的版本(Transform)。我们还可以指定一个Description

The body consists of a set of resources: each resource has a name, a resource Type, and a set of Properties.

主体由一组资源组成:每个资源都有一个名称,一个资源类型,和一组属性

The SAM specification currently supports three types: AWS::Serverless::ApiAWS::Serverless::Function as well as AWS::Serverless::SimpleTable.

SAM规范目前支持三种类型。AWS::Serverless::ApiAWS::Serverless::Function以及AWS::Serverless::SimpleTable

As we want to deploy our example application, we have to define one SimpleTable, two Functions, as well as one Api in our template-body.

由于我们要部署我们的示例应用程序,我们必须在我们的模板-正文中定义一个SimpleTable,两个Functions,以及一个Api

4.2. DynamoDB Table Definition

4.2.DynamoDB表的定义

Let’s define our DynamoDB table now:

现在我们来定义我们的DynamoDB表。

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Baeldung Serverless Application Model example
 
Resources:
  PersonTable:
    Type: AWS::Serverless::SimpleTable
    Properties:
      PrimaryKey:
          Name: id
          Type: Number
      TableName: Person

We only need to define two properties for our SimpleTable: the table name, as well as a primary key, which is called id and has the type Number in our case.

我们只需要为我们的SimpleTable定义两个属性:表名,以及一个主键,它被称为id,在我们的例子中,它的类型是Number

A full list of supported SimpleTable properties can be found in the official specification.

支持的SimpleTable属性的完整列表可以在官方规范中找到

Note: As we only want to access the table using the primary key, the AWS::Serverless::SimpleTable is sufficient for us. For more complex requirements, the native CloudFormation type AWS::DynamoDB::Table can be used instead.

注意:由于我们只想使用主键访问表,AWS::Serverless::SimpleTable对我们来说已经足够。对于更复杂的要求,可以使用本地CloudFormation类型AWS::DynamoDB::Table来代替。

4.3. Definition of the Lambda Functions

4.3.兰姆达函数的定义

Next, let’s define our two functions:

接下来,让我们定义我们的两个函数。

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Baeldung Serverless Application Model example
 
Resources:
  StorePersonFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleRequest
      Runtime: java8
      Timeout: 15
      MemorySize: 512
      CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
      Policies: DynamoDBCrudPolicy
      Environment:
        Variables:
          TABLE_NAME: !Ref PersonTable
      Events:
        StoreApi:
          Type: Api
            Properties:
              Path: /persons
              Method: PUT
              RestApiId:
                Ref: MyApi
  GetPersonByHTTPParamFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleGetByParam
      Runtime: java8
      Timeout: 15
      MemorySize: 512
      CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
      Policies: DynamoDBReadPolicy
      Environment:
        Variables:
          TABLE_NAME: !Ref PersonTable
      Events:
        GetByPathApi:
          Type: Api
            Properties:
              Path: /persons/{id}
              Method: GET
              RestApiId:
                Ref: MyApi
        GetByQueryApi:
          Type: Api
            Properties:
              Path: /persons
              Method: GET
              RestApiId:
                Ref: MyApi

As we can see, each function has the same properties:

我们可以看到,每个函数都有相同的属性。

Handler defines the logic of the function. As we are using Java, it is the class name including the package, in connection with the method name.

Handler定义了函数的逻辑。由于我们使用的是Java,它是包括包在内的类名,与方法名相关。

Runtime defines how the function was implemented, which is Java 8 in our case.

Runtime定义了函数的实现方式,在我们的例子中是Java 8。

Timeout defines how long the execution of the code may take at most before AWS terminates the execution.

Timeout定义了在AWS终止执行之前,代码的执行最多可能需要多长时间

MemorySize defines the size of the assigned memory in MB. It’s important to know, that AWS assigns CPU resources proportionally to MemorySize. So in the case of a CPU-intensive function, it might be required to increase MemorySize, even if the function doesn’t need that much memory.

MemorySize 定义了分配的内存大小,单位为MB。重要的是要知道,AWS按比例分配CPU资源给MemorySize。因此,在CPU密集型功能的情况下,可能需要增加MemorySize,即使该功能不需要那么多内存。

CodeUri defines the location of the function code. It currently references the target folder in our local workspace. When we upload our function later using CloudFormation, we’ll get an updated file with a reference to an S3 object.

CodeUri定义了函数代码的位置。它目前引用了我们本地工作区的目标文件夹。当我们稍后使用CloudFormation上传我们的函数时,我们将得到一个更新的文件,其中有一个对S3对象的引用。

Policies can hold a set of AWS-managed IAM policies or SAM-specific policy templates. We use the SAM-specific policies DynamoDBCrudPolicy for the StorePersonFunction and DynamoDBReadPolicy for GetPersonByPathParamFunction and GetPersonByQueryParamFunction.

政策可以持有一组AWS管理的IAM政策或SAM特定的政策模板。我们对StorePersonFunction使用SAM特定的策略DynamoDBCrudPolicy,对GetPersonByPathParamFunctionGetPersonByQueryParamFunction使用DynamoDBReadPolicy

Environment defines environment properties at runtime. We use an environment variable for holding the name of our DynamoDB table.

环境在运行时定义环境属性。我们使用一个环境变量来保存我们的DynamoDB表的名称。

Events can hold a set of AWS events, which shall be able to trigger the function. In our case, we define an Event of type Api. The unique combination of path, an HTTP Method, and a RestApiId links the function to a method of our API, which we’ll define in the next section.

Events 可以保存一组AWS事件,这些事件应能触发该函数。在我们的案例中,我们定义了一个Event类型Apipath、HTTP MethodRestApiId的独特组合将该函数链接到我们的API的一个方法,我们将在下一节定义这个方法。

A full list of supported Function properties can be found in the official specification.

支持的Function属性的完整列表可以在官方规范中找到

4.4. API Definition as Swagger File

4.4.作为Swagger文件的API定义

After defining DynamoDB table and functions, we can now define the API.

在定义了DynamoDB表和函数之后,我们现在可以定义API。

The first possibility is to define our API inline using the Swagger format:

第一种可能性是使用Swagger格式内联定义我们的API。

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Baeldung Serverless Application Model example
 
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: test
      EndpointConfiguration: REGIONAL
      DefinitionBody:
        swagger: "2.0"
        info:
          title: "TestAPI"
        paths:
          /persons:
            get:
              parameters:
              - name: "id"
                in: "query"
                required: true
                type: "string"
              x-amazon-apigateway-request-validator: "Validate query string parameters and\
                \ headers"
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetPersonByHTTPParamFunction.Arn}/invocations
                responses: {}
                httpMethod: "POST"
                type: "aws_proxy"
            put:
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${StorePersonFunction.Arn}/invocations
                responses: {}
                httpMethod: "POST"
                type: "aws_proxy"
          /persons/{id}:
            get:
              parameters:
              - name: "id"
                in: "path"
                required: true
                type: "string"
              responses: {}
              x-amazon-apigateway-integration:
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetPersonByHTTPParamFunction.Arn}/invocations
                responses: {}
                httpMethod: "POST"
                type: "aws_proxy"
        x-amazon-apigateway-request-validators:
          Validate query string parameters and headers:
            validateRequestParameters: true
            validateRequestBody: false

Our Api has three properties: StageNamedefines the stage of the API, EndpointConfiguration defines whether the API is regional or edge-optimized, and DefinitionBody contains the actual structure of the API.

我们的Api有三个属性。StageName定义了API的阶段,EndpointConfiguration定义了API是区域优化还是边缘优化,以及DefinitionBody包含了API的实际结构。

In the DefinitionBody, we define three parameters: the swagger version as “2.0”, the info:title: as “TestAPI”, as well as a set of paths.

DefinitionBody中,我们定义了三个参数:swagger版本为“2.0”info:title:“TestAPI”,以及一组paths

As we can see, the paths represent the API structure, which we had to define manually before. The paths in Swagger are equivalent to the resources in the AWS Console. Just like that, each path can have one or more HTTP verbs, which are equivalent to the methods in the AWS Console.

正如我们所看到的,paths代表API结构,我们必须手动定义before。Swagger中的paths等同于AWS控制台中的资源。就像这样,每个path可以有一个或多个HTTP动词,它们相当于AWS控制台中的方法。

Each method can have one or more parameters as well as a request validator.

每个方法可以有一个或多个参数,以及一个请求验证器。

The most exciting part is the attribute x-amazon-apigateway-integration, which is an AWS-specific extension to Swagger:

最令人兴奋的部分是属性x-amazon-apigateway-integration,这是一个针对AWS的Swagger扩展:

uri specifies which Lambda function shall be invoked.

uri指定应调用哪个Lambda函数。

responses specify rules how to transform the responses returned by the function. As we are using Lambda Proxy Integration, we don’t need any specific rule.

responses 指定如何转换函数返回的响应的规则。由于我们使用的是Lambda代理集成,我们不需要任何特定的规则。

type defines that we want to use Lambda Proxy Integration, and thereby we have to set httpMethod to “POST”, as this is what Lambda functions expect.

类型定义了我们要使用Lambda代理集成,因此我们必须将httpMethod设置为“POST”,因为这是Lambda函数所期望的。

A full list of supported Api properties can be found in the official specification.

支持的Api属性的完整列表可以在官方规范中找到

4.5. Implicit API Definition

4.5.隐式API的定义

A second option is to define the API implicitly within the Function resources:

第二个选择是在Function资源中隐含地定义API。

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: Baeldung Serverless Application Model Example with Implicit API Definition
 
Globals:
  Api:
    EndpointConfiguration: REGIONAL
    Name: "TestAPI"
 
Resources:
  StorePersonFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleRequest
      Runtime: java8
      Timeout: 15
      MemorySize: 512
      CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
      Policies:
        - DynamoDBCrudPolicy:
            TableName: !Ref PersonTable
      Environment:
        Variables:
          TABLE_NAME: !Ref PersonTable
      Events:
        StoreApi:
          Type: Api
          Properties:
            Path: /persons
            Method: PUT
  GetPersonByHTTPParamFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleGetByParam
      Runtime: java8
      Timeout: 15
      MemorySize: 512
      CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
      Policies:
        - DynamoDBReadPolicy:
            TableName: !Ref PersonTable
      Environment:
        Variables:
          TABLE_NAME: !Ref PersonTable
      Events:
        GetByPathApi:
          Type: Api
          Properties:
            Path: /persons/{id}
            Method: GET
        GetByQueryApi:
          Type: Api
          Properties:
            Path: /persons
            Method: GET

As we can see, our template is slightly different now: There is no AWS::Serverless::Api resource anymore.

我们可以看到,我们的模板现在略有不同。不再有AWS::Serverless::Api资源。

However, CloudFormation takes the Events attributes of type Api as an implicit definition and creates an API anyway. As soon as we test our application, we’ll see that it behaves the same as when defining the API explicitly using Swagger.

然而,CloudFormation 将 Events 类型的 Api 属性作为隐式定义,并创建了一个 API。当我们测试我们的应用程序时,我们将看到它的行为与使用 Swagger 明确定义 API 时的行为相同。

Besides, there is a Globals section, where we can define the name of our API, as well as that our endpoint shall be regional.

此外,还有一个Globals部分,我们可以在这里定义我们的API的名称,以及我们的端点应该是区域性的。

Only one limitation occurs: when defining the API implicitly, we are not able to set a stage name. This is why AWS will create a stage called Prod in any case.

只有一个限制:当隐式定义API时,我们不能设置阶段名称。这就是为什么AWS在任何情况下都会创建一个名为Prod的阶段。

5. Deployment and Test

5.部署和测试

After creating the template, we can now proceed with deployment and testing.

创建模板后,我们现在可以进行部署和测试。

For this, we’ll upload our function code to S3 before triggering the actual deployment.

为此,我们将在触发实际部署之前把我们的功能代码上传到S3。

In the end, we can test our application using any HTTP client.

最后,我们可以使用任何HTTP客户端测试我们的应用程序。

5.1. Code Upload to S3

5.1.代码上传至S3

In a first step, we have to upload the function code to S3.

第一步,我们必须将功能代码上传到S3。

We can do that by calling CloudFormation via the AWS CLI:

我们可以通过AWS CLI调用CloudFormation来做到这一点。

$> aws cloudformation package --template-file ./sam-templates/template.yml --s3-bucket baeldung-sam-bucket --output-template-file ./sam-templates/packaged-template.yml

With this command, we trigger CloudFormation to take the function code specified in CodeUri: and to upload it to S3. CloudFormation will create a packaged-template.yml file, which has the same content, except that CodeUri: now points to the S3 object.

通过这个命令,我们触发CloudFormation获取CodeUri:中指定的功能代码并将其上传到S3。CloudFormation将创建一个packaged-template.yml文件,其内容相同,只是CodeUri:现在指向了S3对象。

Let’s take a look at the CLI output:

让我们来看看CLI的输出。

Uploading to 4b445c195c24d05d8a9eee4cd07f34d0 92702076 / 92702076.0 (100.00%)
Successfully packaged artifacts and wrote output template to file packaged-template.yml.
Execute the following command to deploy the packaged template
aws cloudformation deploy --template-file c:\zz_workspace\tutorials\aws-lambda\sam-templates\packaged-template.yml --stack-name <YOUR STACK NAME>

5.2. Deployment

5.2.部署

Now, we can trigger the actual deployment:

现在,我们可以触发实际部署。

$> aws cloudformation deploy --template-file ./sam-templates/packaged-template.yml --stack-name baeldung-sam-stack  --capabilities CAPABILITY_IAM

As our stack also needs IAM roles (like the functions’ roles for accessing our DynamoDB table), we must explicitly acknowledge that by specifying the –capabilities parameter.

由于我们的堆栈也需要IAM角色(比如访问我们DynamoDB表的函数角色),我们必须通过指定-capabilities参数来明确确认。

And the CLI output should look like:

而CLI的输出应该是这样的。

Waiting for changeset to be created..
Waiting for stack create/update to complete
Successfully created/updated stack - baeldung-sam-stack

5.3. Deployment Review

5.3.部署审查

After the deployment, we can review the result:

部署完成后,我们可以审查结果。

$> aws cloudformation describe-stack-resources --stack-name baeldung-sam-stack

CloudFormation will list all resources, which are part of our stack.

CloudFormation将列出所有资源,这些资源是我们堆栈的一部分。

5.4. Test

5.4.测试

Finally, we can test our application using any HTTP client.

最后,我们可以使用任何HTTP客户端测试我们的应用程序。

Let’s see some sample cURL commands we can use for these tests.

让我们看看一些样本cURL命令,我们可以用来进行这些测试。

StorePersonFunction:

StorePersonFunction

$> curl -X PUT 'https://0skaqfgdw4.execute-api.eu-central-1.amazonaws.com/test/persons' \
   -H 'content-type: application/json' \
   -d '{"id": 1, "name": "John Doe"}'

GetPersonByPathParamFunction:

GetPersonByPathParamFunction

$> curl -X GET 'https://0skaqfgdw4.execute-api.eu-central-1.amazonaws.com/test/persons/1' \
   -H 'content-type: application/json'

GetPersonByQueryParamFunction:

GetPersonByQueryParamFunction

$> curl -X GET 'https://0skaqfgdw4.execute-api.eu-central-1.amazonaws.com/test/persons?id=1' \
   -H 'content-type: application/json'

5.5. Clean Up

5.5.清理工作

In the end, we can clean up by removing the stack and all included resources:

最后,我们可以通过删除堆栈和所有包含的资源来进行清理。

aws cloudformation delete-stack --stack-name baeldung-sam-stack

6. Conclusion

6.结论

In this article, we had a look at the AWS Serverless Application Model (SAM), which enables a template-based description and automated deployment of serverless applications on AWS.

在这篇文章中,我们看了一下AWS无服务器应用模型(SAM),它可以在AWS上实现基于模板的描述和自动部署无服务器应用。

In detail, we discussed the following topics:

详细来说,我们讨论了以下议题。

  • Basics of the Serverless Application Model (SAM), as well as the underlying CloudFormation
  • Definition of a Serverless Application, using the SAM template syntax
  • Automated deployment of the application, using the CloudFormation CLI

As usual, all the code for this article is available over on GitHub.

像往常一样,本文的所有代码都可以在GitHub上获得。