

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# AWS SAM 模板
<a name="sam-specification"></a>

运行**sam init**命令并完成其后续工作流程后， AWS SAM 创建您的应用程序项目目录，即您的 AWS SAM 项目。您可以通过向 AWS SAM 项目中添加代码来定义您的无服务器应用程序。虽然您的 AWS SAM 项目由一组文件和文件夹组成，但您主要使用的文件是您的 AWS SAM 模板（已命名`template.yaml`）。在此模板中，您可以编写代码来表达资源、事件源映射以及定义无服务器应用程序的其他属性。

**注意**  
模板的一个关键元素是 AWS SAM AWS SAM 模板规范。本规范提供了简短的语法，与之相比 CloudFormation，它允许您使用更少的代码行来定义无服务器应用程序的资源、事件源映射 APIs、权限和其他属性。

本节详细介绍了如何使用 AWS SAM 模板中的部分来定义资源类型、资源属性、数据类型、资源属性、内部函数和 API Gateway 扩展。

AWS SAM 模板是 CloudFormation 模板的扩展，其独特的语法类型使用速记语法，代码行数少于。 CloudFormation在构建无服务器应用程序时，这可以加快开发速度。有关更多信息，请参阅[AWS SAM 资源和财产](sam-specification-resources-and-properties.md)。有关 CloudFormation 模板的完整参考，请参阅《*AWS CloudFormation 用户指南》*中的 “[CloudFormation 模板参考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-reference.html)”。

在开发时，您通常会发现将应用程序代码分解为单独的文件是有益的，这样可以更好地组织和管理您的应用程序。这方面的一个基本例子是为 AWS Lambda 函数代码使用单独的文件，而不是在 AWS SAM 模板中包含此代码。为此，请将 Lambda 函数代码整理到项目的子目录中，然后在 () 模板中引用其本地路径。 AWS Serverless Application Model AWS SAM

**Topics**
+ [AWS SAM 模板解剖学](sam-specification-template-anatomy.md)
+ [AWS SAM 资源和财产](sam-specification-resources-and-properties.md)
+ [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)
+ [支持的资源属性 AWS SAM](sam-specification-resource-attributes.md)
+ [适用于 API Gateway 的扩展 AWS SAM](sam-specification-api-gateway-extensions.md)
+ [的内在函数 AWS SAM](sam-specification-intrinsic-functions.md)

# AWS SAM 模板解剖学
<a name="sam-specification-template-anatomy"></a>

 AWS SAM 模板文件严格遵循 CloudFormation 模板文件的格式，该格式在《*AWS CloudFormation 用户指南》*的[模板剖析](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-anatomy.html)中进行了描述。 AWS SAM 模板文件和 CloudFormation 模板文件之间的主要区别如下：
+ **转换声明。** AWS SAM 模板文件需要声明 `Transform: AWS::Serverless-2016-10-31`。此声明将 CloudFormation 模板文件标识为 AWS SAM 模板文件。有关转换的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的[转换](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html)。
+ **全局变量部分。**该`Globals`部分是独一无二的 AWS SAM。它定义了所有无服务器函数通用的属性，以及。 APIs所有`AWS::Serverless::Function`、、`AWS::Serverless::Api``AWS::Serverless::CapacityProvider`、`AWS::Serverless::HttpApi``AWS::Serverless::SimpleTable`、和`AWS::Serverless::StateMachine`资源都继承本`Globals`节中定义的属性。有关该部分的更多信息，请参阅 [模板的 “全局” 部分 AWS SAM](sam-specification-template-anatomy-globals.md)。
+ **资源部分。**在 AWS SAM 模板中，该`Resources`部分可以包含 CloudFormation 资源和 AWS SAM 资源的组合。有关 CloudFormation 资源的更多信息，请参阅*AWS CloudFormation 用户指南*中的[AWS 资源和属性类型参考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html)。有关 AWS SAM 资源的更多信息，请参阅[AWS SAM 资源和财产](sam-specification-resources-and-properties.md)。

 AWS SAM 模板文件的所有其他部分对应于同名的 CloudFormation 模板文件部分。

## YAML
<a name="template-anatomy-outline.yaml"></a>

以下示例显示 YAML 格式的模板片段。

```
Transform: AWS::Serverless-2016-10-31

Globals:
  set of globals

Description:
  String

Metadata:
  template metadata

Parameters:
  set of parameters

Mappings:
  set of mappings

Conditions:
  set of conditions

Resources:
  set of resources

Outputs:
  set of outputs
```

## 模板部分
<a name="template-anatomy-sections"></a>

AWS SAM 模板可以包括几个主要部分。仅 `Transform` 和 `Resources` 部分为必需。

您可以按任意顺序包含模板部分。但是，如果使用语言扩展，则应在无服务器转换*之前*（即 `AWS::Serverless-2016-10-31` 之前）添加 `AWS::LanguageExtensions`，如下例所示：

```
Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31
```

在您构建模板时，使用以下列表中显示的逻辑顺序可能会很有用。这是因为某一部分中的值可能引用前一部分中的值。

**[转换（必需）](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html)**  
对于 AWS SAM 模板，必须包含此部分，其值为`AWS::Serverless-2016-10-31`。  
其它变换是可选的。有关转换的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的[转换](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html)。

**[全局变量（可选）](sam-specification-template-anatomy-globals.md)**  
所有无服务器函数和简单表都通用的属性。 APIs所有`AWS::Serverless::Function`、、`AWS::Serverless::Api``AWS::Serverless::CapacityProvider`、`AWS::Serverless::HttpApi``AWS::Serverless::SimpleTable`、和`AWS::Serverless::StateMachine`资源都继承本`Globals`节中定义的属性。  
本节是独一无二的 AWS SAM。 CloudFormation 模板中没有相应的部分。

**[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-description-structure.html)（可选）**  
一个描述模板的文本字符串。  
本节与 CloudFormation 模板`Description`部分直接对应。

**[元数据（可选）](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/metadata-section-structure.html)**  
提供有关模板的其他信息的对象。  
本节与 CloudFormation 模板`Metadata`部分直接对应。

**[Parameters（可选）](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html)**  
要在运行时 (创建或更新堆栈时) 传递到模板的值。您可引用模板的 `Resources` 和 `Outputs` 部分中的参数。在 `Parameters` 部分中声明的对象会导致 **sam deploy --guided** 命令向用户显示附加提示。  
使用 `sam deploy` 命令的 `--parameter-overrides` 参数传入的值以及配置文件中的条目优先于 AWS SAM 模板文件中的条目。有关 `sam deploy` 命令的更多信息，请参阅 AWS SAM CLI 命令参考中的 [sam deploy](sam-cli-command-reference-sam-deploy.md)。有关配置文件的更多信息，请参阅[AWS SAMCLI 配置文件](serverless-sam-cli-config.md)。

**[Mappings（可选）](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/mappings-section-structure.html)**  
可用来指定条件参数值的密钥和关键值的映射，与查找表类似。可以通过使用 `Resources` 和 `Outputs` 部分中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-findinmap.html) 内置函数将键与相应的值匹配。  
本节与 CloudFormation 模板`Mappings`部分直接对应。

**[条件（可选）](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html)**  
用于控制是否创建某些资源或者是否在堆栈创建或更新过程中为某些资源属性分配值的条件。例如，您可以根据堆栈是用于生产环境还是用于测试环境来按照条件创建资源。  
本节与 CloudFormation 模板`Conditions`部分直接对应。

**[Resources（必需）](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html)**  
堆栈资源及其属性，例如亚马逊弹性计算云 (Amazon EC2) 实例或亚马逊简单存储服务 (Amazon S3) Service 存储桶。您可引用模板的 `Resources` 和 `Outputs` 部分中的资源。  
该部分与 CloudFormation 模板的 `Resources` 部分类似。在 AWS SAM 模板中，除 AWS SAM 资源外，此部分还可以包含 CloudFormation 资源。

**[Outputs（可选）](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/outputs-section-structure.html)**  
在您查看堆栈的属性时返回的值。例如，您可以为 S3 存储桶名称声明输出，然后调用 `aws cloudformation describe-stacks` AWS Command Line Interface (AWS CLI) 命令查看该名称。  
该部分与 CloudFormation 模板的 `Outputs` 部分直接对应。

## 后续步骤
<a name="template-anatomy-next-steps"></a>

要下载和部署包含 AWS SAM 模板文件的示例无服务器应用程序，请参阅[入门 AWS SAM](serverless-getting-started.md)并按照中的[教程：使用以下命令部署 Hello World 应用程序 AWS SAM](serverless-getting-started-hello-world.md)说明进行操作。

# 模板的 “全局” 部分 AWS SAM
<a name="sam-specification-template-anatomy-globals"></a>

有时，您在 AWS SAM 模板中声明的资源具有通用配置。例如，应用程序可能包含多个具有相同的 `Runtime`、`Memory`、`VPCConfig`、`Environment` 和 `Cors` 配置的 `AWS::Serverless::Function` 资源。与其在每个资源中复制这些信息，不如在 `Globals` 部分中声明一次，然后让您的资源继承它们。

该`Globals`部分支持以下 AWS SAM 资源类型：
+ `AWS::Serverless::Api`
+ `AWS::Serverless::CapacityProvider`
+ `AWS::Serverless::Function`
+ `AWS::Serverless::HttpApi`
+ `AWS::Serverless::SimpleTable`
+ `AWS::Serverless::StateMachine`

示例：

```
Globals:
  Function:
    Runtime: nodejs12.x
    Timeout: 180
    Handler: index.handler
    Environment:
      Variables:
        TABLE_NAME: data-table

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          MESSAGE: "Hello From SAM"

  ThumbnailFunction:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        Thumbnail:
          Type: Api
          Properties:
            Path: /thumbnail
            Method: POST
```

在此示例中，`HelloWorldFunction` 和 `ThumbnailFunction` 都使用如下配置：`Runtime` 为“nodejs12.x”，`Timeout` 为“180”秒，`Handler` 为“index.handler”。除了继承的 TABLE\$1NAME 之外，`HelloWorldFunction` 还会添加 MESSAGE 环境变量。`ThumbnailFunction` 会继承所有 `Globals` 属性并添加 API 事件源。

## 支持的资源和属性
<a name="sam-specification-template-anatomy-globals-supported-resources-and-properties"></a>

AWS SAM 支持以下资源和属性。

```
Globals:
  Api:
    AccessLogSetting:
    Auth:
    BinaryMediaTypes:
    CacheClusterEnabled:
    CacheClusterSize:
    CanarySetting:
    Cors:
    DefinitionUri:
    Domain:
    EndpointConfiguration:
    GatewayResponses:
    MethodSettings:
    MinimumCompressionSize:
    Name:
    OpenApiVersion:
    PropagateTags:
    TracingEnabled:
    Variables:
  
  CapacityProvider:
    InstanceRequirements:
    KmsKeyArn:
    OperatorRole:
    PropagateTags:
    ScalingConfig:
    Tags:
    VpcConfig:
  
  Function:
    Architectures:
    AssumeRolePolicyDocument:
    AutoPublishAlias:
    AutoPublishAliasAllProperties:
    CapacityProviderConfig:
    CodeSigningConfigArn:
    CodeUri:
    DeadLetterQueue:
    DeploymentPreference:
    Description:
    DurableConfig:
    Environment:
    EphemeralStorage:
    EventInvokeConfig:
    FileSystemConfigs:
    FunctionScalingConfig:
    FunctionUrlConfig:
    Handler:
    KmsKeyArn:
    Layers:
    LoggingConfig:
    MemorySize:
    PermissionsBoundary:
    PropagateTags:
    ProvisionedConcurrencyConfig:
    PublishToLatestPublished:
    RecursiveLoop:
    ReservedConcurrentExecutions:
    RolePath:
    Runtime:
    RuntimeManagementConfig:
    SnapStart:
    SourceKMSKeyArn:
    Tags:
    TenancyConfig:
    Timeout:
    Tracing:
    VersionDeletionPolicy:
    VpcConfig:

  HttpApi:
    AccessLogSettings:
    Auth:
    PropagateTags:
    StageVariables:
    Tags:

  SimpleTable:
    SSESpecification:
    
  StateMachine:
    PropagateTags:
```

**注意**  
系统不支持任何未包含在前面列表中的资源和属性。不支持它们的一些原因包括：1) 它们会带来潜在的安全问题，或者 2) 它们使模板难以理解。

## 隐含的 APIs
<a name="sam-specification-template-anatomy-globals-implicit-apis"></a>

AWS SAM APIs当您在本`Events`节中声明 API 时会创建*隐式*的。您可以使用`Globals`覆盖隐式的所有属性 APIs。

## 可覆盖属性
<a name="sam-specification-template-anatomy-globals-overrideable"></a>

资源可以覆盖您在 `Globals` 部分声明的属性。例如，您可以向环境变量映射中添加新变量，也可以覆盖全局声明的变量。但是资源无法删除 `Globals` 部分中指定的属性。

更笼统地说，`Globals` 部分会声明所有资源共享的属性。有些资源可以为全局声明的属性提供新的值，但它们无法将其删除。如果一些资源使用某属性而其他资源不使用，则不得在 `Globals` 部分中声明它们。

以下部分描述了覆盖如何应用于不同的数据类型。

### 替换原始数据类型
<a name="sam-specification-template-anatomy-globals-overrideable-primitives"></a>

原始数据类型包括字符串、数字、布尔值等。

`Resources` 部分中指定的值替换 `Globals` 部分中的值。

示例：

```
Globals:
  Function:
    Runtime: nodejs12.x

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: python3.9
```

`MyFunction` 的 `Runtime` 设置为 `python3.9`。

### 合并映射
<a name="sam-specification-template-anatomy-globals-overrideable-maps"></a>

映射也称为字典或键值对的集合。

`Resources` 部分中的映射条目与全局映射条目合并。如果存在重复项，则 `Resource` 部分条目将覆盖 `Globals` 部分条目。

示例：

```
Globals:
  Function:
    Environment:
      Variables:
        STAGE: Production
        TABLE_NAME: global-table

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          TABLE_NAME: resource-table
          NEW_VAR: hello
```

`MyFunction` 的环境变量设置如下：

```
{
  "STAGE": "Production",
  "TABLE_NAME": "resource-table",
  "NEW_VAR": "hello"
}
```

### 添加列表
<a name="sam-specification-template-anatomy-globals-overrideable-lists"></a>

列表也称为数组。

`Globals` 部分中的列表条目添加到 `Resources` 部分的列表之前。

示例：

```
Globals:
  Function:
    VpcConfig:
      SecurityGroupIds:
        - sg-123
        - sg-456

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      VpcConfig:
        SecurityGroupIds:
          - sg-first
```

针对 `MyFunction` 的 `VpcConfig` 的 `SecurityGroupIds` 设置如下：

```
[ "sg-123", "sg-456", "sg-first" ]
```

# AWS SAM 资源和财产
<a name="sam-specification-resources-and-properties"></a>

本节介绍特定于的资源和属性类型。 AWS SAM您可以使用 AWS SAM 速记语法定义这些资源和属性。 AWS SAM 还支持 CloudFormation 资源和属性类型。有关所有 AWS 资源和属性类型 CloudFormation 及 AWS SAM 支持的参考信息，请参阅*《AWS CloudFormation 用户指南》*中的[AWS 资源和属性类型参考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html)。

**Topics**
+ [AWS::Serverless::Api](sam-resource-api.md)
+ [AWS::Serverless::Application](sam-resource-application.md)
+ [AWS::Serverless::CapacityProvider](sam-resource-capacityprovider.md)
+ [AWS::Serverless::Connector](sam-resource-connector.md)
+ [AWS::Serverless::Function](sam-resource-function.md)
+ [AWS::Serverless::GraphQLApi](sam-resource-graphqlapi.md)
+ [AWS::Serverless::HttpApi](sam-resource-httpapi.md)
+ [AWS::Serverless::LayerVersion](sam-resource-layerversion.md)
+ [AWS::Serverless::SimpleTable](sam-resource-simpletable.md)
+ [AWS::Serverless::StateMachine](sam-resource-statemachine.md)

# AWS::Serverless::Api
<a name="sam-resource-api"></a>

创建一组可通过 HTTPS 端点调用的 Amazon API Gateway 资源和方法。

无需将[AWS::Serverless::Api](#sam-resource-api)资源明确添加到 AWS 无服务器应用程序定义模板中。这种类型的资源是通过 [AWS::Serverless::Function](sam-resource-function.md) 资源上定义的 Api 事件的并集隐式创建的，这些资源定义于未引用 [AWS::Serverless::Api](#sam-resource-api) 资源的模板。

应使用[AWS::Serverless::Api](#sam-resource-api)资源来定义和记录 API OpenApi，这样可以更好地配置底层 Amazon API Gateway 资源。

我们建议您使用 CloudFormation 挂钩或 IAM 策略来验证 API Gateway 资源是否附加了授权者来控制对它们的访问。

有关使用 CloudFormation 挂钩的更多信息，请参阅 *CloudFormation CLI 用户指南*和[apigw-enforce-authorizer](https://github.com/aws-cloudformation/aws-cloudformation-samples/tree/main/hooks/python-hooks/apigw-enforce-authorizer/) GitHub 存储库中的[注册挂钩](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/registering-hook-python.html)。

有关使用 IAM 策略的更多信息，请参阅*《API Gateway 开发人员指南》*中的[要求 API 路由具有授权](https://docs.aws.amazon.com/apigateway/latest/developerguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-require-authorization)。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-api-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-resource-api-syntax.yaml"></a>

```
Type: AWS::Serverless::Api
Properties:
  [AccessLogSetting](#sam-api-accesslogsetting): [AccessLogSetting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-accesslogsetting)
  AlwaysDeploy: Boolean
  [ApiKeySourceType](#sam-api-apikeysourcetype): String
  [Auth](#sam-api-auth): ApiAuth
  [BinaryMediaTypes](#sam-api-binarymediatypes): List
  [CacheClusterEnabled](#sam-api-cacheclusterenabled): Boolean
  [CacheClusterSize](#sam-api-cacheclustersize): String
  [CanarySetting](#sam-api-canarysetting): [CanarySetting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-canarysetting)
  [Cors](#sam-api-cors): String | CorsConfiguration
  [DefinitionBody](#sam-api-definitionbody): JSON
  [DefinitionUri](#sam-api-definitionuri): String | ApiDefinition
  [Description](#sam-api-description): String
  [DisableExecuteApiEndpoint](#sam-api-disableexecuteapiendpoint): Boolean
  [Domain](#sam-api-domain): DomainConfiguration
  [EndpointConfiguration](#sam-api-endpointconfiguration): EndpointConfiguration
  [FailOnWarnings](#sam-api-failonwarnings): Boolean
  [GatewayResponses](#sam-api-gatewayresponses): Map
  MergeDefinitions: Boolean
  [MethodSettings](#sam-api-methodsettings): MethodSettings
  [MinimumCompressionSize](#sam-api-minimumcompressionsize): Integer
  [Mode](#sam-api-mode): String
  [Models](#sam-api-models): Map
  [Name](#sam-api-name): String
  [OpenApiVersion](#sam-api-openapiversion): String
  PropagateTags: Boolean
  [Policy](#sam-api-policy): JSON
  [StageName](#sam-api-stagename): String
  [Tags](#sam-api-tags): Map
  [TracingEnabled](#sam-api-tracingenabled): Boolean
  [Variables](#sam-api-variables): Map
```

## Properties
<a name="sam-resource-api-properties"></a>

 `AccessLogSetting`   <a name="sam-api-accesslogsetting"></a>
配置某个阶段的访问日志设置。  
*类型*：[AccessLogSetting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-accesslogsetting)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::Stage`资源的`[AccessLogSetting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-accesslogsetting)`属性。

 `AlwaysDeploy`   <a name="sam-api-alwaysdeploy"></a>
即使未检测到 API 的更改，也要始终部署 API。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ApiKeySourceType`   <a name="sam-api-apikeysourcetype"></a>
用于根据使用计划对请求进行计量的 API 键的源。有效值为 `HEADER` 和 `AUTHORIZER`。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi`资源的`[ApiKeySourceType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-apikeysourcetype)`属性。

 `Auth`   <a name="sam-api-auth"></a>
配置授权，以控制对 API Gateway API 的访问。  
有关使用配置访问权限的更多信息， AWS SAM 请参阅[使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。有关如何覆盖全局授权方的示例，请参阅 [覆盖 Amazon API Gateway REST API 的全局授权方](sam-property-function-apifunctionauth.md#sam-property-function-apifunctionauth--examples--override)。  
*类型*：[ApiAuth](sam-property-api-apiauth.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `BinaryMediaTypes`   <a name="sam-api-binarymediatypes"></a>
您的 API 可能返回的 MIME 类型列表。使用它来启用对的二进制支持APIs。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::RestApi`资源的`[BinaryMediaTypes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-binarymediatypes)`属性。的列表 BinaryMediaTypes 已添加到 CloudFormation 资源和 OpenAPI 文档中。

 `CacheClusterEnabled`   <a name="sam-api-cacheclusterenabled"></a>
指示是否为阶段启用缓存。要缓存响应，还必须在 `MethodSettings` 下将 `CachingEnabled` 设置为 `true`。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::Stage`资源的`[CacheClusterEnabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-cacheclusterenabled)`属性。

 `CacheClusterSize`   <a name="sam-api-cacheclustersize"></a>
阶段的缓存群集大小。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::Stage`资源的`[CacheClusterSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-cacheclustersize)`属性。

 `CanarySetting`   <a name="sam-api-canarysetting"></a>
将金丝雀设置配置为常规部署的某个阶段。  
*类型*：[CanarySetting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-canarysetting)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::Stage`资源的`[CanarySetting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-canarysetting)`属性。

 `Cors`   <a name="sam-api-cors"></a>
管理所有 API Gateway 的跨源资源共享 (CORS)。 APIs使用字符串指定允许使用的域，或使用其他 Cors 配置指定词典。  
CORS AWS SAM 需要修改你的 OpenAPI 定义。在 `DefinitionBody` 中创建内联 OpenAPI 定义以开启 CORS。
有关 CORS 的更多信息，请参阅*《API Gateway 开发人员指南》*中的[为 API Gateway REST API 资源启用 CORS](https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html)。  
*类型*：字符串 \$1 [CorsConfiguration](sam-property-api-corsconfiguration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `DefinitionBody`   <a name="sam-api-definitionbody"></a>
描述您的 API 的 OpenAPI 规范。如果 `DefinitionUri` 和 `DefinitionBody` 均未指定，SAM 将根据模板配置为您生成 `DefinitionBody`。  
要引用定义 API 的本地 OpenAPI 文件，请使用 `AWS::Include` 转换。要了解更多信息，请参阅[如何 AWS SAM 上传本地文件](deploy-upload-local-files.md)。  
*类型*：JSON  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::RestApi`资源的`[Body](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-body)`属性。如果提供了某些属性，则可以在将内容传递给DefinitionBody 之前在中插入或修改内容 CloudFormation。属性包括 `Auth`、`BinaryMediaTypes`、`Cors`、`GatewayResponses`、`Models`、和 `AWS::Serverless::Function` 相应 Api 类型的 `EventSource`。

 `DefinitionUri`   <a name="sam-api-definitionuri"></a>
Amazon S3 Uri、本地文件路径或定义 API 的 OpenAPI 文档的位置对象。此属性引用的 Amazon S3 对象必须是有效的 OpenAPI 文件。如果 `DefinitionUri` 和 `DefinitionBody` 均未指定，SAM 将根据模板配置为您生成 `DefinitionBody`。  
如果提供了本地文件路径，则模板必须经过包含 `sam deploy` 或 `sam package` 命令的工作流程，才能使定义正确转换。  
引用的外部 OpenApi 文件不支持内部函数。`DefinitionUri`改用带[有 Include 转换](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/create-reusable-transform-function-snippets-and-add-to-your-template-with-aws-include-transform.html)的`DefinitionBody`属性将 OpenApi 定义导入到模板中。  
*类型*：字符串 \$1 [ApiDefinition](sam-property-api-apidefinition.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::RestApi`资源的`[BodyS3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-bodys3location)`属性。嵌套的 Amazon S3 属性的命名有所不同。

 `Description`   <a name="sam-api-description"></a>
Api 资源的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-description)`属性。

 `DisableExecuteApiEndpoint`   <a name="sam-api-disableexecuteapiendpoint"></a>
指定客户端是否可以使用默认 `execute-api` 端点调用您的 API。默认情况下，客户端可以使用默认 `https://{api_id}.execute-api.{region}.amazonaws.com` 调用您的 API。如果要求客户端使用自定义域名来调用 API，请指定 `True`。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::RestApi`资源的`[ DisableExecuteApiEndpoint](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-disableexecuteapiendpoint)`属性。它直接传递给 `[ x-amazon-apigateway-endpoint-configuration](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-endpoint-configuration.html)` 扩展的 `disableExecuteApiEndpoint` 属性，然后添加到 `AWS::ApiGateway::RestApi` 资源的 ` [ Body](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-body)` 属性中。

 `Domain`   <a name="sam-api-domain"></a>
为此 API Gateway API 配置自定义域。  
*类型*：[DomainConfiguration](sam-property-api-domainconfiguration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `EndpointConfiguration`   <a name="sam-api-endpointconfiguration"></a>
REST API 的端点类型。  
*类型*：[EndpointConfiguration](sam-property-api-endpointconfiguration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::RestApi`资源的`[EndpointConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-endpointconfiguration)`属性。嵌套配置属性的命名有所不同。

 `FailOnWarnings`   <a name="sam-api-failonwarnings"></a>
指定在遇到警告时是回滚 (`true`) 还是不回滚 (`false`) API 创建。默认值为 `false`。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi`资源的`[FailOnWarnings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-failonwarnings)`属性。

 `GatewayResponses`   <a name="sam-api-gatewayresponses"></a>
为 API 配置网关响应。网关响应是 API Gateway 直接返回或使用 Lambda 授权方返回的响应。有关更多信息，请参阅[网关响应的 Api Gateway OpenApi 扩展](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.html)文档。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `MergeDefinitions`   <a name="sam-api-mergedefinitions"></a>
AWS SAM 从您的 API 事件源生成OpenAPI规范。指定`true`将其 AWS SAM 合并到`AWS::Serverless::Api`资源中定义的内联OpenAPI规范中。指定 `false` 以不合并。  
`MergeDefinitions` 需要定义 `AWS::Serverless::Api` 的 `DefinitionBody` 属性。`MergeDefinitions` 与 `AWS::Serverless::Api` 的 `DefinitionUri` 属性不兼容。  
*默认值*：`false`  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `MethodSettings`   <a name="sam-api-methodsettings"></a>
配置 API 阶段的所有设置，包括日志、指标、CacheTTL、节流。  
*类型*：[ MethodSetting](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-stage-methodsetting.html) 列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::Stage`资源的`[MethodSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-methodsettings)`属性。

 `MinimumCompressionSize`   <a name="sam-api-minimumcompressionsize"></a>
允许根据客户端的 Accept-Encoding 标头压缩响应正文。当响应正文大小大于或等于您配置的阈值时，就会触发压缩。最大正文大小阈值为 10 MB（10,485,760 字节）。- 支持以下压缩类型：gzip、deflate 和身份。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi`资源的`[MinimumCompressionSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-minimumcompressionsize)`属性。

 `Mode`   <a name="sam-api-mode"></a>
此属性仅在您使用 OpenAPI 定义 REST API 时才适用。`Mode` 确定 API Gateway 如何处理资源更新。有关更多信息，请参阅 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html) 资源类型的[模式](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-mode)属性。  
*有效值*：`overwrite` 或 `merge`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi`资源的`[Mode](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-mode)`属性。

 `Models`   <a name="sam-api-models"></a>
您的 API 方法要使用的架构。可以使用 JSON 或 YAML 描述这些架构。有关示例模型，请参阅本页底部的“示例”部分。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Name`   <a name="sam-api-name"></a>
API Gateway RestApi 资源的名称  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-name)`属性。

 `OpenApiVersion`   <a name="sam-api-openapiversion"></a>
 OpenApi 要使用的版本。这可以是 `2.0` Swagger 规范，也可以是 OpenApi 3.0 版本之一，比如。`3.0.1`有关 OpenAPI 的更多信息，请参阅 [OpenAPI 规范](https://swagger.io/specification/)。  
 AWS SAM 创建一个默认情况下名为`Stage`的阶段。将此属性设置为任何有效值将阻止阶段 `Stage` 的创建。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`PropagateTags`  <a name="sam-api-propagatetags"></a>
指明是否将 `Tags` 属性中的标签传递给 [AWS::Serverless::Api](sam-specification-generated-resources-api.md) 生成的资源。指定 `True` 以在生成的资源中传播标签。  
*类型*：布尔值  
*必需*：否  
*默认值*：`False`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`Policy`  <a name="sam-api-policy"></a>
一个策略文档，其中包含 API 的权限。要设置策略的 ARN，请使用 `!Join` 内部函数（`""` 作为分隔符）以及值 `"execute-api:/"` 和 `"*"`。  
*类型*：JSON  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi`资源的 P [ol](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-policy) icy 属性。

 `StageName`   <a name="sam-api-stagename"></a>
阶段的名称，API Gateway 将它用作调用的统一资源标识符 (URI) 中的第一个路径部分。  
要引用阶段资源，请使用 `<api-logical-id>.Stage`。有关指定 [AWS::Serverless::Api](#sam-resource-api) 资源时引用生成资源的更多信息，请参阅 [CloudFormation 指定时AWS::Serverless::Api生成的资源](sam-specification-generated-resources-api.md)。有关生成的 CloudFormation 资源的一般信息，请参阅[生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::Stage`资源的`[StageName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-stagename)`属性。它在 SAM 中为必需，但在 API Gateway 中并非必需  
*附加说明*：隐式 API 的阶段名称为 “Prod”。

 `Tags`   <a name="sam-api-tags"></a>
指定要添加到此 API Gateway 阶段的标签的映射（字符串到字符串）。有关标签的有效键和值的详细信息，请参阅*《AWS CloudFormation 用户指南》*中的[资源标签](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html)。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::Stage`资源的`[Tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-tags)`属性。SAM 中的 Tags 属性由 Key: Value CloudFormation 对组成；其中包含标签对象的列表。

 `TracingEnabled`   <a name="sam-api-tracingenabled"></a>
指示是否为阶段启用通过 X-Ray 进行的主动跟踪。有关 X-Ray 的更多信息，请参阅 *API Gateway 开发者指南中的 APIs 使用 X-Ray* [跟踪用户向 REST 发出的请求](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-xray.html)。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::Stage`资源的`[TracingEnabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-tracingenabled)`属性。

 `Variables`   <a name="sam-api-variables"></a>
一个定义阶段变量的映射 (字符串到字符串)，其中变量名作为键，变量值作为值。变量名称只能包含字母数字字符。值必须匹配以下正则表达式：`[A-Za-z0-9._~:/?#&=,-]+`。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::Stage`资源的`[Variables](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-stage.html#cfn-apigateway-stage-variables)`属性。

## 返回值
<a name="sam-resource-api-return-values"></a>

### Ref
<a name="sam-resource-api-return-values-ref"></a>

当向 `Ref` 内置函数提供此资源的逻辑 ID 时，它将返回底层 API Gateway API 的 ID。

有关使用 `Ref` 函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。

### Fn:: GetAtt
<a name="sam-resource-api-return-values-fn--getatt"></a>

`Fn::GetAtt` 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

有关使用 `Fn::GetAtt` 的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html)。

`RootResourceId`  <a name="RootResourceId-fn::getatt"></a>
`RestApi` 资源的根资源 ID，例如 `a0bc123d4e`。

## 示例
<a name="sam-resource-api--examples"></a>

### SimpleApiExample
<a name="sam-resource-api--examples--simpleapiexample"></a>

一个 Hello World AWS SAM 模板文件，其中包含带有 API 端点的 Lambda 函数。这是正在运行的无服务器应用程序的完整 AWS SAM 模板文件。

#### YAML
<a name="sam-resource-api--examples--simpleapiexample--yaml"></a>

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS SAM template with a simple API definition
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
  ApiFunction: # Adds a GET method at the root resource via an Api event
    Type: AWS::Serverless::Function
    Properties:
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Path: /
            Method: get
            RestApiId:
              Ref: ApiGatewayApi
      Runtime: python3.10
      Handler: index.handler
      InlineCode: |
        def handler(event, context):
            return {'body': 'Hello World!', 'statusCode': 200}
```

### ApiCorsExample
<a name="sam-resource-api--examples--apicorsexample"></a>

一个 AWS SAM 模板片段，其中包含在外部 Swagger 文件中定义的 API 以及 Lambda 集成和 CORS 配置。这只是显示[AWS::Serverless::Api](#sam-resource-api)定义的 AWS SAM 模板文件的一部分。

#### YAML
<a name="sam-resource-api--examples--apicorsexample--yaml"></a>

```
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      # Allows www.example.com to call these APIs
      # SAM will automatically add AllowMethods with a list of methods for this API
      Cors: "'www.example.com'"
      DefinitionBody: # Pull in an OpenApi definition from S3
        'Fn::Transform':
          Name: 'AWS::Include'
          # Replace "bucket" with your bucket name
          Parameters:
            Location: s3://bucket/swagger.yaml
```

### ApiCognitoAuthExample
<a name="sam-resource-api--examples--apicognitoauthexample"></a>

包含使用 Amazon Cognito 授权针对该 API 的请求的 API 的 AWS SAM 模板片段。这只是显示[AWS::Serverless::Api](#sam-resource-api)定义的 AWS SAM 模板文件的一部分。

#### YAML
<a name="sam-resource-api--examples--apicognitoauthexample--yaml"></a>

```
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Cors: "'*'"
      Auth:
        DefaultAuthorizer: MyCognitoAuthorizer
        Authorizers:
          MyCognitoAuthorizer:
            UserPoolArn:
              Fn::GetAtt: [MyCognitoUserPool, Arn]
```

### ApiModelsExample
<a name="sam-resource-api--examples--apimodelsexample"></a>

带有包含模型架构的 API 的 AWS SAM 模板片段。这只是 AWS SAM 模板文件的一部分，显示了一个包含两个模型架构的[AWS::Serverless::Api](#sam-resource-api)定义。

#### YAML
<a name="sam-resource-api--examples--apimodelsexample--yaml"></a>

```
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Models:
        User:
          type: object
          required:
            - username
            - employee_id
          properties:
            username:
              type: string
            employee_id:
              type: integer
            department:
              type: string
        Item:
          type: object
          properties:
            count:
              type: integer
            category:
              type: string
            price:
              type: integer
```

### 缓存示例
<a name="sam-resource-api--examples--caching-example"></a>

一个 Hello World AWS SAM 模板文件，其中包含带有 API 端点的 Lambda 函数。API 已为一种资源和方法启用缓存。有关缓存的更多信息，请参阅的*《API Gateway 开发人员指南》*中的[启用 API 缓存以增强响应能力](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-caching.html)。

#### YAML
<a name="sam-resource-api--examples--caching-example--yaml"></a>

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS SAM template with a simple API definition with caching turned on
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      CacheClusterEnabled: true
      CacheClusterSize: '0.5'
      MethodSettings:
        - ResourcePath: /
          HttpMethod: GET
          CachingEnabled: true
          CacheTtlInSeconds: 300
      Tags:
        CacheMethods: All 

  ApiFunction: # Adds a GET method at the root resource via an Api event
    Type: AWS::Serverless::Function
    Properties:
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Path: /
            Method: get
            RestApiId:
              Ref: ApiGatewayApi
      Runtime: python3.10
      Handler: index.handler
      InlineCode: |
        def handler(event, context):
            return {'body': 'Hello World!', 'statusCode': 200}
```

### 带私有 API 的自定义域示例
<a name="sam-resource-api--examples--custom-domain-example"></a>

一个 Hello World AWS SAM 模板文件，其中包含一个 Lambda 函数，该函数的 API 终端节点映射到私有域。该模板在 VPC 端点与私有域之间创建域访问关联。有关更多信息，请参阅 [API Gateway APIs 中的私有自定义域名](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-custom-domains.html)。

#### YAML
<a name="sam-resource-api--examples--custom-domain-example--yaml"></a>

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: AWS SAM template configured with a custom domain using a private API

Parameters:
    DomainName:
      Type: String
      Default: mydomain.example.com
    CertificateArn:
      Type: String
    HostedZoneId:
      Type: String
    VpcEndpointId:
      Type: String
    VpcEndpointDomainName:
      Type: String
    VpcEndpointHostedZoneId:
      Type: String

Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      InlineCode: |
        def handler(event, context):
            return {'body': 'Hello World!', 'statusCode': 200}
      Handler: index.handler
      Runtime: python3.13
      Events:
        Fetch:
          Type: Api
          Properties:
            RestApiId:
              Ref: MyApi
            Method: Get
            Path: /get
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      EndpointConfiguration:
        Type: PRIVATE
        VPCEndpointIds:
        - !Ref VpcEndpointId
      Policy:
        Version: '2012-10-17		 	 	 '
        Statement:
        - Effect: Allow
          Principal: '*'
          Action: execute-api:Invoke
          Resource: execute-api:/*
        - Effect: Deny
          Principal: '*'
          Action: execute-api:Invoke
          Resource: execute-api:/*
          Condition:
            StringNotEquals:
              aws:SourceVpce: !Ref VpcEndpointId
      Domain:
        DomainName: !Ref DomainName
        CertificateArn: !Ref CertificateArn
        EndpointConfiguration: PRIVATE
        BasePath:
        - /
        Route53:
          HostedZoneId: !Ref HostedZoneId
          VpcEndpointDomainName: !Ref VpcEndpointDomainName
          VpcEndpointHostedZoneId: !Ref VpcEndpointHostedZoneId
        AccessAssociation:
          VpcEndpointId: !Ref VpcEndpointId
        Policy:
          Version: '2012-10-17		 	 	 '
          Statement:
          - Effect: Allow
            Principal: '*'
            Action: execute-api:Invoke
            Resource: execute-api:/*
          - Effect: Deny
            Principal: '*'
            Action: execute-api:Invoke
            Resource: execute-api:/*
            Condition:
              StringNotEquals:
                aws:SourceVpce: !Ref VpcEndpointId
```

# ApiAuth
<a name="sam-property-api-apiauth"></a>

配置授权，以控制对 API Gateway API 的访问。

有关使用配置访问权限的更多信息和示例， AWS SAM 请参阅[使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。

## 语法
<a name="sam-property-api-apiauth-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-apiauth-syntax.yaml"></a>

```
  AddApiKeyRequiredToCorsPreflight: Boolean
  [AddDefaultAuthorizerToCorsPreflight](#sam-api-apiauth-adddefaultauthorizertocorspreflight): Boolean
  [ApiKeyRequired](#sam-api-apiauth-apikeyrequired): Boolean
  [Authorizers](#sam-api-apiauth-authorizers): CognitoAuthorizer | LambdaTokenAuthorizer | LambdaRequestAuthorizer | AWS_IAM
  [DefaultAuthorizer](#sam-api-apiauth-defaultauthorizer): String
  [InvokeRole](#sam-api-apiauth-invokerole): String
  [ResourcePolicy](#sam-api-apiauth-resourcepolicy): ResourcePolicyStatement
  [UsagePlan](#sam-api-apiauth-usageplan): ApiUsagePlan
```

**注意**  
该 `Authorizers` 属性包含 `AWS_IAM`，但无需为 `AWS_IAM` 进行额外配置。有关示例，请参阅[AWS IAM](#sam-property-api-apiauth--examples--aws_iam)。

## Properties
<a name="sam-property-api-apiauth-properties"></a>

 `AddApiKeyRequiredToCorsPreflight`   <a name="sam-api-apiauth-addapikeyrequiredtocorspreflight"></a>
如果设置了 `ApiKeyRequired` 和 `Cors` 属性，则设置 `AddApiKeyRequiredToCorsPreflight` 会导致 API 密钥被添加到 `Options` 属性中。  
*类型*：布尔值  
*必需*：否  
*默认值*：`True`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AddDefaultAuthorizerToCorsPreflight`   <a name="sam-api-apiauth-adddefaultauthorizertocorspreflight"></a>
如果设置了 `DefaultAuthorizer` 和 `Cors` 属性，则设置 `AddDefaultAuthorizerToCorsPreflight` 会导致默认授权方被添加到 OpenAPI 部分的 `Options` 属性中。  
*类型*：布尔值  
*必需*：否  
*默认值*：True  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ApiKeyRequired`   <a name="sam-api-apiauth-apikeyrequired"></a>
如果设置为 true，则所有 API 事件都需要 API 密钥。有关 API 密钥的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API 密钥创建和使用使用计划](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html)。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Authorizers`   <a name="sam-api-apiauth-authorizers"></a>
用于控制对 API Gateway API 的访问的授权方。  
有关更多信息，请参阅 [使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。  
*类型*:[CognitoAuthorizer](sam-property-api-cognitoauthorizer.md)\$1 [LambdaTokenAuthorizer](sam-property-api-lambdatokenauthorizer.md)\$1 [LambdaRequestAuthorizer](sam-property-api-lambdarequestauthorizer.md)\$1 AWS\$1IAM  
*必需*：否  
*默认值*：无  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*其他说明*：SAM 在 Api 的 OpenApi 定义中添加了授权方。

 `DefaultAuthorizer`   <a name="sam-api-apiauth-defaultauthorizer"></a>
为 API Gateway API 指定默认授权方，默认情况下，该授权方将用于授权 API 调用。  
如果将与此 API EventSource 关联的函数的 Api 配置为使用 IAM 权限，则必须将此属性设置为`AWS_IAM`，否则将导致错误。
*类型*：字符串  
*必需*：否  
*默认值*：无  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `InvokeRole`   <a name="sam-api-apiauth-invokerole"></a>
将所有资源和方法的集成凭证设置为此值。  
`CALLER_CREDENTIALS` 映射到 `arn:aws:iam:::<user>/`，后者使用调用者凭证来调用端点。  
*有效值*: `CALLER_CREDENTIALS`, `NONE`, `IAMRoleArn`   
*类型*：字符串  
*必需*：否  
*默认值*：`CALLER_CREDENTIALS`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ResourcePolicy`   <a name="sam-api-apiauth-resourcepolicy"></a>
为 API 中的所有方法和路径配置资源策略。  
*类型*：[ResourcePolicyStatement](sam-property-api-resourcepolicystatement.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*附加说明*：也可以使用 [ApiFunctionAuth](sam-property-function-apifunctionauth.md) 在各个 `AWS::Serverless::Function` 中定义此设置。这是 with 所必需 APIs 的`EndpointConfiguration: PRIVATE`。

 `UsagePlan`   <a name="sam-api-apiauth-usageplan"></a>
配置与此 API 关联的使用计划。有关使用计划的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API 密钥创建和使用使用计划](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html)。  
设置此 AWS SAM 属性后，此属性会额外生成三个 CloudFormation 资源：a [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html)、a 和[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html)。有关此场景的更多信息，请参阅[UsagePlan 属性已指定](sam-specification-generated-resources-api.md#sam-specification-generated-resources-api-usage-plan)。有关生成的 CloudFormation 资源的一般信息，请参阅[生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。  
*类型*：[ApiUsagePlan](sam-property-api-apiusageplan.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-apiauth--examples"></a>

### CognitoAuth
<a name="sam-property-api-apiauth--examples--cognitoauth"></a>

Cognito 身份验证示例

#### YAML
<a name="sam-property-api-apiauth--examples--cognitoauth--yaml"></a>

```
Auth:
  Authorizers:
    MyCognitoAuth:
     UserPoolArn:
       Fn::GetAtt:
         - MyUserPool
         - Arn
     AuthType: "COGNITO_USER_POOLS"
  DefaultAuthorizer: MyCognitoAuth
  InvokeRole: CALLER_CREDENTIALS
  AddDefaultAuthorizerToCorsPreflight: false
  ApiKeyRequired: false
  ResourcePolicy:
    CustomStatements: [{
      "Effect": "Allow",
      "Principal": "*",
      "Action": "execute-api:Invoke",
      "Resource": "execute-api:/Prod/GET/pets",
      "Condition": {
          "IpAddress": {
              "aws:SourceIp": "1.2.3.4"
          }
        }
    }]
    IpRangeDenylist:
      - "10.20.30.40"
```

### AWS IAM
<a name="sam-property-api-apiauth--examples--aws_iam"></a>

AWS IAM 示例

#### YAML
<a name="sam-property-api-apiauth--examples--cognitoauth--yaml"></a>

```
Auth:
  Authorizers: AWS_IAM
```

# ApiUsagePlan
<a name="sam-property-api-apiusageplan"></a>

为 API Gateway API 配置使用计划。有关使用计划的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API 密钥创建和使用使用计划](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-api-usage-plans.html)。

## 语法
<a name="sam-property-api-apiusageplan-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-apiusageplan-syntax.yaml"></a>

```
  [CreateUsagePlan](#sam-api-apiusageplan-createusageplan): String
  [Description](#sam-api-apiusageplan-description): String
  [Quota](#sam-api-apiusageplan-quota): [QuotaSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-quota)
  [Tags](#sam-api-apiusageplan-tags): List
  [Throttle](#sam-api-apiusageplan-throttle): [ThrottleSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-throttle)
  [UsagePlanName](#sam-api-apiusageplan-usageplanname): String
```

## Properties
<a name="sam-property-api-apiusageplan-properties"></a>

 `CreateUsagePlan`   <a name="sam-api-apiusageplan-createusageplan"></a>
确定如何配置此使用计划。有效值包括 `PER_API`、`SHARED` 和 `NONE`。  
`PER_API` 会创建特定于此 API 的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html)、[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-apikey.html) 和 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplankey.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplankey.html) 资源。这些资源的逻辑 IDs 分别为`<api-logical-id>UsagePlan``<api-logical-id>ApiKey``<api-logical-id>UsagePlanKey`、和。  
`SHARED`创建[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html)、和[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplankey.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplankey.html)资源，这些资源在同一 AWS SAM 模板`CreateUsagePlan: SHARED`中也包含的任何 API 之间共享。这些资源的逻辑 IDs 分别为`ServerlessUsagePlan``ServerlessApiKey``ServerlessUsagePlanKey`、和。如果您使用此选项，我们建议您仅在一个 API 资源中为此使用计划添加其他配置，以避免定义冲突和状态不确定性。  
`NONE` 禁止创建使用计划或将使用计划与此 API 关联。在 [模板的 “全局” 部分 AWS SAM](sam-specification-template-anatomy-globals.md) 中指定了 `SHARED` 或 `PER_API` 的情况下才需要这样做。  
*有效值*：`PER_API`、`SHARED` 和 `NONE`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Description`   <a name="sam-api-apiusageplan-description"></a>
使用计划的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-description)`属性。

 `Quota`   <a name="sam-api-apiusageplan-quota"></a>
配置用户可在指定时间间隔内发出的请求的数量。  
*类型*：[QuotaSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-quota)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[Quota](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-quota)`属性。

 `Tags`   <a name="sam-api-apiusageplan-tags"></a>
与使用计划关联的任意标签（键值对）的数组。  
此属性使用[CloudFormation 标签类型](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[Tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-tags)`属性。

 `Throttle`   <a name="sam-api-apiusageplan-throttle"></a>
配置整体请求速率（每秒平均请求数）和突发容量。  
*类型*：[ThrottleSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-throttle)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[Throttle](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-throttle)`属性。

 `UsagePlanName`   <a name="sam-api-apiusageplan-usageplanname"></a>
使用计划的名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::UsagePlan`资源的`[UsagePlanName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html#cfn-apigateway-usageplan-usageplanname)`属性。

## 示例
<a name="sam-property-api-apiusageplan--examples"></a>

### UsagePlan
<a name="sam-property-api-apiusageplan--examples--usageplan"></a>

以下是使用计划示例。

#### YAML
<a name="sam-property-api-apiusageplan--examples--usageplan--yaml"></a>

```
Auth:
  UsagePlan:
    CreateUsagePlan: PER_API
    Description: Usage plan for this API
    Quota:
      Limit: 500
      Period: MONTH
    Throttle:
      BurstLimit: 100
      RateLimit: 50
    Tags:
      - Key: TagName
        Value: TagValue
```

# CognitoAuthorizer
<a name="sam-property-api-cognitoauthorizer"></a>

定义 Amazon Cognito 用户群体授权方。

有关更多信息以及示例，请参阅 [使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。

## 语法
<a name="sam-property-api-cognitoauthorizer-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-cognitoauthorizer-syntax.yaml"></a>

```
  [AuthorizationScopes](#sam-api-cognitoauthorizer-authorizationscopes): List
  [Identity](#sam-api-cognitoauthorizer-identity): CognitoAuthorizationIdentity
  [UserPoolArn](#sam-api-cognitoauthorizer-userpoolarn): String
```

## Properties
<a name="sam-property-api-cognitoauthorizer-properties"></a>

 `AuthorizationScopes`   <a name="sam-api-cognitoauthorizer-authorizationscopes"></a>
此授权方的授权范围列表。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Identity`   <a name="sam-api-cognitoauthorizer-identity"></a>
此属性可用于在授权方传入请求中指定 `IdentitySource`。  
*类型*：[CognitoAuthorizationIdentity](sam-property-api-cognitoauthorizationidentity.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `UserPoolArn`   <a name="sam-api-cognitoauthorizer-userpoolarn"></a>
可以指用户 pool/specify 一个你想向其添加这个 cognito 授权者的用户池 arn  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-cognitoauthorizer--examples"></a>

### CognitoAuth
<a name="sam-property-api-cognitoauthorizer--examples--cognitoauth"></a>

Cognito 身份验证示例

#### YAML
<a name="sam-property-api-cognitoauthorizer--examples--cognitoauth--yaml"></a>

```
Auth:
  Authorizers:
    MyCognitoAuth:
      AuthorizationScopes:
        - scope1
        - scope2
      UserPoolArn:
        Fn::GetAtt:
          - MyCognitoUserPool
          - Arn
      Identity:
        Header: MyAuthorizationHeader
        ValidationExpression: myauthvalidationexpression
```

# CognitoAuthorizationIdentity
<a name="sam-property-api-cognitoauthorizationidentity"></a>

此属性可用于在授权方的传入请求 IdentitySource 中指定。有关更多信息， IdentitySource 请参阅 A [ApiGateway uthorizer OpenApi 扩展](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html)。

## 语法
<a name="sam-property-api-cognitoauthorizationidentity-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-cognitoauthorizationidentity-syntax.yaml"></a>

```
  [Header](#sam-api-cognitoauthorizationidentity-header): String
  [ReauthorizeEvery](#sam-api-cognitoauthorizationidentity-reauthorizeevery): Integer
  [ValidationExpression](#sam-api-cognitoauthorizationidentity-validationexpression): String
```

## Properties
<a name="sam-property-api-cognitoauthorizationidentity-properties"></a>

 `Header`   <a name="sam-api-cognitoauthorizationidentity-header"></a>
在 OpenApi 定义中为 “授权” 指定标题名称。  
*类型*：字符串  
*必需*：否  
*默认值*：Authorization  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ReauthorizeEvery`   <a name="sam-api-cognitoauthorizationidentity-reauthorizeevery"></a>
 time-to-live(TTL) 周期，以秒为单位，用于指定 API Gateway 缓存授权方结果的时长。如果您指定一个大于 0 的值，API Gateway 将缓存授权方响应。默认情况下，API Gateway 将此属性设为 300。最大值为 3600 秒（1 小时）。  
*类型*：整数  
*必需*：否  
*默认值*：300  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ValidationExpression`   <a name="sam-api-cognitoauthorizationidentity-validationexpression"></a>
指定验证传入身份的验证表达式  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-cognitoauthorizationidentity--examples"></a>

### CognitoAuthIdentity
<a name="sam-property-api-cognitoauthorizationidentity--examples--cognitoauthidentity"></a>

#### YAML
<a name="sam-property-api-cognitoauthorizationidentity--examples--cognitoauthidentity--yaml"></a>

```
Identity:
  Header: MyCustomAuthHeader
  ValidationExpression: Bearer.*
  ReauthorizeEvery: 30
```

# LambdaRequestAuthorizer
<a name="sam-property-api-lambdarequestauthorizer"></a>

配置 Lambda 授权方以通过 Lambda 函数控制对 API 的访问。

有关更多信息以及示例，请参阅 [使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。

## 语法
<a name="sam-property-api-lambdarequestauthorizer-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-lambdarequestauthorizer-syntax.yaml"></a>

```
DisableFunctionDefaultPermissions: Boolean
[FunctionArn](#sam-api-lambdarequestauthorizer-functionarn): String
[FunctionInvokeRole](#sam-api-lambdarequestauthorizer-functioninvokerole): String
[FunctionPayloadType](#sam-api-lambdarequestauthorizer-functionpayloadtype): String
[Identity](#sam-api-lambdarequestauthorizer-identity): LambdaRequestAuthorizationIdentity
```

## Properties
<a name="sam-property-api-lambdarequestauthorizer-properties"></a>

 `DisableFunctionDefaultPermissions`   <a name="sam-api-lambdarequestauthorizer-disablefunctiondefaultpermissions"></a>
指定`true`以 AWS SAM 防止自动创建`AWS::Lambda::Permissions`资源以在您的`AWS::Serverless::Api`资源和授权者 Lambda 函数之间配置权限。  
*默认值*：`false`  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionArn`   <a name="sam-api-lambdarequestauthorizer-functionarn"></a>
指定 Lambda 函数的函数 ARN，该函数为 API 提供授权。  
AWS SAM 当为指定`AWS::Lambda::Permissions`资源时`FunctionArn`，将自动创建资源`AWS::Serverless::Api`。该 `AWS::Lambda::Permissions` 资源在您的 API 和授权方 Lambda 函数之间配置权限。
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionInvokeRole`   <a name="sam-api-lambdarequestauthorizer-functioninvokerole"></a>
将授权者凭证添加到 Lambda 授权方的 OpenApi 定义中。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionPayloadType`   <a name="sam-api-lambdarequestauthorizer-functionpayloadtype"></a>
此属性可用于定义 API 的 Lambda 授权方的类型。  
*有效值*：`TOKEN` 或 `REQUEST`  
*类型*：字符串  
*必需*：否  
*默认值*：`TOKEN`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Identity`   <a name="sam-api-lambdarequestauthorizer-identity"></a>
此属性可用于在授权方传入请求中指定 `IdentitySource`。仅当属性 `FunctionPayloadType` 为 `REQUEST` 时，该属性是必需属性。  
*类型*：[LambdaRequestAuthorizationIdentity](sam-property-api-lambdarequestauthorizationidentity.md)  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-lambdarequestauthorizer--examples"></a>

### LambdaRequestAuth
<a name="sam-property-api-lambdarequestauthorizer--examples--lambdarequestauth"></a>

#### YAML
<a name="sam-property-api-lambdarequestauthorizer--examples--lambdarequestauth--yaml"></a>

```
Authorizers:
  MyLambdaRequestAuth:
    FunctionPayloadType: REQUEST
    FunctionArn:
      Fn::GetAtt:
        - MyAuthFunction
        - Arn
    FunctionInvokeRole:
      Fn::GetAtt:
        - LambdaAuthInvokeRole
        - Arn
    Identity:
      Headers:
        - Authorization1
```

# LambdaRequestAuthorizationIdentity
<a name="sam-property-api-lambdarequestauthorizationidentity"></a>

此属性可用于在授权方的传入请求 IdentitySource 中指定。有关更多信息， IdentitySource 请参阅 A [ApiGateway uthorizer OpenApi 扩展](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html)。

## 语法
<a name="sam-property-api-lambdarequestauthorizationidentity-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-lambdarequestauthorizationidentity-syntax.yaml"></a>

```
  [Context](#sam-api-lambdarequestauthorizationidentity-context): List
  [Headers](#sam-api-lambdarequestauthorizationidentity-headers): List
  [QueryStrings](#sam-api-lambdarequestauthorizationidentity-querystrings): List
  [ReauthorizeEvery](#sam-api-lambdarequestauthorizationidentity-reauthorizeevery): Integer
  [StageVariables](#sam-api-lambdarequestauthorizationidentity-stagevariables): List
```

## Properties
<a name="sam-property-api-lambdarequestauthorizationidentity-properties"></a>

 `Context`   <a name="sam-api-lambdarequestauthorizationidentity-context"></a>
将给定的上下文字符串转换为格式 `context.contextString` 的映射表达式。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Headers`   <a name="sam-api-lambdarequestauthorizationidentity-headers"></a>
将标头转换为格式 `method.request.header.name` 的映射表达式的逗号分隔字符串。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `QueryStrings`   <a name="sam-api-lambdarequestauthorizationidentity-querystrings"></a>
将给定的查询字符串转换为格式 `method.request.querystring.queryString` 的映射表达式的逗号分隔字符串。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ReauthorizeEvery`   <a name="sam-api-lambdarequestauthorizationidentity-reauthorizeevery"></a>
 time-to-live(TTL) 周期，以秒为单位，用于指定 API Gateway 缓存授权方结果的时长。如果您指定一个大于 0 的值，API Gateway 将缓存授权方响应。默认情况下，API Gateway 将此属性设为 300。最大值为 3600 秒（1 小时）。  
*类型*：整数  
*必需*：否  
*默认值*：300  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `StageVariables`   <a name="sam-api-lambdarequestauthorizationidentity-stagevariables"></a>
将给定的阶段变量转换为格式 `stageVariables.stageVariable` 的映射表达式的逗号分隔字符串。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-lambdarequestauthorizationidentity--examples"></a>

### LambdaRequestIdentity
<a name="sam-property-api-lambdarequestauthorizationidentity--examples--lambdarequestidentity"></a>

#### YAML
<a name="sam-property-api-lambdarequestauthorizationidentity--examples--lambdarequestidentity--yaml"></a>

```
Identity:
  QueryStrings:
    - auth
  Headers:
    - Authorization
  StageVariables:
    - VARIABLE
  Context:
    - authcontext
  ReauthorizeEvery: 100
```

# LambdaTokenAuthorizer
<a name="sam-property-api-lambdatokenauthorizer"></a>

配置 Lambda 授权方以通过 Lambda 函数控制对 API 的访问。

有关更多信息以及示例，请参阅 [使用您的 AWS SAM 模板控制 API 访问权限](serverless-controlling-access-to-apis.md)。

## 语法
<a name="sam-property-api-lambdatokenauthorizer-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-lambdatokenauthorizer-syntax.yaml"></a>

```
DisableFunctionDefaultPermissions: Boolean
[FunctionArn](#sam-api-lambdatokenauthorizer-functionarn): String
[FunctionInvokeRole](#sam-api-lambdatokenauthorizer-functioninvokerole): String
[FunctionPayloadType](#sam-api-lambdatokenauthorizer-functionpayloadtype): String
[Identity](#sam-api-lambdatokenauthorizer-identity): LambdaTokenAuthorizationIdentity
```

## Properties
<a name="sam-property-api-lambdatokenauthorizer-properties"></a>

 `DisableFunctionDefaultPermissions`   <a name="sam-api-lambdatokenauthorizer-disablefunctiondefaultpermissions"></a>
指定`true`以 AWS SAM 防止自动创建`AWS::Lambda::Permissions`资源以在您的`AWS::Serverless::Api`资源和授权者 Lambda 函数之间配置权限。  
*默认值*：`false`  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionArn`   <a name="sam-api-lambdatokenauthorizer-functionarn"></a>
指定 Lambda 函数的函数 ARN，该函数为 API 提供授权。  
AWS SAM 当为指定`AWS::Lambda::Permissions`资源时`FunctionArn`，将自动创建资源`AWS::Serverless::Api`。该 `AWS::Lambda::Permissions` 资源在您的 API 和授权方 Lambda 函数之间配置权限。
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionInvokeRole`   <a name="sam-api-lambdatokenauthorizer-functioninvokerole"></a>
将授权者凭证添加到 Lambda 授权方的 OpenApi 定义中。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionPayloadType`   <a name="sam-api-lambdatokenauthorizer-functionpayloadtype"></a>
此属性可用于定义 Api 的 Lambda 授权方的类型。  
*有效值*：`TOKEN` 或 `REQUEST`  
*类型*：字符串  
*必需*：否  
*默认值*：`TOKEN`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Identity`   <a name="sam-api-lambdatokenauthorizer-identity"></a>
此属性可用于在授权方传入请求中指定 `IdentitySource`。仅当属性 `FunctionPayloadType` 为 `REQUEST` 时，该属性是必需属性。  
*类型*：[LambdaTokenAuthorizationIdentity](sam-property-api-lambdatokenauthorizationidentity.md)  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-lambdatokenauthorizer--examples"></a>

### LambdaTokenAuth
<a name="sam-property-api-lambdatokenauthorizer--examples--lambdatokenauth"></a>

#### YAML
<a name="sam-property-api-lambdatokenauthorizer--examples--lambdatokenauth--yaml"></a>

```
Authorizers:
  MyLambdaTokenAuth:
    FunctionArn:
      Fn::GetAtt:
        - MyAuthFunction
        - Arn
    Identity:
      Header: MyCustomAuthHeader # OPTIONAL; Default: 'Authorization'
      ValidationExpression: mycustomauthexpression # OPTIONAL
      ReauthorizeEvery: 20 # OPTIONAL; Service Default: 300
```

### BasicLambdaTokenAuth
<a name="sam-property-api-lambdatokenauthorizer--examples--basiclambdatokenauth"></a>

#### YAML
<a name="sam-property-api-lambdatokenauthorizer--examples--basiclambdatokenauth--yaml"></a>

```
Authorizers:
  MyLambdaTokenAuth:
    FunctionArn:
      Fn::GetAtt:
        - MyAuthFunction
        - Arn
```

# LambdaTokenAuthorizationIdentity
<a name="sam-property-api-lambdatokenauthorizationidentity"></a>

此属性可用于在授权方的传入请求 IdentitySource 中指定。有关更多信息， IdentitySource 请参阅[ApiGateway 授权器 OpenApi 扩展](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html)。

## 语法
<a name="sam-property-api-lambdatokenauthorizationidentity-syntax"></a>

 要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-lambdatokenauthorizationidentity-syntax.yaml"></a>

```
  [Header](#sam-api-lambdatokenauthorizationidentity-header): String
  [ReauthorizeEvery](#sam-api-lambdatokenauthorizationidentity-reauthorizeevery): Integer
  [ValidationExpression](#sam-api-lambdatokenauthorizationidentity-validationexpression): String
```

## Properties
<a name="sam-property-api-lambdatokenauthorizationidentity-properties"></a>

 `Header`   <a name="sam-api-lambdatokenauthorizationidentity-header"></a>
在 OpenApi 定义中为授权指定标题名称。  
*类型*：字符串  
*必需*：否  
*默认值*：Authorization  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ReauthorizeEvery`   <a name="sam-api-lambdatokenauthorizationidentity-reauthorizeevery"></a>
 time-to-live(TTL) 周期，以秒为单位，用于指定 API Gateway 缓存授权方结果的时长。如果您指定一个大于 0 的值，API Gateway 将缓存授权方响应。默认情况下，API Gateway 将此属性设为 300。最大值为 3600 秒（1 小时）。  
*类型*：整数  
*必需*：否  
*默认值*：300  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ValidationExpression`   <a name="sam-api-lambdatokenauthorizationidentity-validationexpression"></a>
指定验证传入身份的验证表达式。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-lambdatokenauthorizationidentity--examples"></a>

### LambdaTokenIdentity
<a name="sam-property-api-lambdatokenauthorizationidentity--examples--lambdatokenidentity"></a>

#### YAML
<a name="sam-property-api-lambdatokenauthorizationidentity--examples--lambdatokenidentity--yaml"></a>

```
Identity:
  Header: MyCustomAuthHeader
  ValidationExpression: Bearer.*
  ReauthorizeEvery: 30
```

# ResourcePolicyStatement
<a name="sam-property-api-resourcepolicystatement"></a>

为 API 的所有方法和路径配置资源策略。有关资源策略的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API Gateway 资源策略控制 API 的访问权限](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html)。

## 语法
<a name="sam-property-api-resourcepolicystatement-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-resourcepolicystatement-syntax.yaml"></a>

```
  [AwsAccountBlacklist](#sam-api-resourcepolicystatement-awsaccountblacklist): List
  [AwsAccountWhitelist](#sam-api-resourcepolicystatement-awsaccountwhitelist): List
  [CustomStatements](#sam-api-resourcepolicystatement-customstatements): List
  [IntrinsicVpcBlacklist](#sam-api-resourcepolicystatement-intrinsicvpcblacklist): List
  [IntrinsicVpcWhitelist](#sam-api-resourcepolicystatement-intrinsicvpcwhitelist): List
  [IntrinsicVpceBlacklist](#sam-api-resourcepolicystatement-intrinsicvpceblacklist): List
  [IntrinsicVpceWhitelist](#sam-api-resourcepolicystatement-intrinsicvpcewhitelist): List
  [IpRangeBlacklist](#sam-api-resourcepolicystatement-iprangeblacklist): List
  [IpRangeWhitelist](#sam-api-resourcepolicystatement-iprangewhitelist): List
  [SourceVpcBlacklist](#sam-api-resourcepolicystatement-sourcevpcblacklist): List
  [SourceVpcWhitelist](#sam-api-resourcepolicystatement-sourcevpcwhitelist): List
```

## Properties
<a name="sam-property-api-resourcepolicystatement-properties"></a>

 `AwsAccountBlacklist`   <a name="sam-api-resourcepolicystatement-awsaccountblacklist"></a>
要封锁的 AWS 账户。  
*类型*：字符串列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AwsAccountWhitelist`   <a name="sam-api-resourcepolicystatement-awsaccountwhitelist"></a>
要允许的 AWS 账户。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：字符串列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `CustomStatements`   <a name="sam-api-resourcepolicystatement-customstatements"></a>
适用于此 API 的自定义资源策略语句列表。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpcBlacklist`   <a name="sam-api-resourcepolicystatement-intrinsicvpcblacklist"></a>
要屏蔽的虚拟私有云列表 (VPCs)，其中每个 VPC 都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内部函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpcWhitelist`   <a name="sam-api-resourcepolicystatement-intrinsicvpcwhitelist"></a>
 VPCs 要允许的列表，其中每个 VPC 都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内部函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpceBlacklist`   <a name="sam-api-resourcepolicystatement-intrinsicvpceblacklist"></a>
要阻止的 VPC 端点列表，其中每个 VPC 端点都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内置函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpceWhitelist`   <a name="sam-api-resourcepolicystatement-intrinsicvpcewhitelist"></a>
要允许的 VPC 端点列表，其中每个 VPC 端点都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内置函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IpRangeBlacklist`   <a name="sam-api-resourcepolicystatement-iprangeblacklist"></a>
要阻止的 IP 地址或地址范围。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IpRangeWhitelist`   <a name="sam-api-resourcepolicystatement-iprangewhitelist"></a>
要允许的 IP 地址或地址范围。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceVpcBlacklist`   <a name="sam-api-resourcepolicystatement-sourcevpcblacklist"></a>
要阻止的源 VPC 或 VPC 端点。源 VPC 名称必须以 `"vpc-"` 开头，源 VPC 端点名称必须以 `"vpce-"` 开头。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceVpcWhitelist`   <a name="sam-api-resourcepolicystatement-sourcevpcwhitelist"></a>
要允许的源 VPC 或 VPC 端点。源 VPC 名称必须以 `"vpc-"` 开头，源 VPC 端点名称必须以 `"vpce-"` 开头。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-resourcepolicystatement--examples"></a>

### 资源策略示例
<a name="sam-property-api-resourcepolicystatement--examples--resource-policy-example"></a>

以下示例屏蔽两个 IP 地址和一个源 VPC，并允许一个 AWS 账户。

#### YAML
<a name="sam-property-api-resourcepolicystatement--examples--resource-policy-example--yaml"></a>

```
Auth:
  ResourcePolicy:
    CustomStatements: [{
                         "Effect": "Allow",
                         "Principal": "*",
                         "Action": "execute-api:Invoke",
                         "Resource": "execute-api:/Prod/GET/pets",
                         "Condition": {
                           "IpAddress": {
                             "aws:SourceIp": "1.2.3.4"
                           }
                         }
                       }]
    IpRangeBlacklist:
      - "10.20.30.40"
      - "1.2.3.4"
    SourceVpcBlacklist:
      - "vpce-1a2b3c4d"
    AwsAccountWhitelist:
      - "111122223333"
    IntrinsicVpcBlacklist:
      - "{{resolve:ssm:SomeVPCReference:1}}" 
      - !Ref MyVPC
    IntrinsicVpceWhitelist:
      - "{{resolve:ssm:SomeVPCEReference:1}}" 
      - !Ref MyVPCE
```

# ApiDefinition
<a name="sam-property-api-apidefinition"></a>

定义 API 的 OpenAPI 文档。

## 语法
<a name="sam-property-api-apidefinition-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-apidefinition-syntax.yaml"></a>

```
  [Bucket](#sam-api-apidefinition-bucket): String
  [Key](#sam-api-apidefinition-key): String
  [Version](#sam-api-apidefinition-version): String
```

## Properties
<a name="sam-property-api-apidefinition-properties"></a>

 `Bucket`   <a name="sam-api-apidefinition-bucket"></a>
存储了 OpenAPI 文件的 Amazon S3 桶的名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi``S3Location`数据类型的`[Bucket](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-s3location.html#cfn-apigateway-restapi-s3location-bucket)`属性。

 `Key`   <a name="sam-api-apidefinition-key"></a>
OpenAPI 文件的 Amazon S3 密钥。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi``S3Location`数据类型的`[Key](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-s3location.html#cfn-apigateway-restapi-s3location-key)`属性。

 `Version`   <a name="sam-api-apidefinition-version"></a>
对于受版本控制的对象，是 OpenAPI 文件的版本。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi``S3Location`数据类型的`[Version](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-s3location.html#cfn-apigateway-restapi-s3location-version)`属性。

## 示例
<a name="sam-property-api-apidefinition--examples"></a>

### 定义 Uri 示例
<a name="sam-property-api-apidefinition--examples--definition-uri-example"></a>

API 定义示例

#### YAML
<a name="sam-property-api-apidefinition--examples--definition-uri-example--yaml"></a>

```
DefinitionUri:
  Bucket: amzn-s3-demo-bucket-name
  Key: mykey-name
  Version: 121212
```

# CorsConfiguration
<a name="sam-property-api-corsconfiguration"></a>

管理 API Gateway 的跨源资源共享 (CORS)。 APIs使用字符串指定允许使用的域，或使用其他 Cors 配置指定词典。

**注意**  
CORS AWS SAM 需要修改你的 OpenAPI 定义。在 `DefinitionBody` 中创建内联 OpenAPI 定义以开启 CORS。如果在 `CorsConfiguration` OpenAPI 定义中和属性级别设置了，则将其 AWS SAM 合并。属性级别优先于 OpenAPI 定义。

有关 CORS 的更多信息，请参阅*《API Gateway 开发人员指南》*中的[为 API Gateway REST API 资源启用 CORS](https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-cors.html)。

## 语法
<a name="sam-property-api-corsconfiguration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-corsconfiguration-syntax.yaml"></a>

```
  [AllowCredentials](#sam-api-corsconfiguration-allowcredentials): Boolean
  [AllowHeaders](#sam-api-corsconfiguration-allowheaders): String
  [AllowMethods](#sam-api-corsconfiguration-allowmethods): String
  [AllowOrigin](#sam-api-corsconfiguration-alloworigin): String
  [MaxAge](#sam-api-corsconfiguration-maxage): String
```

## Properties
<a name="sam-property-api-corsconfiguration-properties"></a>

 `AllowCredentials`   <a name="sam-api-corsconfiguration-allowcredentials"></a>
表示是否允许请求包含凭证的布尔值。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowHeaders`   <a name="sam-api-corsconfiguration-allowheaders"></a>
允许的标头字符串。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowMethods`   <a name="sam-api-corsconfiguration-allowmethods"></a>
包含允许的 HTTP 方法的字符串。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowOrigin`   <a name="sam-api-corsconfiguration-alloworigin"></a>
允许的源字符串。这可以是字符串格式的逗号分隔的列表。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `MaxAge`   <a name="sam-api-corsconfiguration-maxage"></a>
包含缓存 CORS 预检请求的秒数的字符串。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-api-corsconfiguration--examples"></a>

### CorsConfiguration
<a name="sam-property-api-corsconfiguration--examples--corsconfiguration"></a>

CORS 配置示例。这只是 AWS SAM 模板文件的一部分，其中显示了配置了 CORS 的[AWS::Serverless::Api](sam-resource-api.md)定义和. [AWS::Serverless::Function](sam-resource-function.md) 如果您使用 Lambda 代理集成或 HTTP 代理集成，则您的后端必须返回 `Access-Control-Allow-Origin`、`Access-Control-Allow-Methods` 和 `Access-Control-Allow-Headers` 标头。

#### YAML
<a name="sam-property-api-corsconfiguration--examples--corsconfiguration--yaml"></a>

```
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Cors:
        AllowMethods: "'POST, GET'"
        AllowHeaders: "'X-Forwarded-For'"
        AllowOrigin: "'https://example.com'"
        MaxAge: "'600'"
        AllowCredentials: true
  ApiFunction: # Adds a GET method at the root resource via an Api event
    Type: AWS::Serverless::Function
    Properties:
      Events:
        ApiEvent:
          Type: Api
          Properties:
            Path: /
            Method: get
            RestApiId:
              Ref: ApiGatewayApi
      Runtime: python3.10
      Handler: index.handler
      InlineCode: |
        import json
        def handler(event, context):
          return {
          'statusCode': 200,
          'headers': {
            'Access-Control-Allow-Headers': 'Content-Type',
            'Access-Control-Allow-Origin': 'https://example.com',
            'Access-Control-Allow-Methods': 'POST, GET'
            },
          'body': json.dumps('Hello from Lambda!')
          }
```

# DomainConfiguration
<a name="sam-property-api-domainconfiguration"></a>

为 API 配置自定义域。

## 语法
<a name="sam-property-api-domainconfiguration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-domainconfiguration-syntax.yaml"></a>

```
  [AccessAssociation](#sam-api-domainconfiguration-domainaccessassociation): DomainAccessAssociation
  [BasePath](#sam-api-domainconfiguration-basepath): List
  [CertificateArn](#sam-api-domainconfiguration-certificatearn): String
  [DomainName](#sam-api-domainconfiguration-domainname): String
  [EndpointConfiguration](#sam-api-domainconfiguration-endpointconfiguration): String
  [MutualTlsAuthentication](#sam-api-domainconfiguration-mutualtlsauthentication): [MutualTlsAuthentication](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-mutualtlsauthentication)
  [NormalizeBasePath](#sam-api-domainconfiguration-normalizebasepath): Boolean
  [OwnershipVerificationCertificateArn](#sam-api-domainconfiguration-ownershipverificationcertificatearn): String
  [Policy: ](#sam-api-domainconfiguration-policy)Json
  [Route53](#sam-api-domainconfiguration-route53): Route53Configuration
  [SecurityPolicy](#sam-api-domainconfiguration-securitypolicy): String
```

## Properties
<a name="sam-property-api-domainconfiguration-properties"></a>

 `AccessAssociation`   <a name="sam-api-domainconfiguration-domainaccessassociation"></a>
生成 ` AWS::ApiGateway::DomainNameAccessAssociation` 资源所需的配置。  
AWS SAM 设置此属性时会生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnameaccessassociation.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnameaccessassociation.html)资源。有关生成的 CloudFormation 资源的信息，请参阅[生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。  
*类型*：[DomainAccessAssociation](sam-property-api-domainaccessassociation.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `BasePath`   <a name="sam-api-domainconfiguration-basepath"></a>
要使用 Amazon API Gateway 域名配置的基本路径列表。  
*类型*：列表  
*必需*：否  
*默认值*：/  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::BasePathMapping`资源的`[BasePath](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-basepathmapping.html#cfn-apigateway-basepathmapping-basepath)`属性。 AWS SAM 创建多个`AWS::ApiGateway::BasePathMapping`资源，每个资源在此属性中`BasePath`指定一个。

 `CertificateArn`   <a name="sam-api-domainconfiguration-certificatearn"></a>
 AWS 托管证书的亚马逊资源名称 (ARN) 此域名的终端节点。 AWS Certificate Manager 是唯一支持的来源。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGateway::DomainName`资源的`[CertificateArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-certificatearn)`属性。如果设置`EndpointConfiguration`为`REGIONAL`（默认值），则`CertificateArn`映射到 [RegionalCertificateArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-regionalcertificatearn)in `AWS::ApiGateway::DomainName`。如果设置`EndpointConfiguration`为`EDGE`，则`CertificateArn`映射到 [CertificateArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-certificatearn)in `AWS::ApiGateway::DomainName`。如果设置`EndpointConfiguration`为`PRIVATE`，则此属性将传递给 [AWS::ApiGateway::DomainNameV2](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnamev2) 资源。  
*其他说明*：对于终`EDGE`端节点，您必须在`us-east-1` AWS 区域中创建证书。

 `DomainName`   <a name="sam-api-domainconfiguration-domainname"></a>
API Gateway API 的自定义域名。不支持大写字母。  
AWS SAM 设置此属性时会生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html)资源。有关此场景的更多信息，请参阅[DomainName 属性已指定](sam-specification-generated-resources-api.md#sam-specification-generated-resources-api-domain-name)。有关生成的 CloudFormation 资源的信息，请参阅[生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::DomainName`资源的`[DomainName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-domainname)`属性，或者在设置为[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnamev2](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnamev2)时传递给 EndpointConfiguration 该属性`PRIVATE`。

 `EndpointConfiguration`   <a name="sam-api-domainconfiguration-endpointconfiguration"></a>
定义要映射到自定义域的 API Gateway 端点的类型。此属性的值决定了该`CertificateArn`属性的映射方式 CloudFormation。  
*有效值*：`EDGE`、`REGIONAL` 或 `PRIVATE`  
*类型*：字符串  
*必需*：否  
*默认值*：`REGIONAL`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `MutualTlsAuthentication`   <a name="sam-api-domainconfiguration-mutualtlsauthentication"></a>
自定义域名的相互传输层安全性协议（TLS）身份验证配置。  
*类型*：[MutualTlsAuthentication](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-mutualtlsauthentication)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::DomainName`资源的`[MutualTlsAuthentication](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-mutualtlsauthentication)`属性。

 `NormalizeBasePath`   <a name="sam-api-domainconfiguration-normalizebasepath"></a>
表示 `BasePath` 属性定义的基本路径中是否允许非字母数字字符。如果设置为 `True`，则将从基本路径中移除非字母数字字符。  
针对 `BasePath` 属性使用 `NormalizeBasePath`。  
*类型*：布尔值  
*必需*：否  
*默认值*：True  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `OwnershipVerificationCertificateArn`   <a name="sam-api-domainconfiguration-ownershipverificationcertificatearn"></a>
ACM 颁发的用于验证自定义域所有权的公有证书的 ARN。只有在配置双向 TLS 并且为 `CertificateArn` 指定了 ACM 导入的或私有 CA 证书 ARN 时才需要。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::DomainName`资源的`[OwnershipVerificationCertificateArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-ownershipverificationcertificatearn)`属性。

 `Policy`   <a name="sam-api-domainconfiguration-policy"></a>
要附加到该 AP Gateway 域名的 IAM 策略。仅当 `EndpointConfiguration` 设置为 `PRIVATE` 时适用。  
*类型*：Json  
*必需*：否  
*CloudFormation 兼容性*：当设置为时`EndpointConfiguration`，此`Policy`属性将直接传递给`AWS::ApiGateway::DomainNameV2`资源的属性`PRIVATE`。有关有效政策文件的示例，请参阅 [AWS::ApiGateway::DomainNameV2](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnamev2)。

 `Route53`   <a name="sam-api-domainconfiguration-route53"></a>
定义 Amazon Route 53 配置。  
*类型*：[Route53Configuration](sam-property-api-route53configuration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SecurityPolicy`   <a name="sam-api-domainconfiguration-securitypolicy"></a>
此域名的 TLS 版本加密码套件。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::DomainName`资源的`[SecurityPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html#cfn-apigateway-domainname-securitypolicy)`属性，或者在设置为[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnamev2](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnamev2)时传递给`EndpointConfiguration`该属性`PRIVATE`。对于`PRIVATE` 端点，仅支持 TLS\$11\$12。

## 示例
<a name="sam-property-api-domainconfiguration--examples"></a>

### DomainName
<a name="sam-property-api-domainconfiguration--examples--domainname"></a>

DomainName 示例

#### YAML
<a name="sam-property-api-domainconfiguration--examples--domainname--yaml"></a>

```
Domain:
  DomainName: www.example.com
  CertificateArn: arn-example
  EndpointConfiguration: EDGE
  Route53:
    HostedZoneId: Z1PA6795UKMFR9
  BasePath:
    - foo
    - bar
```

# DomainAccessAssociation
<a name="sam-property-api-domainaccessassociation"></a>

配置访问关联源与私有自定义域名之间的域访问关联。唯一支持的访问关联源是 VPC 端点 ID。有关更多信息，请参阅 [API Gateway APIs 中的私有自定义域名](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-private-custom-domains.html)。

## 语法
<a name="sam-property-api-domainaccessassociation-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-domainaccessassociation-syntax.yaml"></a>

```
 VpcEndpointId: String
```

## Properties
<a name="sam-property-api-domainaccessassociation-properties"></a>

 `VpcEndpointId`   <a name="sam-api-domainaccessassociation-vpcendpointid"></a>
与 API Gateway VPC 服务关联的 VPC 接口端点的端点 ID。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::DomainNameAccessAssociation`资源的`[ AccessAssociationSource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainnameaccessassociation.html#cfn-apigateway-domainnameaccessassociation-accessassociationsource)`属性。

# Route53Configuration
<a name="sam-property-api-route53configuration"></a>

为 API 配置 Route53 记录集。

## 语法
<a name="sam-property-api-route53configuration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-route53configuration-syntax.yaml"></a>

```
  [DistributionDomainName](#sam-api-route53configuration-distributiondomainname): String
  [EvaluateTargetHealth](#sam-api-route53configuration-evaluatetargethealth): Boolean
  [HostedZoneId](#sam-api-route53configuration-hostedzoneid): String
  [HostedZoneName](#sam-api-route53configuration-hostedzonename): String
  [IpV6](#sam-api-route53configuration-ipv6): Boolean
  Region: String
  SetIdentifier: String
  VpcEndpointDomainName: String
  VpcEndpointHostedZoneId: String
```

## Properties
<a name="sam-property-api-route53configuration-properties"></a>

 `DistributionDomainName`   <a name="sam-api-route53configuration-distributiondomainname"></a>
配置 API 自定义域名的自定义分配。  
*类型*：字符串  
*必需*：否  
*默认*：使用 API Gateway 分配。  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup AliasTarget`资源的`[DNSName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget-1.html#cfn-route53-aliastarget-dnshostname)`属性。  
*其他说明*：[CloudFront分配](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-distribution.html)的域名。

 `EvaluateTargetHealth`   <a name="sam-api-route53configuration-evaluatetargethealth"></a>
如果 EvaluateTargetHealth 为 true，则别名记录将继承引用 AWS 资源的运行状况，例如 Elastic Load Balancing 负载均衡器或托管区域中的其他记录。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup AliasTarget`资源的`[EvaluateTargetHealth](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html#cfn-route53-aliastarget-evaluatetargethealth)`属性。  
*其他说明*：当别名目标为 CloudFront 分布时，您不能 EvaluateTargetHealth 将其设置为 true。

 `HostedZoneId`   <a name="sam-api-route53configuration-hostedzoneid"></a>
要在其中创建记录的托管区的 ID。  
指定 `HostedZoneName` 或 `HostedZoneId`，但不能同时指定两者。如果您拥有多个使用相同域名的托管区域，则必须使用 `HostedZoneId` 指定托管区。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup RecordSet`资源的`[HostedZoneId](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-1.html#cfn-route53-recordset-hostedzoneid)`属性。

 `HostedZoneName`   <a name="sam-api-route53configuration-hostedzonename"></a>
要在其中创建记录的托管区的名称。  
指定 `HostedZoneName` 或 `HostedZoneId`，但不能同时指定两者。如果您拥有多个使用相同域名的托管区域，则必须使用 `HostedZoneId` 指定托管区。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup RecordSet`资源的`[HostedZoneName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-1.html#cfn-route53-recordset-hostedzonename)`属性。

 `IpV6`   <a name="sam-api-route53configuration-ipv6"></a>
设置此属性后，将 AWS SAM 创建一个`AWS::Route53::RecordSet`资源并将提供的资源的 [Type](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset.html#cfn-route53-recordset-type) 设置`AAAA`为 HostedZone。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`Region`  <a name="sam-api-route53configuration-region"></a>
*仅限基于延迟的资源记录集*：您创建此资源记录集所引用的资源的亚马逊 EC2 区域。资源通常是 AWS 资源，例如 EC2 实例或 ELB 负载均衡器，并由 IP 地址或 DNS 域名引用，具体取决于记录类型。  
当 Amazon Route 53 收到针对您已为其创建延迟资源记录集的域名和类型的 DNS 查询时，Route 53 会选择最终用户与关联亚马逊 EC2 地区之间延迟最低的延迟资源记录集。然后，Route 53 会返回与所选资源记录集相关的值。  
注意以下几点：  
+ 您只能为每个延迟资源记录集指定一个 `ResourceRecord`。
+ 您只能为每个 Amazon EC2 地区创建一个延迟资源记录集。
+ 您无需为所有 Amazon EC2 区域创建延迟资源记录集。Route 53 会从您已创建延迟资源记录集的区域中选择延迟性能最佳的区域。
+ 您不能创建 `Name` 和 `Type` 元素的值与延迟资源记录集相同的非延迟资源记录集。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup``RecordSet`数据类型的`[ Region](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-1.html#cfn-route53-recordset-region)`属性。

`SetIdentifier`  <a name="sam-api-route53configuration-setidentifier"></a>
*具有简单策略以外的路由策略的资源记录集：*用于区分具有相同名称和类型组合的多个资源记录集的标识符，如名为 acme.example.com 且类型为 A 的多个加权资源记录集。在一组具有相同名称和类型的资源记录集中，每个资源记录集的 `SetIdentifier` 值必须唯一。  
有关路由策略的信息，请参阅*《Amazon Route 53 开发人员指南》*中的[选择路由策略](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html)。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup``RecordSet`数据类型的`[ SetIdentifier](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-1.html#cfn-route53-recordset-setidentifier)`属性。

`VpcEndpointDomainName`  <a name="sam-api-route53configuration-vpcendpointdomainname"></a>
与 API Gateway VPC 服务关联的 VPC 接口端点的 DNS 名称。仅私有域需要该属性。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSet``AliasTarget`字段的`[DNSName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-aliastarget.html)`属性。

`VpcEndpointHostedZoneId`  <a name="sam-api-route53configuration-vpcendpointhostedzoneid"></a>
与 API Gateway VPC 服务关联的 VPC 接口端点的托管区。仅私有域需要该属性。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSet``AliasTarget`字段的`[HostedZoneId](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-aliastarget.html)`属性。

## 示例
<a name="sam-property-api-route53configuration--examples"></a>

### 基本示例
<a name="sam-property-api-route53configuration--examples--route-53-configuration-example"></a>

在此示例中，我们为 API 配置了自定义域和 Route 53 记录集。

#### YAML
<a name="sam-property-api-route53configuration--examples--route-53-configuration-example--yaml"></a>

```
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      Domain:
        DomainName: www.example.com
        CertificateArn: arn:aws:acm:us-east-1:123456789012:certificate/abcdef12-3456-7890-abcd-ef1234567890
        EndpointConfiguration: REGIONAL
        Route53:
          HostedZoneId: ABCDEFGHIJKLMNOP
```

# EndpointConfiguration
<a name="sam-property-api-endpointconfiguration"></a>

REST API 的端点类型。

## 语法
<a name="sam-property-api-endpointconfiguration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-api-endpointconfiguration-syntax.yaml"></a>

```
  [IpAddressType](#sam-api-endpointconfiguration-ipaddresstype): String
  [Type](#sam-api-endpointconfiguration-type): String
  [VPCEndpointIds](#sam-api-endpointconfiguration-vpcendpointids): List
```

## Properties
<a name="sam-property-api-endpointconfiguration-properties"></a>

 `IpAddressType`   <a name="sam-api-endpointconfiguration-ipaddresstype"></a>
可以调用 API 的 IP 地址类型 (RestApi)。  
*有效值*：`ipv4` 或 `dualstack`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi``EndpointConfiguration`数据类型的`[IpAddressType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-ipaddresstype)`属性。

 `Type`   <a name="sam-api-endpointconfiguration-type"></a>
REST API 的端点类型。  
*有效值*：`EDGE` 或 `REGIONAL` 或 `PRIVATE`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi``EndpointConfiguration`数据类型的`[Types](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-types)`属性。

 `VPCEndpointIds`   <a name="sam-api-endpointconfiguration-vpcendpointids"></a>
用于创建 Route53 IDs 别名的 REST API 的 VPC 终端节点列表。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway::RestApi``EndpointConfiguration`数据类型的`[VpcEndpointIds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-restapi-endpointconfiguration.html#cfn-apigateway-restapi-endpointconfiguration-vpcendpointids)`属性。

## 示例
<a name="sam-property-api-endpointconfiguration--examples"></a>

### EndpointConfiguration
<a name="sam-property-api-endpointconfiguration--examples--endpointconfiguration"></a>

端点配置示例

#### YAML
<a name="sam-property-api-endpointconfiguration--examples--endpointconfiguration--yaml"></a>

```
EndpointConfiguration:
  Type: PRIVATE
  VPCEndpointIds:
    - vpce-123a123a
    - vpce-321a321a
```

# AWS::Serverless::Application
<a name="sam-resource-application"></a>

将来自 [AWS Serverless Application Repository](https://serverlessrepo.aws.amazon.com/applications) 或来自 Amazon S3 存储桶的无服务器应用程序嵌入为嵌套应用程序。嵌套应用程序以嵌套 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudformation-stack.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudformation-stack.html) 资源形式部署，其中可以包含多个其他资源，包括其他 [AWS::Serverless::Application](#sam-resource-application) 资源。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-application-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-resource-application-syntax.yaml"></a>

```
Type: AWS::Serverless::Application
Properties:
  [Location](#sam-application-location): String | ApplicationLocationObject
  [NotificationARNs](#sam-application-notificationarns): List
  [Parameters](#sam-application-parameters): Map
  [Tags](#sam-application-tags): Map
  [TimeoutInMinutes](#sam-application-timeoutinminutes): Integer
```

## Properties
<a name="sam-resource-application-properties"></a>

 `Location`   <a name="sam-application-location"></a>
嵌套应用程序的模板 URL、文件路径或位置对象。  
如果提供了模板 URL，则它必须遵循[CloudFormation TemplateUrl 文档](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-templateurl)中指定的格式并包含有效的 CloudFormation 或 SAM 模板。可以使用 [ApplicationLocationObject](sam-property-application-applicationlocationobject.md) 指定已发布到 [AWS Serverless Application Repository](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html) 的应用程序。  
如果提供了本地文件路径，则模板必须经过包含 `sam deploy` 或 `sam package` 命令的工作流程，才能让应用程序正确转换。  
*类型*：字符串 \$1 [ApplicationLocationObject](sam-property-application-applicationlocationobject.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性类似于`AWS::CloudFormation::Stack`资源的`[TemplateURL](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-templateurl)`属性。该 CloudFormation 版本无需使用[ApplicationLocationObject](sam-property-application-applicationlocationobject.md)即可从中检索应用程序 AWS Serverless Application Repository。

 `NotificationARNs`   <a name="sam-application-notificationarns"></a>
向其发送堆栈事件通知的现有 Amazon SNS 主题的列表。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::CloudFormation::Stack`资源的`[NotificationARNs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-notificationarns)`属性。

 `Parameters`   <a name="sam-application-parameters"></a>
应用程序参数值。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::CloudFormation::Stack`资源的`[Parameters](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-parameters)`属性。

 `Tags`   <a name="sam-application-tags"></a>
指定要添加到此应用程序的标签的映射（字符串到字符串）。键和值只能包含字母数字字符。键的长度可以在 1 到 127 个 Unicode 字符之间，并且不能带有前缀“aws:”。值的长度可以在 1 到 255 个 Unicode 字符之间。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::CloudFormation::Stack`资源的`[Tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-tags)`属性。SAM 中的 Tags 属性由 Key: Value CloudFormation 对组成；其中包含标签对象的列表。创建堆栈后，SAM 将自动向该应用程序添加 `lambda:createdBy:SAM` 标签。此外，如果此应用程序来自 AWS Serverless Application Repository，那么 SAM 还将自动添加两个附加标签`serverlessrepo:applicationId:ApplicationId`和`serverlessrepo:semanticVersion:SemanticVersion`。

 `TimeoutInMinutes`   <a name="sam-application-timeoutinminutes"></a>
 CloudFormation 等待嵌套堆栈达到`CREATE_COMPLETE`状态的时间长度（以分钟为单位）。默认值为无超时。当 CloudFormation 检测到嵌套堆栈已达到`CREATE_COMPLETE`状态时，它会将嵌套堆栈资源标记为`CREATE_COMPLETE`在父堆栈中，并继续创建父堆栈。如果超时时间在嵌套堆栈到达之前到期`CREATE_COMPLETE`，则会将嵌套堆栈 CloudFormation 标记为失败并回滚嵌套堆栈和父堆栈。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::CloudFormation::Stack`资源的`[TimeoutInMinutes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html#cfn-cloudformation-stack-timeoutinminutes)`属性。

## 返回值
<a name="sam-resource-application-return-values"></a>

### Ref
<a name="sam-resource-application-return-values-ref"></a>

当向 `Ref` 内置函数提供此资源的逻辑 ID 时，将返回底层 `AWS::CloudFormation::Stack` 资源的资源名称。

有关使用 `Ref` 函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。

### Fn:: GetAtt
<a name="sam-resource-application-return-values-fn--getatt"></a>

`Fn::GetAtt` 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

有关使用 `Fn::GetAtt` 的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html)。

`Outputs.ApplicationOutputName`  <a name="Outputs.ApplicationOutputName-fn::getatt"></a>
带有名称 `ApplicationOutputName` 的堆栈输出的值。

## 示例
<a name="sam-resource-application--examples"></a>

### SAR 应用程序
<a name="sam-resource-application--examples--sar-application"></a>

使用来自无服务器应用程序存储库的模板的应用程序

#### YAML
<a name="sam-resource-application--examples--sar-application--yaml"></a>

```
Type: AWS::Serverless::Application
Properties:
  Location:
    ApplicationId: 'arn:aws:serverlessrepo:us-east-1:012345678901:applications/my-application'
    SemanticVersion: 1.0.0
  Parameters:
    StringParameter: parameter-value
    IntegerParameter: 2
```

### 正常应用
<a name="sam-resource-application--examples--normal-application"></a>

来自 S3 网址的应用程序

#### YAML
<a name="sam-resource-application--examples--normal-application--yaml"></a>

```
Type: AWS::Serverless::Application
Properties:
  Location: https://s3.amazonaws.com/sam-s3-demo-bucket/template.yaml
```

# ApplicationLocationObject
<a name="sam-property-application-applicationlocationobject"></a>

已发布到 [AWS Serverless Application Repository](https://docs.aws.amazon.com/serverlessrepo/latest/devguide/what-is-serverlessrepo.html) 的应用程序。

## 语法
<a name="sam-property-application-applicationlocationobject-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-application-applicationlocationobject-syntax.yaml"></a>

```
  [ApplicationId](#sam-application-applicationlocationobject-applicationid): String
  [SemanticVersion](#sam-application-applicationlocationobject-semanticversion): String
```

## Properties
<a name="sam-property-application-applicationlocationobject-properties"></a>

 `ApplicationId`   <a name="sam-application-applicationlocationobject-applicationid"></a>
应用程序的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SemanticVersion`   <a name="sam-application-applicationlocationobject-semanticversion"></a>
应用程序的语义版本。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-application-applicationlocationobject--examples"></a>

### my-application
<a name="sam-property-application-applicationlocationobject--examples--my-application"></a>

应用程序位置对象示例

#### YAML
<a name="sam-property-application-applicationlocationobject--examples--my-application--yaml"></a>

```
Location:
  ApplicationId: 'arn:aws:serverlessrepo:us-east-1:012345678901:applications/my-application'
  SemanticVersion: 1.0.0
```

# AWS::Serverless::CapacityProvider
<a name="sam-resource-capacityprovider"></a>

 为允许在客户拥有的 Amazon Elastic Compute Cloud 实例上运行 Lambda 托管实例的 AWS Lambda 函数创建容量提供程序。该资源是 Lambda 托管实例功能的一部分，该功能利用亚马逊定价模型为大规模 Lambda 工作负载提供成本优化。 EC2 

 容量提供商管理 Amazon EC2 实例的生命周期，并提供必要的基础设施，让 Lambda 函数在客户拥有的计算资源上执行，同时保持无服务器编程模型。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-capacityprovider-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-resource-capacityprovider-syntax.yaml"></a>

```
Type: AWS::Serverless::CapacityProvider
Properties:
  [CapacityProviderName](#sam-capacityprovider-capacityprovidername): String
  [VpcConfig](#sam-capacityprovider-vpcconfig): VpcConfig
  [OperatorRole](#sam-capacityprovider-operatorrole): String
  [Tags](#sam-capacityprovider-tags): Map
  [PropagateTags](#sam-capacityprovider-propagatetags): Boolean
  [InstanceRequirements](#sam-capacityprovider-instancerequirements): InstanceRequirements
  [ScalingConfig](#sam-capacityprovider-scalingconfig): ScalingConfig
  [KmsKeyArn](#sam-capacityprovider-kmskeyarn): String
```

## Properties
<a name="sam-resource-capacityprovider-properties"></a>

 `CapacityProviderName`   <a name="sam-capacityprovider-capacityprovidername"></a>
容量提供程序的名称。此名称在您的 AWS 账户和地区内必须是唯一的。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::CapacityProvider`资源的`[CapacityProviderName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-capacityprovidername)`属性。

 `VpcConfig`   <a name="sam-capacityprovider-vpcconfig"></a>
容量提供商的 VPC 配置。指定将在其中启动 Amazon EC2 实例的 VPC 子网和安全组。  
*类型*：[VpcConfig](sam-property-capacityprovider-vpcconfig.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::CapacityProvider`资源的`[VpcConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-vpcconfig)`属性。

 `OperatorRole`   <a name="sam-capacityprovider-operatorrole"></a>
 Lambda 操作员角色的 ARN，有权在客户账户中创建和管理 Amazon EC2 实例及相关资源。如果未提供，则会 AWS SAM 自动生成具有必要权限的角色。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`[PermissionsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-permissionsconfig)``AWS::Lambda::CapacityProvider`资源的`[CapacityProviderOperatorRoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-capacityproviderpermissionsconfig.html#cfn-lambda-capacityprovider-capacityproviderpermissionsconfig-capacityprovideroperatorrolearn)`属性。

 `Tags`   <a name="sam-capacityprovider-tags"></a>
应用于容量提供商及其关联资源的键值对映射。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::CapacityProvider`资源的`[Tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-tags)`属性。中的`Tags`属性由键值对 AWS SAM 组成（而 CloudFormation 在此属性中则由标签对象的列表组成）。此外，还 AWS SAM 会自动向此 Lambda 函数以及为此函数生成的默认角色添加`lambda:createdBy:SAM`标签。

 `PropagateTags`   <a name="sam-capacityprovider-propagatetags"></a>
 表示是否将标签从 Tags 属性传递到`AWS::Serverless::CapacityProvider`生成的资源。将其设置`True`为可在生成的资源中传播标签。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `InstanceRequirements`   <a name="sam-capacityprovider-instancerequirements"></a>
 容量提供商可以使用的计算实例类型的规范。这包括架构要求和 `allowed` /或`excluded`实例类型。  
*类型*：[InstanceRequirements](sam-property-capacityprovider-instancerequirements.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::CapacityProvider`资源的`[InstanceRequirements](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-instancerequirements)`属性。

 `ScalingConfig`   <a name="sam-capacityprovider-scalingconfig"></a>
 容量提供商的扩展配置。定义容量提供商如何根据需求扩展 Amazon EC2 实例。  
*类型*：[ScalingConfig](sam-property-capacityprovider-scalingconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::CapacityProvider`资源的`[CapacityProviderScalingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-capacityproviderscalingconfig)`属性。

 `KmsKeyArn`   <a name="sam-capacityprovider-kmskeyarn"></a>
用于为容量提供商加密静态数据和传输中数据的密 AWS KMS 钥的 ARN。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::CapacityProvider`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-kmskeyarn)`属性。

## 返回值
<a name="sam-resource-capacityprovider-return-values"></a>

### Ref
<a name="sam-resource-capacityprovider-return-values-ref"></a>

当向`Ref`内部函数提供此资源的逻辑 ID 时，它会返回容量提供者的名称。

有关使用 `Ref` 函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。

### Fn:: GetAtt
<a name="sam-resource-capacityprovider-return-values-fn--getatt"></a>

`Fn::GetAtt` 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

有关使用 `Fn::GetAtt` 的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html)。

`Arn`  <a name="Arn-fn::getatt"></a>
容量提供商的 ARN。

## 示例
<a name="sam-resource-capacityprovider-examples"></a>

### 基本容量提供商
<a name="sam-resource-capacityprovider-examples-basic"></a>

以下示例创建了一个具有 VPC 配置的基本容量提供商。

```
MyCapacityProvider:
  Type: AWS::Serverless::CapacityProvider
  Properties:
    CapacityProviderName: my-capacity-provider
    VpcConfig:
      SubnetIds:
        - subnet-12345678
        - subnet-87654321
      SecurityGroupIds:
        - sg-12345678
    Tags:
      Environment: Production
      Team: ServerlessTeam
```

### 具有扩展功能的高级容量提供商
<a name="sam-resource-capacityprovider-examples-advanced"></a>

以下示例创建了一个具有自定义实例要求和扩展配置的容量提供商。

```
AdvancedCapacityProvider:
  Type: AWS::Serverless::CapacityProvider
  Properties:
    CapacityProviderName: advanced-capacity-provider
    VpcConfig:
      SubnetIds:
        - subnet-12345678
        - subnet-87654321
      SecurityGroupIds:
        - sg-12345678
    OperatorRole: arn:aws:iam::123456789012:role/MyCapacityProviderRole
    PropagateTags: true
    InstanceRequirements:
      Architectures:
        - x86_64
      ExcludedTypes:
        - t2.micro
    ScalingConfig:
      MaxInstanceCount: 10
      ManualScalingPolicies:
        AverageCPUUtilization: 70.0
    KmsKeyArn: arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012
    Tags:
      Environment: Production
      CostCenter: Engineering
```

# VpcConfig
<a name="sam-property-capacityprovider-vpcconfig"></a>

为容量提供商配置 VPC 设置，包括将在其中 EC2 启动实例的子网和安全组。

## 语法
<a name="sam-property-capacityprovider-vpcconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-capacityprovider-vpcconfig-syntax.yaml"></a>

```
[SubnetIds](#sam-capacityprovider-vpcconfig-subnetids): List
[SecurityGroupIds](#sam-capacityprovider-vpcconfig-securitygroupids): List
```

## Properties
<a name="sam-property-capacityprovider-vpcconfig-properties"></a>

 `SubnetIds`   <a name="sam-capacityprovider-vpcconfig-subnetids"></a>
将在 IDs 其中启动 EC2 实例的子网列表。必须至少指定一个子网。  
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`[VpcConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-vpcconfig) ``AWS::Lambda::CapacityProvider`资源的`[SubnetIds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-capacityprovidervpcconfig.html#cfn-lambda-capacityprovider-capacityprovidervpcconfig-subnetids)`属性。

 `SecurityGroupIds`   <a name="sam-capacityprovider-vpcconfig-securitygroupids"></a>
 IDs 要与 EC2 实例关联的安全组列表。如果未指定，则将使用 VPC 的默认安全组。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::CapacityProvider`资源`[VpcConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-vpcconfig)`属性的属性。`[SecurityGroupIds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-capacityprovidervpcconfig.html#cfn-lambda-capacityprovider-capacityprovidervpcconfig-securitygroupids)`

## 示例
<a name="sam-property-capacityprovider-vpcconfig-examples"></a>

### VPC 配置
<a name="sam-property-capacityprovider-vpcconfig-examples-basic"></a>

以下示例显示了具有多个子网和安全组的 VPC 配置。

```
VpcConfig:
  SubnetIds:
    - subnet-12345678
    - subnet-87654321
  SecurityGroupIds:
    - sg-12345678
    - sg-87654321
```

# InstanceRequirements
<a name="sam-property-capacityprovider-instancerequirements"></a>

指定将由容量提供商启动的 EC2 实例的要求，包括架构和实例类型限制。

## 语法
<a name="sam-property-capacityprovider-instancerequirements-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-capacityprovider-instancerequirements-syntax.yaml"></a>

```
[Architectures](#sam-capacityprovider-instancerequirements-architectures): List
[AllowedTypes](#sam-capacityprovider-instancerequirements-allowedtypes): List
[ExcludedTypes](#sam-capacityprovider-instancerequirements-excludedtypes): List
```

**注意**  
您可以选择在为容量提供商定义实例要求`ExcludedTypes`时指定其中一个`AllowedTypes`或一个，但不能同时指定两者。

## Properties
<a name="sam-property-capacityprovider-instancerequirements-properties"></a>

 `Architectures`   <a name="sam-capacityprovider-instancerequirements-architectures"></a>
容量提供程序实例的指令集架构。  
*有效值*：`x86_64` 或 `arm64`  
*类型*：列表  
*必需*：否  
*默认值*：`x86_64`  
*CloudFormation 兼容性*：此属性直接传递给`[InstanceRequirements](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-instancerequirements)``AWS::Lambda::CapacityProvider`资源的`[Architectures](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-instancerequirements.html#cfn-lambda-capacityprovider-instancerequirements-architectures)`属性。

 `AllowedTypes`   <a name="sam-capacityprovider-instancerequirements-allowedtypes"></a>
容量提供程序 EC2 实例允许的实例类型列表。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`[InstanceRequirements](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-instancerequirements)``AWS::Lambda::CapacityProvider`资源的`[AllowedInstanceTypes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-instancerequirements.html#cfn-lambda-capacityprovider-instancerequirements-allowedinstancetypes)`属性。

 `ExcludedTypes`   <a name="sam-capacityprovider-instancerequirements-excludedtypes"></a>
要从容量提供程序中排除的 EC2 实例类型列表。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`[InstanceRequirements](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-instancerequirements)``AWS::Lambda::CapacityProvider`资源的`[ExcludedInstanceTypes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-instancerequirements.html#cfn-lambda-capacityprovider-instancerequirements-excludedinstancetypes)`属性。

## 示例
<a name="sam-property-capacityprovider-instancerequirements-examples"></a>

### 实例要求配置
<a name="sam-property-capacityprovider-instancerequirements-examples-basic"></a>

以下示例显示了具有特定架构和实例类型限制的实例要求。

```
InstanceRequirements:
  Architectures:
    - x86_64
  ExcludedTypes:
    - t2.micro
```

# ScalingConfig
<a name="sam-property-capacityprovider-scalingconfig"></a>

配置容量提供商如何根据需求扩展 EC2 实例，包括最大实例限制和扩展策略。

## 语法
<a name="sam-property-capacityprovider-scalingconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-capacityprovider-scalingconfig-syntax.yaml"></a>

```
[MaxVCpuCount](#sam-capacityprovider-scalingconfig-maxvcpucount): Integer
[AverageCPUUtilization](#sam-capacityprovider-scalingconfig-averagecpuutilization): Double
```

## Properties
<a name="sam-property-capacityprovider-scalingconfig-properties"></a>

 `MaxVCpuCount`   <a name="sam-capacityprovider-scalingconfig-maxvcpucount"></a>
容量提供者可以在所有计算实例中配置的最大 v CPUs 数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`[CapacityProviderScalingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-capacityproviderscalingconfig)``AWS::Lambda::CapacityProvider`资源的`[MaxVCpuCount](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-capacityproviderscalingconfig.html#cfn-lambda-capacityprovider-capacityproviderscalingconfig-maxvcpucount)`属性。

 `AverageCPUUtilization`   <a name="sam-capacityprovider-scalingconfig-averagecpuutilization"></a>
扩展决策的目标平均 CPU 利用率百分比 (0-100)。当平均 CPU 使用率超过此阈值时，容量提供商将扩展 Amazon EC2 实例。指定后， AWS SAM 将`[CapacityProviderScalingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html#cfn-lambda-capacityprovider-capacityproviderscalingconfig)`构造设置为、`[ScalingMode](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-capacityproviderscalingconfig.html#cfn-lambda-capacityprovider-capacityproviderscalingconfig-scalingmode)`设置为`'Manual'`的`AWS::Lambda::CapacityProvider``[ScalingPolicies](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-capacityprovider-capacityproviderscalingconfig.html#cfn-lambda-capacityprovider-capacityproviderscalingconfig-scalingpolicies)`资源。`[{PredefinedMetricType: 'LambdaCapacityProviderAverageCPUUtilization', TargetValue: <this value>}]`  
*类型*：双精度  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-capacityprovider-scalingconfig-examples"></a>

### 扩展配置
<a name="sam-property-capacityprovider-scalingconfig-examples-basic"></a>

以下示例显示了具有最大 VCpu 计数和平均 CPU 利用率的扩展配置。

```
ScalingConfig:
  MaxVCpuCount: 10
  AverageCPUUtilization: 70.0
```

# AWS::Serverless::Connector
<a name="sam-resource-connector"></a>

配置两种资源之间的权限。有关连接器的简介，请参阅[使用 AWS SAM 连接器管理资源权限](managing-permissions-connectors.md)。

有关生成的 AWS CloudFormation 资源的更多信息，请参阅[CloudFormation 指定时生成的资源 AWS::Serverless::Connector](sam-specification-generated-resources-connector.md)。

要提供有关连接器的反馈，[请在*serverless-application-model AWS GitHub 存储库*中提交新问题](https://github.com/aws/serverless-application-model/issues/new?assignees=&labels=area%2Fconnectors,stage%2Fneeds-triage&template=other.md&title=%28Feature%20Request%29)。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-connector-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下任一语法。

**注意**  
对于大多数用例，我们建议使用嵌入式连接器语法。随着时间的推移，嵌入在源资源中使其更易于读取和维护。当您需要引用不在同一 AWS SAM 模板中的源资源（例如嵌套堆栈中的资源或共享资源）时，请使用`AWS::Serverless::Connector`语法。

### 嵌入式连接器
<a name="sam-resource-connector-syntax-embedded"></a>

```
<source-resource-logical-id>:
  Connectors:
    <connector-logical-id:
      Properties:
        [Destination](#sam-connector-destination): ResourceReference | List of ResourceReference
        [Permissions](#sam-connector-permissions): List
        [SourceReference](#sam-connector-sourcereference): SourceReference
```

### AWS::Serverless::Connector
<a name="sam-resource-connector-syntax-connector"></a>

```
Type: AWS::Serverless::Connector
Properties:
  [Destination](#sam-connector-destination): ResourceReference | List of ResourceReference
  [Permissions](#sam-connector-permissions): List
  [Source](#sam-connector-source): ResourceReference
```

## Properties
<a name="sam-resource-connector-properties"></a>

 `Destination`   <a name="sam-connector-destination"></a>
目标资源。  
*类型*:[ResourceReference](sam-property-connector-resourcereference.md)\$1 清单 [ResourceReference](sam-property-connector-resourcereference.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Permissions`   <a name="sam-connector-permissions"></a>
允许源资源对目标资源执行的权限类型。  
`Read`包括允许从资源中读取数据的 AWS Identity and Access Management (IAM) 操作。  
`Write` 包括允许初始化和向资源写入数据的 IAM 操作。  
*有效值*：`Read` 或 `Write`  
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Source`   <a name="sam-connector-source"></a>
源资源。使用 `AWS::Serverless::Connector` 语法时为必需。  
*类型*：[ResourceReference](sam-property-connector-resourcereference.md)  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceReference`   <a name="sam-connector-sourcereference"></a>
源资源。  
为源资源定义其他属性时，使用嵌入式连接器语法。
*类型*：[SourceReference](sam-property-connector-sourcereference.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-resource-connector-examples"></a>

### 嵌入式连接器
<a name="sam-resource-connector-examples-embedded"></a>

以下示例使用嵌入式连接器定义 AWS Lambda 函数和 Amazon DynamoDB 表之间的 `Write` 数据连接：

```
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyTable:
    Type: AWS::Serverless::SimpleTable
  MyFunction:
    Type: AWS::Serverless::Function
    Connectors:
      MyConn:
        Properties:
          Destination:
            Id: MyTable
          Permissions:
            - Write
    ...
```

以下示例使用嵌入式连接器定义 `Read` 和 `Write` 权限：

```
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Connectors:
      MyConn:
        Properties:
          Destination:
            Id: MyTable
          Permissions:
            - Read
            - Write
  MyTable:
    Type: AWS::DynamoDB::Table
    ...
```

以下示例使用嵌入式连接器定义具有 `Id` 以外属性的源资源：

```
Transform: AWS::Serverless-2016-10-31
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Connectors:
      ApitoLambdaConn:
        Properties:
          SourceReference:
            Qualifier: Prod/GET/foobar
          Destination:
            Id: MyTable
          Permissions:
            - Read
            - Write
  MyTable:
    Type: AWS::DynamoDB::Table
    ...
```

### AWS::Serverless::Connector
<a name="sam-resource-connector--examples-connector"></a>

以下示例使用该[AWS::Serverless::Connector](#sam-resource-connector)资源对一个 AWS Lambda 函数 Amazon DynamoDB 表进行读取和写入：

```
MyConnector:
  Type: AWS::Serverless::Connector
  Properties:
    Source:
      Id: MyFunction
    Destination:
      Id: MyTable
    Permissions:
      - Read
      - Write
```

以下示例使用 [AWS::Serverless::Connector](#sam-resource-connector) 资源让 Lambda 函数写入 Amazon SNS 主题，两个资源位于同一个模板中：

```
MyConnector:
  Type: AWS::Serverless::Connector
  Properties:
    Source:
      Id: MyLambda
    Destination:
      Id: MySNSTopic
    Permissions:
      - Write
```

以下示例使用 [AWS::Serverless::Connector](#sam-resource-connector) 资源让 Amazon SNS 主题写入 Lambda 函数，然后该函数写入 Amazon DynamoDB 表，所有资源都位于同一个模板中：

```
Transform: AWS::Serverless-2016-10-31
Resources:
  Topic:
    Type: AWS::SNS::Topic
    Properties:
      Subscription:
        - Endpoint: !GetAtt Function.Arn
          Protocol: lambda

  Function:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs16.x
      Handler: index.handler
      InlineCode: |
        const AWS = require('aws-sdk');
        exports.handler = async (event, context) => {
          const docClient = new AWS.DynamoDB.DocumentClient();
          await docClient.put({ 
            TableName: process.env.TABLE_NAME, 
            Item: {
              id: context.awsRequestId,
              event: JSON.stringify(event)
            }
          }).promise();
        };
      Environment:
        Variables:
          TABLE_NAME: !Ref Table

  Table:
    Type: AWS::Serverless::SimpleTable

  TopicToFunctionConnector:
    Type: AWS::Serverless::Connector
    Properties:
      Source: 
        Id: Topic
      Destination: 
        Id: Function
      Permissions:
        - Write

  FunctionToTableConnector:
    Type: AWS::Serverless::Connector
    Properties:
      Source: 
        Id: Function
      Destination: 
        Id: Table
      Permissions:
        - Write
```

以下是上面示例中转换后的 AWS CloudFormation 模板：

```
"FunctionToTableConnectorPolicy": {
  "Type": "AWS::IAM::ManagedPolicy",
  "Metadata": {
    "aws:sam:connectors": {
      "FunctionToTableConnector": {
        "Source": {
          "Type": "AWS::Lambda::Function"
        },
        "Destination": {
          "Type": "AWS::DynamoDB::Table"
        }
      }
    }
  },
  "Properties": {
    "PolicyDocument": {
      "Version": "2012-10-17",		 	 	 
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "dynamodb:PutItem",
            "dynamodb:UpdateItem",
            "dynamodb:DeleteItem",
            "dynamodb:BatchWriteItem",
            "dynamodb:PartiQLDelete",
            "dynamodb:PartiQLInsert",
            "dynamodb:PartiQLUpdate"
          ],
          "Resource": [
            {
              "Fn::GetAtt": [
                "MyTable",
                "Arn"
              ]
            },
            {
              "Fn::Sub": [
                "${DestinationArn}/index/*",
                {
                  "DestinationArn": {
                    "Fn::GetAtt": [
                      "MyTable",
                      "Arn"
                    ]
                  }
                }
              ]
            }
          ]
        }
      ]
    },
    "Roles": [
      {
        "Ref": "MyFunctionRole"
      }
    ]
  }
}
```

# ResourceReference
<a name="sam-property-connector-resourcereference"></a>

对 [AWS::Serverless::Connector](sam-resource-connector.md) 资源类型使用的资源的引用。

**注意**  
对于同一模板中的资源，请提供 `Id`。对于不在同一模板中的资源，请使用其他属性的组合。有关更多信息，请参阅 [AWS SAM 连接器参考](reference-sam-connector.md)。

## 语法
<a name="sam-property-connector-resourcereference-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-connector-resourcereference-syntax.yaml"></a>

```
  [Arn](#sam-connector-resourcereference-arn): String
  [Id](#sam-connector-resourcereference-id): String
  [Name](#sam-connector-resourcereference-name): String
  [Qualifier](#sam-connector-resourcereference-qualifier): String
  [QueueUrl](#sam-connector-resourcereference-queueurl): String
  [ResourceId](#sam-connector-resourcereference-resourceid): String
  [RoleName](#sam-connector-resourcereference-rolename): String
  [Type](#sam-connector-resourcereference-type): String
```

## Properties
<a name="sam-property-connector-resourcereference-properties"></a>

 `Arn`   <a name="sam-connector-resourcereference-arn"></a>
资源的 ARN。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Id`   <a name="sam-connector-resourcereference-id"></a>
同一模板中资源的[逻辑 ID](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html)。  
指定后`Id`，如果连接器生成 AWS Identity and Access Management (IAM) 策略，则将从资源`Id`中推断出与这些策略关联的 IAM 角色。如果 `Id` 未指定，则为连接器提供资源 `RoleName`，以便将生成的 IAM 策略附加到 IAM 角色。
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Name`   <a name="sam-connector-resourcereference-name"></a>
资源的名称。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Qualifier`   <a name="sam-connector-resourcereference-qualifier"></a>
缩小其范围的资源限定符。`Qualifier` 替换资源约束 ARN 末尾的 `*` 值。有关示例，请参阅[API Gateway 调用 Lambda 函数](#sam-property-connector-resourcereference--examples--api-gateway-invoking-a-lambda-function)。  
限定符定义因资源类型而异。有关受支持的源资源和目的地资源类型的列表，请参阅 [AWS SAM 连接器参考](reference-sam-connector.md)。
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `QueueUrl`   <a name="sam-connector-resourcereference-queueurl"></a>
Amazon SQS 队列 URL。此属性仅适用于 Amazon SQS 资源。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ResourceId`   <a name="sam-connector-resourcereference-resourceid"></a>
资源的 ID。例如，API Gateway API ID。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `RoleName`   <a name="sam-connector-resourcereference-rolename"></a>
与资源关联的角色名称。  
指定 `Id` 后，如果连接器生成 IAM 策略，则将从资源 `Id` 中推断出与这些策略关联的 IAM 角色。如果 `Id` 未指定，则为连接器提供资源 `RoleName`，以便将生成的 IAM 策略附加到 IAM 角色。
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Type`   <a name="sam-connector-resourcereference-type"></a>
资源的 CloudFormation 类型。有关更多信息，请参阅[AWS 资源和属性类型参考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html)。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-connector-resourcereference--examples"></a>

### API Gateway 调用 Lambda 函数
<a name="sam-property-connector-resourcereference--examples--api-gateway-invoking-a-lambda-function"></a>

以下示例使用该[AWS::Serverless::Connector](sam-resource-connector.md)资源允许 Amazon API Gateway 调用 AWS Lambda 函数。

#### YAML
<a name="sam-property-connector-resourcereference--examples--api-gateway-invoking-a-lambda-function--yaml"></a>

```
Transform: AWS::Serverless-2016-10-31
Resources:
  MyRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Statement:
          - Effect: Allow
            Action: sts:AssumeRole
            Principal:
              Service: lambda.amazonaws.com
      ManagedPolicyArns:
        - !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole

  MyFunction:
    Type: AWS::Lambda::Function
    Properties:
      Role: !GetAtt MyRole.Arn
      Runtime: nodejs16.x
      Handler: index.handler
      Code:
        ZipFile: |
          exports.handler = async (event) => {
            return {
              statusCode: 200,
              body: JSON.stringify({
                "message": "It works!"
              }),
            };
          };

  MyApi:
    Type: AWS::ApiGatewayV2::Api
    Properties:
      Name: MyApi
      ProtocolType: HTTP

  MyStage:
    Type: AWS::ApiGatewayV2::Stage
    Properties:
      ApiId: !Ref MyApi
      StageName: prod
      AutoDeploy: True

  MyIntegration:
    Type: AWS::ApiGatewayV2::Integration
    Properties:
      ApiId: !Ref MyApi
      IntegrationType: AWS_PROXY
      IntegrationUri: !Sub arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations
      IntegrationMethod: POST
      PayloadFormatVersion: "2.0"

  MyRoute:
    Type: AWS::ApiGatewayV2::Route
    Properties:
      ApiId: !Ref MyApi
      RouteKey: GET /hello
      Target: !Sub integrations/${MyIntegration}

  MyConnector:
    Type: AWS::Serverless::Connector
    Properties:
      Source: # Use 'Id' when resource is in the same template
        Type: AWS::ApiGatewayV2::Api
        ResourceId: !Ref MyApi
        Qualifier: prod/GET/hello # Or "*" to allow all routes
      Destination: # Use 'Id' when resource is in the same template
        Type: AWS::Lambda::Function
        Arn: !GetAtt MyFunction.Arn
      Permissions:
        - Write

Outputs:
  Endpoint:
    Value: !Sub https://${MyApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/prod/hello
```

# SourceReference
<a name="sam-property-connector-sourcereference"></a>

对 [AWS::Serverless::Connector](sam-resource-connector.md) 资源类型使用的源资源的引用。

## 语法
<a name="sam-property-connector-sourcereference-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-connector-sourcereference-syntax.yaml"></a>

```
[Qualifier](#sam-connector-sourcereference-qualifier): String
```

## Properties
<a name="sam-property-connector-sourcereference-properties"></a>

 `Qualifier`   <a name="sam-connector-sourcereference-qualifier"></a>
缩小其范围的资源限定符。`Qualifier` 替换资源约束 ARN 末尾的 `*` 值。  
限定符定义因资源类型而异。有关受支持的源资源和目的地资源类型的列表，请参阅 [AWS SAM 连接器参考](reference-sam-connector.md)。
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-connector-sourcereference--examples"></a>

**以下示例使用嵌入式连接器定义具有 `Id` 以外属性的源资源：**

```
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Connectors:
      ApitoLambdaConn:
        Properties:
          SourceReference:
            Qualifier: Prod/GET/foobar
          Destination:
            Id: MyTable
          Permissions:
            - Read
            - Write
  MyTable:
    Type: AWS::DynamoDB::Table
    ...
```

# AWS::Serverless::Function
<a name="sam-resource-function"></a>

创建触发该 AWS Lambda 函数的函数、 AWS Identity and Access Management (IAM) 执行角色和事件源映射。

该[AWS::Serverless::Function](#sam-resource-function)资源还支持 r `Metadata` esource 属性，因此您可以指示 AWS SAM 构建应用程序所需的自定义运行时。有关构建自定义运行时系统的更多信息，请参阅 [在中使用自定义运行时构建 Lambda 函数 AWS SAM](building-custom-runtimes.md)。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-function-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-resource-function-syntax.yaml"></a>

```
Type: AWS::Serverless::Function
Properties:
  [Architectures](#sam-function-architectures): List
  [AssumeRolePolicyDocument](#sam-function-assumerolepolicydocument): JSON
  [AutoPublishAlias](#sam-function-autopublishalias): String
  AutoPublishAliasAllProperties: Boolean
  [AutoPublishCodeSha256](#sam-function-autopublishcodesha256): String
  [CapacityProviderConfig](#sam-function-capacityproviderconfig): CapacityProviderConfig
  [CodeSigningConfigArn](#sam-function-codesigningconfigarn): String
  [CodeUri](#sam-function-codeuri): String | FunctionCode
  [DeadLetterQueue](#sam-function-deadletterqueue): Map | DeadLetterQueue
  [DeploymentPreference](#sam-function-deploymentpreference): DeploymentPreference
  [Description](#sam-function-description): String
  [DurableConfig](#sam-function-durableconfig): DurableConfig
  [Environment](#sam-function-environment): [Environment](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html)
  [EphemeralStorage](#sam-function-ephemeralstorage): [EphemeralStorage](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-ephemeralstorage)
  [EventInvokeConfig](#sam-function-eventinvokeconfig): EventInvokeConfiguration
  [Events](#sam-function-events): EventSource
  [FileSystemConfigs](#sam-function-filesystemconfigs): List
  [FunctionName](#sam-function-functionname): String
  [FunctionScalingConfig](#sam-function-functionscalingconfig): FunctionScalingConfig
  [FunctionUrlConfig](#sam-function-functionurlconfig): FunctionUrlConfig
  [Handler](#sam-function-handler): String
  [ImageConfig](#sam-function-imageconfig): [ImageConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-imageconfig)
  [ImageUri](#sam-function-imageuri): String
  [InlineCode](#sam-function-inlinecode): String
  [KmsKeyArn](#sam-function-kmskeyarn): String
  [Layers](#sam-function-layers): List
  LoggingConfig: [LoggingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-loggingconfig.html)
  [MemorySize](#sam-function-memorysize): Integer
  [PackageType](#sam-function-packagetype): String
  [PermissionsBoundary](#sam-function-permissionsboundary): String
  [Policies](#sam-function-policies): String | List | Map
  [PublishToLatestPublished](#sam-function-publishtolatestpublished): Boolean
  PropagateTags: Boolean
  [ProvisionedConcurrencyConfig](#sam-function-provisionedconcurrencyconfig): [ProvisionedConcurrencyConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig)
  RecursiveLoop: String
  [ReservedConcurrentExecutions](#sam-function-reservedconcurrentexecutions): Integer
  [Role](#sam-function-role): String
  [RolePath](#sam-function-rolepath): String
  [Runtime](#sam-function-runtime): String
  RuntimeManagementConfig: [RuntimeManagementConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-runtimemanagementconfig.html)
  SnapStart: [SnapStart](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html)
  [SourceKMSKeyArn](#sam-function-sourcekmskeyarn): String
  [Tags](#sam-function-tags): Map
  [TenancyConfig](#sam-function-tenancyconfig): TenancyConfig
  [Timeout](#sam-function-timeout): Integer
  [Tracing](#sam-function-tracing): String
  [VersionDescription](#sam-function-versiondescription): String
  [VersionDeletionPolicy](#sam-function-versiondeletionpolicy): String
  [VpcConfig](#sam-function-vpcconfig): [VpcConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-vpcconfig.html)
```

## Properties
<a name="sam-resource-function-properties"></a>

 `Architectures`   <a name="sam-function-architectures"></a>
该函数的指令集架构。  
有关此属性更多信息，请参阅*《AWS Lambda 开发人员指南》*中的 [Lambda 指令集架构](https://docs.aws.amazon.com/lambda/latest/dg/foundation-arch.html)。  
*有效值*：`x86_64` 或 `arm64` 之一。  
*类型*：列表  
*必需*：否  
*默认值*：`x86_64`  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[Architectures](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-architectures)`属性。

 `AssumeRolePolicyDocument`   <a name="sam-function-assumerolepolicydocument"></a>
 AssumeRolePolicyDocument 为该函数创建`Role`的默认值添加一个。如果未指定此属性，则为该函数 AWS SAM 添加默认的代入角色。  
*类型*：JSON  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::IAM::Role`资源的`[AssumeRolePolicyDocument](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-assumerolepolicydocument)`属性。 AWS SAM 将此属性添加到为此函数生成的 IAM 角色中。如果为此函数提供了角色的 Amazon 资源名称（ARN），则此属性将不执行任何操作。

 `AutoPublishAlias`   <a name="sam-function-autopublishalias"></a>
Lambda 别名的名称。要了解有关 Lambda 别名的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的 [Lambda 函数别名](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html)。有关使用此属性的示例，请参见 [使用以下方法逐步部署无服务器应用程序 AWS SAM](automating-updates-to-serverless-apps.md)。  
AWS SAM 设置此属性时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-version.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-version.html)和[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html)资源。有关此场景的更多信息，请参阅[AutoPublishAlias 属性已指定](sam-specification-generated-resources-function.md#sam-specification-generated-resources-function-autopublishalias)。有关生成的 CloudFormation 资源的一般信息，请参阅[生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AutoPublishAliasAllProperties`   <a name="sam-function-autopublishaliasallproperties"></a>
指定何时创建新的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-version.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-version.html)。当为 `true` 时，修改 Lambda 函数中的任何属性时，就会创建新的 Lambda 版本。当为 `false` 时，只有修改了以下任何属性时，才会创建新的 Lambda 版本：  
+ `Environment`、`MemorySize` 或者 `SnapStart`。
+ 导致 `Code` 属性更新的任何更改，例如 `CodeDict`、`ImageUri`、或 `InlineCode`。
此属性需要定义 `AutoPublishAlias`。  
如果也指定 `AutoPublishCodeSha256`，则其行为优先于 `AutoPublishAliasAllProperties: true`。  
*类型*：布尔值  
*必需*：否  
*默认值*：`false`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AutoPublishCodeSha256`   <a name="sam-function-autopublishcodesha256"></a>
使用时，此字符串将与 `CodeUri` 值一起确定是否需要发布新的 Lambda 版本。此属性通常用于解决以下部署问题：部署包存储在 Amazon S3 位置，且被包含更新后的 Lambda 函数代码的新部署包取代，但 `CodeUri` 属性保持不变（相反情况是新的部署包上传到新的 Amazon S3 位置并且 `CodeUri` 更改为新位置）。  
此问题由具有以下特征的 AWS SAM 模板标记：  
+ `DeploymentPreference` 对象配置为逐步部署（如[使用以下方法逐步部署无服务器应用程序 AWS SAM](automating-updates-to-serverless-apps.md)中所述）
+ `AutoPublishAlias` 属性已设置，且在部署之间不会更改
+ `CodeUri` 属性已设置，且在部署之间不会更改。
在这种情况下，更新 `AutoPublishCodeSha256` 会导致成功创建新的 Lambda 版本。但是，部署到 Amazon S3 的新函数代码将无法识别。要识别新的函数代码，请考虑在 Amazon S3 存储桶中使用版本控制。为 Lambda 函数指定 `Version` 属性，并将存储桶配置为始终使用最新的部署包。  
在这种情况下，要成功触发逐步部署，必须为 `AutoPublishCodeSha256` 提供一个唯一的值。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `CapacityProviderConfig`   <a name="sam-function-capacityproviderconfig"></a>
配置要将函数的已发布版本附加到的容量提供商。这使该函数能够在由 Lambda 托管实例管理的客户拥有的 EC2 实例上运行。  
*类型*：[CapacityProviderConfig](sam-property-function-capacityproviderconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：SAM 对传递给`AWS::Lambda::Function`资源属性的`[CapacityProviderConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-capacityproviderconfig)`属性进行扁平化并重建嵌套结构。

 `CodeSigningConfigArn`   <a name="sam-function-codesigningconfigarn"></a>
[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-codesigningconfig.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-codesigningconfig.html) 资源的 ARN，用于为此函数启用代码签名。有关代码签名的更多信息，请参阅 [为您的 AWS SAM 应用程序设置代码签名](authoring-codesigning.md)。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[CodeSigningConfigArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-codesigningconfigarn)`属性。

 `CodeUri`   <a name="sam-function-codeuri"></a>
函数的代码。可接受的值包括：  
+ 该函数的 Amazon S3 URI。例如 `s3://bucket-123456789/sam-app/1234567890abcdefg`。
+ 函数的本地路径。例如 `hello_world/`。
+ 一个 [FunctionCode](sam-property-function-functioncode.md) 对象。
如果您提供函数的 Amazon S3 URI 或 [FunctionCode](sam-property-function-functioncode.md) 对象，则必须引用有效的 [Lambda 部署包](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html)。  
如果您提供本地文件路径，请在部署时使用 AWS SAM CLI 上传本地文件。要了解更多信息，请参阅[如何在 AWS SAM 部署时上传本地文件](deploy-upload-local-files.md)。  
如果你在`CodeUri`属性中使用内部函数， AWS SAM 将无法正确解析这些值。请考虑改用[AWS::Language扩展程序转换](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-aws-languageextensions.html)。
*类型*：[ 字符串 \$1 [FunctionCode](sam-property-function-functioncode.md) ]  
*必填*：条件性。当 `PackageType` 设置为 `Zip` 时，则 `CodeUri` 或 `InlineCode` 中的一种为必需。  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::Function`资源的`[ Code](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-code)`属性。嵌套的 Amazon S3 属性的命名有所不同。

 `DeadLetterQueue`   <a name="sam-function-deadletterqueue"></a>
在 Lambda 发送无法处理的事件时配置 Amazon Simple Notiﬁcation Service (Amazon SNS)主题或 Amazon Simple Queue Service (Amazon SQS) 队列。有关死信队列功能的更多信息，请参阅《AWS Lambda 开发人员指南》**中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async-retain-records.html#invocation-dlq)。  
如果您的 Lambda 函数的事件源是 Amazon SQS 队列，请为源队列而不是 Lambda 函数配置死信队列。您为函数配置的死信队列用于函数的[异步调用队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html)，而不是用于事件源队列。
*类型*：地图 \$1 [DeadLetterQueue](sam-property-function-deadletterqueue.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::Function`资源的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-deadletterconfig.html)`属性。在 CloudFormation 中，类型是派生自的`TargetArn`，而在中， AWS SAM 你必须将类型与一起传递`TargetArn`。

 `DeploymentPreference`   <a name="sam-function-deploymentpreference"></a>
用于启用逐步 Lambda 部署的设置。  
如果指定了`DeploymentPreference`对象，则 AWS SAM 会创建一个[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-application.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-application.html)被调用对象`ServerlessDeploymentApplication`（每个堆栈一个）、一个[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-deploymentgroup.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-deploymentgroup.html)被调用`<function-logical-id>DeploymentGroup`对象和一个[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html)被调用对象`CodeDeployServiceRole`。  
*类型*：[DeploymentPreference](sam-property-function-deploymentpreference.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*另请参阅*：有关此属性的更多信息，请参阅 [使用以下方法逐步部署无服务器应用程序 AWS SAM](automating-updates-to-serverless-apps.md)。

 `Description`   <a name="sam-function-description"></a>
该函数的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-description)`属性。

 `DurableConfig`   <a name="sam-function-durableconfig"></a>
耐用功能的配置。通过自动检查点和重播功能启用有状态执行。  
*类型*：[DurableConfig](sam-property-function-durableconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Environment`   <a name="sam-function-environment"></a>
运行时系统环境的配置。  
*类型*：[环境](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[Environment](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-environment.html)`属性。

 `EphemeralStorage`   <a name="sam-function-ephemeralstorage"></a>
指定 `/tmp` 中 Lambda 函数可用的磁盘空间（以 MB 为单位）的对象。  
有关此属性的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的 [Lambda 执行环境](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html)。  
*类型*：[EphemeralStorage](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-ephemeralstorage)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[EphemeralStorage](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-ephemeralstorage)`属性。

 `EventInvokeConfig`   <a name="sam-function-eventinvokeconfig"></a>
描述 Lambda 函数的事件调用配置的对象。  
*类型*：[EventInvokeConfiguration](sam-property-function-eventinvokeconfiguration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Events`   <a name="sam-function-events"></a>
指定触发此函数的事件。事件由一个类型和一组依赖于该类型的属性组成。  
*类型*：[EventSource](sam-property-function-eventsource.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FileSystemConfigs`   <a name="sam-function-filesystemconfigs"></a>
指定亚马逊弹性文件系统 (Amazon EFS) 文件系统的连接设置的[FileSystemConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-filesystemconfig.html)对象列表。  
如果模板包含 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-mounttarget.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-efs-mounttarget.html) 资源，您还必须指定一个 `DependsOn` 资源属性，以确保在函数之前创建或更新装载目标。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[FileSystemConfigs](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-filesystemconfigs)`属性。

 `FunctionName`   <a name="sam-function-functionname"></a>
函数的名称。如果您没有指定名称，则系统为您生成唯一的名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[FunctionName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-functionname)`属性。

 `FunctionScalingConfig`   <a name="sam-function-functionscalingconfig"></a>
为在容量提供程序上运行的 Lambda 函数配置扩展行为。定义执行环境的最小和最大数量。  
*类型*：[FunctionScalingConfig](sam-property-function-functionscalingconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[FunctionScalingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-functionscalingconfig)`属性。

 `FunctionUrlConfig`   <a name="sam-function-functionurlconfig"></a>
描述函数 URL 的对象。函数 URL 是可用于调用函数的 HTTPS 端点。  
有关更多信息，请参阅《*AWS Lambda 开发者指南*》URLs中的[函数](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html)。  
*类型*：[FunctionUrlConfig](sam-property-function-functionurlconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Handler`   <a name="sam-function-handler"></a>
代码中被调用以开始执行的函数。仅当属性 `PackageType` 为 `Zip` 时，该属性是必需属性。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[Handler](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-handler)`属性。

 `ImageConfig`   <a name="sam-function-imageconfig"></a>
用于配置 Lambda 容器映像设置的对象。有关更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[将容器映像与 Lambda 结合使用](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html)。  
*类型*：[ImageConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-imageconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[ImageConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-imageconfig)`属性。

 `ImageUri`   <a name="sam-function-imageuri"></a>
Lambda 函数容器映像的 Amazon Elastic Container Registry (Amazon ECR) 存储库 URI 仅当 `PackageType` 属性设置为 `Image` 时，此属性才适用，否则将被忽略。有关更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[将容器映像与 Lambda 结合使用](https://docs.aws.amazon.com/lambda/latest/dg/lambda-images.html)。  
如果将该`PackageType`属性设置为`Image`，`ImageUri`则要么为必填项，要么必须使用 AWS SAM 模板文件中的必要`Metadata`条目来构建应用程序。有关更多信息，请参阅 [默认版本使用 AWS SAM](serverless-sam-cli-using-build.md)。
使用必要的 `Metadata` 条目构建应用程序优先于 `ImageUri`，因此，如果您同时指定两者，则 `ImageUri` 会被忽略。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``Code`数据类型的`[ImageUri](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-imageuri)`属性。

 `InlineCode`   <a name="sam-function-inlinecode"></a>
直接在模板中编写的 Lambda 函数代码。仅当 `PackageType` 属性设置为 `Zip` 时，此属性才适用，否则将被忽略。  
如果 `PackageType` 属性设置为 `Zip`（默认），则 `CodeUri` 或 `InlineCode` 中的一个为必需。
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``Code`数据类型的`[ZipFile](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-zipfile)`属性。

 `KmsKeyArn`   <a name="sam-function-kmskeyarn"></a>
Lambda 用来加密和解密函数环境变量的 AWS Key Management Service (AWS KMS) 密钥的 ARN。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-kmskeyarn)`属性。

 `Layers`   <a name="sam-function-layers"></a>
此函数应使用的列表。`LayerVersion` ARNs 此处指定的顺序是运行 Lambda 函数时它们的导入顺序。该版本要么是包含版本的完整 ARN，要么是对资源的引用。 LayerVersion 例如，对 `LayerVersion` 的引用为 `!Ref MyLayer`，而包含版本号的完整 ARN 为 `arn:aws:lambda:region:account-id:layer:layer-name:version`。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[Layers](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-layers)`属性。

 `LoggingConfig`   <a name="sam-function-loggingconfig"></a>
该函数的 Amazon CloudWatch 日志配置设置。  
*类型*：[LoggingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-loggingconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-loggingconfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-loggingconfig)属性。

 `MemorySize`   <a name="sam-function-memorysize"></a>
每次调用函数时分配的内存大小（以 MB 为单位）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[MemorySize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-memorysize)`属性。

 `PackageType`   <a name="sam-function-packagetype"></a>
Lambda 函数的部署包类型。有关更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[Lambda 部署包](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-package.html)。  
**备注**：  
1. 如果此属性设置为 `Zip`（默认），则将应用 `CodeUri` 或 `InlineCode`，并忽略 `ImageUri`。  
2. 如果此属性设置为 `Image`，则仅应用 `ImageUri`，并忽略 `CodeUri` 和 `InlineCode`。存储函数容器镜像所需的 Amazon ECR 存储库可以由自动创建。 AWS SAMCLI有关更多信息，请参阅 [sam deploy](sam-cli-command-reference-sam-deploy.md)。  
*有效值*：`Zip` 或 `Image`  
*类型*：字符串  
*必需*：否  
*默认值*：`Zip`  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[PackageType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-packagetype)`属性。

 `PermissionsBoundary`   <a name="sam-function-permissionsboundary"></a>
用于此函数执行角色的权限边界的 ARN。仅当为您生成角色时，此属性才起作用。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IAM::Role`资源的`[PermissionsBoundary](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-permissionsboundary)`属性。

 `Policies`   <a name="sam-function-policies"></a>
此函数的权限策略。策略将附加到函数的默认 AWS Identity and Access Management (IAM) 执行角色中。  
此属性接受单个值或值列表。允许的值包括：  
+ [AWS SAM策略模板](serverless-policy-templates.md).
+ [AWS 托管策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#aws-managed-policies)或[客户管理型策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#customer-managed-policies)的 ARN。
+ 以下[列表](https://github.com/aws/serverless-application-model/blob/develop/samtranslator/internal/data/aws_managed_policies.json)中 AWS 托管策略的名称。
+ 在 YAML 中格式化为映射的[内联 IAM policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#inline-policies)。
如果指定 `Role` 属性，则将忽略该属性。
*类型*：字符串 \$1 列表 \$1 映射  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::IAM::Role`资源的`[Policies](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-policies)`属性。

 `PublishToLatestPublished`   <a name="sam-function-publishtolatestpublished"></a>
指定在函数更新时是否发布最新的函数版本。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[PublishToLatestPublished](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-publishtolatestpublished)`属性。

`PropagateTags`  <a name="sam-function-propagatetags"></a>
指明是否将 `Tags` 属性中的标签传递给 [AWS::Serverless::Function](sam-specification-generated-resources-function.md) 生成的资源。指定 `True` 以在生成的资源中传播标签。  
*类型*：布尔值  
*必需*：否  
*默认值*：`False`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ProvisionedConcurrencyConfig`   <a name="sam-function-provisionedconcurrencyconfig"></a>
函数别名的预置并发配置。  
仅当设置 `AutoPublishAlias` 时才可以指定 `ProvisionedConcurrencyConfig`。否则将导致错误。
*类型*：[ProvisionedConcurrencyConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Alias`资源的`[ProvisionedConcurrencyConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html#cfn-lambda-alias-provisionedconcurrencyconfig)`属性。

 `RecursiveLoop`   <a name="sam-function-recursiveloop"></a>
函数的递归循环检测配置的状态。  
当此值设置为 `Allow` 且 Lambda 检测到您的函数作为递归循环的一部分调用时，它不会采取任何操作。  
当此值设置为 `Terminate` 且 Lambda 检测到您的函数作为递归循环的一部分调用时，它会停止调用函数并通知您。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[RecursiveLoop](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-recursiveloop)`属性。

 `ReservedConcurrentExecutions`   <a name="sam-function-reservedconcurrentexecutions"></a>
希望为函数预留的最大并发执行数。  
有关此属性更多信息，请参阅*《AWS Lambda 开发人员指南》*中的 [Lambda 函数扩展](https://docs.aws.amazon.com/lambda/latest/dg/scaling.html)。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[ReservedConcurrentExecutions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-reservedconcurrentexecutions)`属性。

 `Role`   <a name="sam-function-role"></a>
要用作此函数执行角色的 IAM 角色的 ARN。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::Function`资源的`[Role](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-role)`属性。这在中是必需的 CloudFormation ，但不是必填的 AWS SAM。如果未指定角色，则会为您创建一个逻辑 ID 为 `<function-logical-id>Role` 的角色。

 `RolePath`   <a name="sam-function-rolepath"></a>
函数的 IAM 执行角色的路径。  
生成角色时请使用此属性。当使用 `Role` 属性指定角色时，请勿使用。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IAM::Role`资源的`[Path](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-path)`属性。

 `Runtime`   <a name="sam-function-runtime"></a>
函数的[运行时](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)的标识符。仅当属性 `PackageType` 为 `Zip` 时，该属性是必需属性。  
如果为此属性指定标`provided`识符，则可以使用 res `Metadata` ource 属性 AWS SAM 来指示构建此函数所需的自定义运行时。有关构建自定义运行时系统的更多信息，请参阅 [在中使用自定义运行时构建 Lambda 函数 AWS SAM](building-custom-runtimes.md)。
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[Runtime](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-runtime)`属性。

 `RuntimeManagementConfig`   <a name="sam-function-runtimemanagementconfig"></a>
为 Lambda 函数配置运行时系统管理选项，例如运行时环境更新、回滚行为以及选择特定的运行时版本。要了解更多信息，请参阅*《AWS Lambda 开发人员指南》*中的 [Lambda 运行时系统更新](https://docs.aws.amazon.com//lambda/latest/dg/runtimes-update.html)。  
*类型*：[RuntimeManagementConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-runtimemanagementconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[ RuntimeManagementConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-runtimemanagementconfig.html)`属性。

 `SnapStart`   <a name="sam-function-snapstart"></a>
创建任何新 Lambda 函数版本的快照。快照是初始化函数的缓存状态，包括其所有依赖项。函数仅被初始化一次，缓存的状态将在未来的所有调用中重复使用，从而通过减少必须初始化函数的次数来提高应用程序性能。要了解更多信息，请参阅*AWS Lambda 开发人员*指南SnapStart中的[使用 Lambda 提高启动性能](https://docs.aws.amazon.com/lambda/latest/dg/snapstart.html)。  
*类型*：[SnapStart](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[SnapStart](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-snapstart.html)`属性。

 `SourceKMSKeyArn`   <a name="sam-function-sourcekmskeyarn"></a>
代表用于加密客户 ZIP 功能代码的 KMS 密钥 ARN。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``Code`数据类型的`[SourceKMSKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-sourcekmskeyarn)`属性。

 `Tags`   <a name="sam-function-tags"></a>
指定添加到此函数的标签的映射（字符串到字符串）。有关标签的有效键和值的详细信息，请参阅*《AWS Lambda 开发人员指南》*中的[标签键和值要求](https://docs.aws.amazon.com/lambda/latest/dg/configuration-tags.html#configuration-tags-restrictions)。  
创建堆栈后， AWS SAM 会自动向此 Lambda 函数以及为此函数生成的默认角色添加`lambda:createdBy:SAM`标签。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::Function`资源的`[Tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-tags)`属性。中的`Tags`属性由键值对 AWS SAM 组成（而 CloudFormation 在此属性中则由`Tag`对象列表组成）。此外，还 AWS SAM 会自动向此 Lambda 函数以及为此函数生成的默认角色添加`lambda:createdBy:SAM`标签。

 `TenancyConfig`   <a name="sam-function-tenancyconfig"></a>
Lambda 租户隔离模式的配置。确保不同租户之间永远不会共享执行环境 IDs，从而为多租户应用程序提供计算级隔离。  
*类型*：[TenancyConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-tenancyconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[TenancyConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-tenancyconfig)`属性。

 `Timeout`   <a name="sam-function-timeout"></a>
函数在停止之前可以运行的最长时间（以秒为单位）。  
*类型*：整数  
*必需*：否  
*原定设置值：*3  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[Timeout](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-timeout)`属性。

 `Tracing`   <a name="sam-function-tracing"></a>
指定函数的 X-Ray 跟踪模式的字符串。  
+ `Active` – 为该函数激活 X-Ray 跟踪
+ `Disabled` – 为该函数停用 X-Ray 跟踪
+ `PassThrough` – 为该函数激活 X-Ray 跟踪 采样决策委托给下游服务。
如果指定为 `Active` 或 `PassThrough` 且未设置 `Role` 属性，则 AWS SAM 会将 `arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess` 策略添加到它为您创建的 Lambda 执行角色中。  
有关 X-Ray 的更多信息，请参阅《*AWS Lambda 开发者指南》 AWS X-Ray*中的 “[AWS Lambda 与一起使用](https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html)”。  
*有效值*：[`Active`\$1`Disabled`\$1`PassThrough`]  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::Function`资源的`[TracingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-tracingconfig)`属性。

 `VersionDescription`   <a name="sam-function-versiondescription"></a>
指定在新的 Lambda 版本资源上添加的 `Description` 字段。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Version`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-version.html#cfn-lambda-version-description)`属性。

 `VersionDeletionPolicy`   <a name="sam-function-versiondeletionpolicy"></a>
为设置时`AutoPublishAlias`创建的 Lambda 版本资源指定删除策略。这控制了删除堆栈时是保留还是删除版本资源。  
*有效值*：`Delete`、`Retain` 或 `Snapshot`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。它在生成的`AWS::Lambda::Version`资源上设置`DeletionPolicy`属性。

 `VpcConfig`   <a name="sam-function-vpcconfig"></a>
该配置使该函数能够访问您的虚拟私有云（VPC）中的私有资源。  
*类型*：[VpcConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-vpcconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[VpcConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-vpcconfig.html)`属性。

## 返回值
<a name="sam-resource-function-return-values"></a>

### Ref
<a name="sam-resource-function-return-values-ref"></a>

当向 `Ref` 内置函数提供此资源的逻辑 ID 时，将返回底层 Lambda 函数的资源名称。

有关使用 `Ref` 函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。

### Fn:: GetAtt
<a name="sam-resource-function-return-values-fn--getatt"></a>

`Fn::GetAtt` 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

有关使用 `Fn::GetAtt` 的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html)。

`Arn`  <a name="Arn-fn::getatt"></a>
底层 Lambda 函数的 ARN。

## 示例
<a name="sam-resource-function-examples"></a>

### 简单函数
<a name="sam-resource-function-examples-simple-function"></a>

以下是 Amazon S3 存储桶中包类型为 `Zip`（默认）的 [AWS::Serverless::Function](#sam-resource-function) 资源和函数代码的基本示例。

#### YAML
<a name="sam-resource-function-examples-simple-function--yaml"></a>

```
Type: AWS::Serverless::Function
Properties:
  Handler: index.handler
  Runtime: python3.9
  CodeUri: s3://bucket-name/key-name
```

### 函数属性示例
<a name="sam-resource-function-examples-function-properties-example"></a>

以下是使用 `InlineCode`、`Layers`、`Tracing`、`Policies`、`Amazon EFS`和 `Api` 事件源的包类型为 `Zip`（默认）的 [AWS::Serverless::Function](#sam-resource-function) 示例。

#### YAML
<a name="sam-resource-function-examples-function-properties-example--yaml"></a>

```
Type: AWS::Serverless::Function
DependsOn: MyMountTarget        # This is needed if an AWS::EFS::MountTarget resource is declared for EFS
Properties:
  Handler: index.handler
  Runtime: python3.9
  InlineCode: |
    def handler(event, context):
      print("Hello, world!")
  ReservedConcurrentExecutions: 30
  Layers:
    - Ref: MyLayer
  Tracing: Active
  Timeout: 120
  FileSystemConfigs:
    - Arn: !Ref MyEfsFileSystem
      LocalMountPath: /mnt/EFS
  Policies:
    - AWSLambdaExecute
    - Version: '2012-10-17		 	 	 ' 
      Statement:
        - Effect: Allow
          Action:
            - s3:GetObject
            - s3:GetObjectACL
          Resource: 'arn:aws:s3:::sam-s3-demo-bucket/*'
  Events:
    ApiEvent:
      Type: Api
      Properties:
        Path: /path
        Method: get
```

### ImageConfig 示例
<a name="sam-resource-function-examples-imageconfig-example"></a>

以下是包类型为 `Image` 的 Lambda 函数的 `ImageConfig` 示例。

#### YAML
<a name="sam-resource-function-examples-imageconfig-example--yaml"></a>

```
HelloWorldFunction:
  Type: AWS::Serverless::Function
  Properties:
    PackageType: Image
    ImageUri: account-id.dkr.ecr.region.amazonaws.com/ecr-repo-name:image-name
    ImageConfig:
      Command:
        - "app.lambda_handler"
      EntryPoint:
        - "entrypoint1"
      WorkingDirectory: "workDir"
```

### RuntimeManagementConfig 例子
<a name="sam-resource-function-examples-runtimemanagementconfig-examples"></a>

配置为根据当前行为更新其运行时环境的 Lambda 函数：

```
TestFunction
  Type: AWS::Serverless::Function
  Properties:
    ...
    Runtime: python3.9
    RuntimeManagementConfig:
      UpdateRuntimeOn: Auto
```

配置为在函数更新时更新其运行时环境的 Lambda 函数：

```
TestFunction
  Type: AWS::Serverless::Function
  Properties:
    ...
    Runtime: python3.9
    RuntimeManagementConfig:
      UpdateRuntimeOn: FunctionUpdate
```

配置为手动更新其运行时环境的 Lambda 函数：

```
TestFunction
  Type: AWS::Serverless::Function
  Properties:
    ...
    Runtime: python3.9
    RuntimeManagementConfig:
      RuntimeVersionArn: arn:aws:lambda:us-east-1::runtime:4c459dd0104ee29ec65dcad056c0b3ddbe20d6db76b265ade7eda9a066859b1e
      UpdateRuntimeOn: Manual
```

### SnapStart 例子
<a name="sam-resource-function-examples-snapstart-examples"></a>

在未来版本中 SnapStart 启用的 Lambda 函数示例：

```
TestFunc
  Type: AWS::Serverless::Function
  Properties:
    ...
    SnapStart:
      ApplyOn: PublishedVersions
```

### TenancyConfig 例子
<a name="sam-resource-function-examples-tenancyconfig-examples"></a>

开启租户隔离模式的 Lambda 函数示例：

```
TestFunction
  Type: AWS::Serverless::Function
  Properties:
    ...
    TenancyConfig:
      TenantIsolationMode: PER_TENANT
```

# DeadLetterQueue
<a name="sam-property-function-deadletterqueue"></a>

指定 ( AWS Lambda Lambda) 在无法处理事件时向其发送事件的 SQS 队列或 SNS 主题。有关死信队列功能的更多信息，请参阅《AWS Lambda 开发人员指南》**中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async-retain-records.html#invocation-dlq)。

SAM 将自动为您的 Lambda 函数执行角色添加相应的权限，以授予 Lambda 服务访问资源的权限。将为 SQS 队列添加 sqs:，SendMessage 将为 SNS 主题添加 SNS: Publish。

## 语法
<a name="sam-property-function-deadletterqueue-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-deadletterqueue-syntax.yaml"></a>

```
  [TargetArn](#sam-function-deadletterqueue-targetarn): String
  [Type](#sam-function-deadletterqueue-type): String
```

## Properties
<a name="sam-property-function-deadletterqueue-properties"></a>

 `TargetArn`   <a name="sam-function-deadletterqueue-targetarn"></a>
Amazon SQS 队列或 Amazon SNS 主题的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``DeadLetterConfig`数据类型的`[TargetArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-deadletterconfig.html#cfn-lambda-function-deadletterconfig-targetarn)`属性。

 `Type`   <a name="sam-function-deadletterqueue-type"></a>
死信队列的类型。  
*有效值*：`SNS`、`SQS`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-deadletterqueue--examples"></a>

### DeadLetterQueue
<a name="sam-property-function-deadletterqueue--examples--deadletterqueue"></a>

SNS 主题的死信队列示例。

#### YAML
<a name="sam-property-function-deadletterqueue--examples--deadletterqueue--yaml"></a>

```
DeadLetterQueue:
  Type: SNS
  TargetArn: arn:aws:sns:us-east-2:123456789012:my-topic
```

# DeploymentPreference
<a name="sam-property-function-deploymentpreference"></a>

指定启用逐步 Lambda 部署的配置。有关配置逐步 Lambda 部署的更多信息，请参阅 [使用以下方法逐步部署无服务器应用程序 AWS SAM](automating-updates-to-serverless-apps.md)。

**注意**  
要使用 `DeploymentPreference` 对象，必须在 [AWS::Serverless::Function](sam-resource-function.md) 中指定 `AutoPublishAlias`，否则将导致错误。

## 语法
<a name="sam-property-function-deploymentpreference-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-deploymentpreference-syntax.yaml"></a>

```
  [Alarms](#sam-function-deploymentpreference-alarms): List
  [Enabled](#sam-function-deploymentpreference-enabled): Boolean
  [Hooks](#sam-function-deploymentpreference-hooks): Hooks
  [PassthroughCondition](#sam-function-deploymentpreference-passthroughcondition): Boolean
  [Role](#sam-function-deploymentpreference-role): String
  [TriggerConfigurations](#sam-function-deploymentpreference-triggerconfigurations): List
  [Type](#sam-function-deploymentpreference-type): String
```

## Properties
<a name="sam-property-function-deploymentpreference-properties"></a>

 `Alarms`   <a name="sam-function-deploymentpreference-alarms"></a>
您希望由部署引发的任何错误触发的 CloudWatch 警报列表。  
此属性接受 `Fn::If` 内置函数。有关使用 `Fn::If` 的示例模板，请参阅本主题底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Enabled`   <a name="sam-function-deploymentpreference-enabled"></a>
是否启用此部署首选项。  
*类型*：布尔值  
*必需*：否  
*默认值*：True  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Hooks`   <a name="sam-function-deploymentpreference-hooks"></a>
流量转移之前和之后运行的验证 Lambda 函数。  
*类型*：[钩子](sam-property-function-hooks.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `PassthroughCondition`   <a name="sam-function-deploymentpreference-passthroughcondition"></a>
如果为 True，并且启用了此部署首选项，则函数的 Condition 将传递给生成的 CodeDeploy 资源。通常，应将其设置为 True。否则，即使函数的条件解析为 False，也会创建 CodeDeploy 资源。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Role`   <a name="sam-function-deploymentpreference-role"></a>
用于流量转移的 IAM 角色 ARN。 CodeDeploy 如有提供，则不会创建 IAM 角色。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `TriggerConfigurations`   <a name="sam-function-deploymentpreference-triggerconfigurations"></a>
要与部署组关联的触发器配置列表。用于通知有关生命周期事件的 SNS 主题。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::CodeDeploy::DeploymentGroup`资源的`[TriggerConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codedeploy-deploymentgroup.html#cfn-codedeploy-deploymentgroup-triggerconfigurations)`属性。

 `Type`   <a name="sam-function-deploymentpreference-type"></a>
目前有两类部署类型：线性和金丝雀。有关可用部署类型的更多信息，请参阅 [使用以下方法逐步部署无服务器应用程序 AWS SAM](automating-updates-to-serverless-apps.md)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-deploymentpreference--examples"></a>

### DeploymentPreference 带有交通前和交通后的挂钩。
<a name="sam-property-function-deploymentpreference--examples--deploymentpreference-with-pre--and-post-traffic-hooks."></a>

包含流量前后钩子的部署首选项示例。

#### YAML
<a name="sam-property-function-deploymentpreference--examples--deploymentpreference-with-pre--and-post-traffic-hooks.--yaml"></a>

```
DeploymentPreference:
  Enabled: true
  Type: Canary10Percent10Minutes 
  Alarms:
    - !Ref: AliasErrorMetricGreaterThanZeroAlarm
    - !Ref: LatestVersionErrorMetricGreaterThanZeroAlarm
  Hooks:
    PreTraffic:
      !Ref: PreTrafficLambdaFunction
    PostTraffic:
      !Ref: PostTrafficLambdaFunction
```

### DeploymentPreference 使用 Fn:: If 内部函数
<a name="sam-property-function-deploymentpreference--examples--deploymentpreference-with-fn::if-intrinsic-function"></a>

使用 `Fn::If` 配置警报的部署首选项示例。在本示例中，如果 `MyCondition` 为 `true`，则将配置 `Alarm1`；如果 `MyCondition` 为 `false`，则将配置 `Alarm2` 和 `Alarm5`。

#### YAML
<a name="sam-property-function-deploymentpreference--examples--deploymentpreference-with-fn::if-intrinsic-function--yaml"></a>

```
DeploymentPreference:
  Enabled: true
  Type: Canary10Percent10Minutes 
  Alarms:
    Fn::If:
      - MyCondition
      - - Alarm1
      - - Alarm2
        - Alarm5
```

# Hooks
<a name="sam-property-function-hooks"></a>

流量转移之前和之后运行的验证 Lambda 函数。

**注意**  
此属性中引用的 Lambda 函数会配置生成的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-alias.html) 资源的 `CodeDeployLambdaAliasUpdate` 对象。有关更多信息，请参阅《*AWS CloudFormation 用户指南*》中的[CodeDeployLambdaAliasUpdate 策略](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatepolicy.html#cfn-attributes-updatepolicy-codedeploylambdaaliasupdate)。

## 语法
<a name="sam-property-function-hooks-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-hooks-syntax.yaml"></a>

```
  [PostTraffic](#sam-function-hooks-posttraffic): String
  [PreTraffic](#sam-function-hooks-pretraffic): String
```

## Properties
<a name="sam-property-function-hooks-properties"></a>

 `PostTraffic`   <a name="sam-function-hooks-posttraffic"></a>
流量转移之后运行的 Lambda 函数。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `PreTraffic`   <a name="sam-function-hooks-pretraffic"></a>
流量转移之前运行的 Lambda 函数。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-hooks--examples"></a>

### 挂钩
<a name="sam-property-function-hooks--examples--hooks"></a>

示例钩子函数

#### YAML
<a name="sam-property-function-hooks--examples--hooks--yaml"></a>

```
Hooks:
  PreTraffic:
    Ref: PreTrafficLambdaFunction
  PostTraffic:
    Ref: PostTrafficLambdaFunction
```

# DurableConfig
<a name="sam-property-function-durableconfig"></a>

为 AWS Lambda 函数配置持久执行设置。耐用的功能可以运行长达一年，并自动检查进度，从而支持长时间运行的工作流程和容错应用程序。有关耐久函数的更多信息，请参阅《*AWS Lambda 开发人员*指南》中的 [Lambda 耐久函数](https://docs.aws.amazon.com/lambda/latest/dg/durable-functions.html)。

## 语法
<a name="sam-property-function-durableconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-durableconfig-syntax.yaml"></a>

```
  [ExecutionTimeout](#sam-function-durableconfig-executiontimeout): Integer
  [RetentionPeriodInDays](#sam-function-durableconfig-retentionperiodindays): Integer
```

## Properties
<a name="sam-property-function-durableconfig-properties"></a>

 `ExecutionTimeout`   <a name="sam-function-durableconfig-executiontimeout"></a>
Lambda 允许持久函数在停止之前运行的时间（以秒为单位）。最大值为一个 366 天的一年或 31,622,400 秒。  
*类型*：整数  
*是否必需*：是  
*最小值*：1  
*最大值*：31622400  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``DurableConfig`数据类型的`[ExecutionTimeout](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-durableconfig.html#cfn-lambda-function-durableconfig-executiontimeout)`属性。

 `RetentionPeriodInDays`   <a name="sam-function-durableconfig-retentionperiodindays"></a>
在持久执行结束后，Lambda 保留其历史记录的天数，从 1 到 90 天不等。默认值为 14 天。  
*类型*：整数  
*必需*：否  
*默认值*：14  
*最小值*：1  
*最大值*：90  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``DurableConfig`数据类型的`[RetentionPeriodInDays](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-durableconfig.html#cfn-lambda-function-durableconfig-retentionperiodindays)`属性。

## 示例
<a name="sam-property-function-durableconfig--examples"></a>

### DurableConfig
<a name="sam-property-function-durableconfig--examples--durableconfig"></a>

具有 1 小时执行超时和 7 天保留期的函数的持久配置示例。

#### YAML
<a name="sam-property-function-durableconfig--examples--durableconfig--yaml"></a>

```
DurableConfig:
  ExecutionTimeout: 3600
  RetentionPeriodInDays: 7
```

# EventInvokeConfiguration
<a name="sam-property-function-eventinvokeconfiguration"></a>

[异步](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html) Lambda 别名或版本调用的配置选项。

## 语法
<a name="sam-property-function-eventinvokeconfiguration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-eventinvokeconfiguration-syntax.yaml"></a>

```
  [DestinationConfig](#sam-function-eventinvokeconfiguration-destinationconfig): EventInvokeDestinationConfiguration
  [MaximumEventAgeInSeconds](#sam-function-eventinvokeconfiguration-maximumeventageinseconds): Integer
  [MaximumRetryAttempts](#sam-function-eventinvokeconfiguration-maximumretryattempts): Integer
```

## Properties
<a name="sam-property-function-eventinvokeconfiguration-properties"></a>

 `DestinationConfig`   <a name="sam-function-eventinvokeconfiguration-destinationconfig"></a>
一个配置对象，用于在 Lambda 处理事件后指定事件目的地。  
*类型*：[EventInvokeDestinationConfiguration](sam-property-function-eventinvokedestinationconfiguration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::EventInvokeConfig`资源的`[DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventinvokeconfig-destinationconfig.html)`属性。SAM 需要一个在中不存在的额外参数 “类型” CloudFormation。

 `MaximumEventAgeInSeconds`   <a name="sam-function-eventinvokeconfiguration-maximumeventageinseconds"></a>
Lambda 发送到函数以进行处理的请求的最长期限。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventInvokeConfig`资源的`[MaximumEventAgeInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventinvokeconfig.html#cfn-lambda-eventinvokeconfig-maximumeventageinseconds)`属性。

 `MaximumRetryAttempts`   <a name="sam-function-eventinvokeconfiguration-maximumretryattempts"></a>
在函数返回错误前重试的最大次数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventInvokeConfig`资源的`[MaximumRetryAttempts](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventinvokeconfig.html#cfn-lambda-eventinvokeconfig-maximumretryattempts)`属性。

## 示例
<a name="sam-property-function-eventinvokeconfiguration--examples"></a>

### MaximumEventAgeInSeconds
<a name="sam-property-function-eventinvokeconfiguration--examples--maximumeventageinseconds"></a>

MaximumEventAgeInSeconds 示例

#### YAML
<a name="sam-property-function-eventinvokeconfiguration--examples--maximumeventageinseconds--yaml"></a>

```
EventInvokeConfig:
  MaximumEventAgeInSeconds: 60
  MaximumRetryAttempts: 2
  DestinationConfig:
    OnSuccess:
      Type: SQS
      Destination: arn:aws:sqs:us-west-2:012345678901:my-queue
    OnFailure:
      Type: Lambda
      Destination: !GetAtt DestinationLambda.Arn
```

# EventInvokeDestinationConfiguration
<a name="sam-property-function-eventinvokedestinationconfiguration"></a>

一个配置对象，用于在 Lambda 处理事件后指定事件目的地。

## 语法
<a name="sam-property-function-eventinvokedestinationconfiguration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-eventinvokedestinationconfiguration-syntax.yaml"></a>

```
  [OnFailure](#sam-function-eventinvokedestinationconfiguration-onfailure): OnFailure
  [OnSuccess](#sam-function-eventinvokedestinationconfiguration-onsuccess): OnSuccess
```

## Properties
<a name="sam-property-function-eventinvokedestinationconfiguration-properties"></a>

 `OnFailure`   <a name="sam-function-eventinvokedestinationconfiguration-onfailure"></a>
处理失败的事件的目的地。  
*类型*：[OnFailure](sam-property-function-onfailure.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::EventInvokeConfig`资源的`[OnFailure](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventinvokeconfig-onfailure.html)`属性。需要 `Type`（这是仅适用于 SAM 的附加属性）。

 `OnSuccess`   <a name="sam-function-eventinvokedestinationconfiguration-onsuccess"></a>
已成功处理的事件的目的地。  
*类型*：[OnSuccess](sam-property-function-onsuccess.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::EventInvokeConfig`资源的`[OnSuccess](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventinvokeconfig-onsuccess)`属性。需要 `Type`（这是仅适用于 SAM 的附加属性）。

## 示例
<a name="sam-property-function-eventinvokedestinationconfiguration--examples"></a>

### OnSuccess
<a name="sam-property-function-eventinvokedestinationconfiguration--examples--onsuccess"></a>

OnSuccess 示例

#### YAML
<a name="sam-property-function-eventinvokedestinationconfiguration--examples--onsuccess--yaml"></a>

```
EventInvokeConfig:
  DestinationConfig:
    OnSuccess:
      Type: SQS
      Destination: arn:aws:sqs:us-west-2:012345678901:my-queue
    OnFailure:
      Type: Lambda
      Destination: !GetAtt DestinationLambda.Arn
```

# OnFailure
<a name="sam-property-function-onfailure"></a>

处理失败的事件的目的地。

## 语法
<a name="sam-property-function-onfailure-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-onfailure-syntax.yaml"></a>

```
  [Destination](#sam-function-onfailure-destination): String
  [Type](#sam-function-onfailure-type): String
```

## Properties
<a name="sam-property-function-onfailure-properties"></a>

 `Destination`   <a name="sam-function-onfailure-destination"></a>
目标资源的 Amazon Resource Name (ARN)。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::EventInvokeConfig`资源的`[OnFailure](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventinvokeconfig-onfailure.html)`属性。SAM 将向与该函数关联的自动生成的 IAM 角色添加任何必要的权限，以访问此属性中引用的资源。  
*其他说明*：如果类型为 Lambda/EventBridge，则必须填写目的地。

 `Type`   <a name="sam-function-onfailure-type"></a>
目标中引用的资源类型。支持的类型有 `SQS`、`SNS`、`S3`、`Lambda` 和 `EventBridge`。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*其他说明*：如果类型为 SQS/SNS 且`Destination`属性留空，则 SQS/SNS 资源由 SAM 自动生成。要引用该资源，请使用 `<function-logical-id>.DestinationQueue`（对于 SQS）或 `<function-logical-id>.DestinationTopic`（对于 SQS）。如果类型为 Lambda/EventBridge，`Destination`则为必填项。

## 示例
<a name="sam-property-function-onfailure--examples"></a>

### EventInvoke 包含 SQS 和 Lambda 目标的配置示例
<a name="sam-property-function-onfailure--examples--eventinvoke-configuration-example-with-sqs-and-lambda-destinations"></a>

在此示例中，没有给出 SQS OnSuccess 配置的目标，因此 SAM 隐式创建了一个 SQS 队列并添加了所有必要的权限。同样在本示例中，在 OnFailure 配置中指定了在模板文件中声明的 Lambda 资源的目标，因此 SAM 向此 Lambda 函数添加了调用目标 Lambda 函数所需的权限。

#### YAML
<a name="sam-property-function-onfailure--examples--eventinvoke-configuration-example-with-sqs-and-lambda-destinations--yaml"></a>

```
EventInvokeConfig:
  DestinationConfig:
    OnSuccess:
      Type: SQS
    OnFailure:
      Type: Lambda
      Destination: !GetAtt DestinationLambda.Arn  # Arn of a Lambda function declared in the template file.
```

### EventInvoke 带有 SNS 目标的配置示例
<a name="sam-property-function-onfailure--examples--eventinvoke-configuration-example-with-sns-destination"></a>

在此示例中，为在 OnSuccess 配置的模板文件中声明的 SNS 主题提供了一个目标。

#### YAML
<a name="sam-property-function-onfailure--examples--eventinvoke-configuration-example-with-sns-destination--yaml"></a>

```
EventInvokeConfig:
  DestinationConfig:
    OnSuccess:
      Type: SNS
      Destination:
        Ref: DestinationSNS       # Arn of an SNS topic declared in the tempate file
```

# OnSuccess
<a name="sam-property-function-onsuccess"></a>

已成功处理的事件的目的地。

## 语法
<a name="sam-property-function-onsuccess-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-onsuccess-syntax.yaml"></a>

```
  [Destination](#sam-function-onsuccess-destination): String
  [Type](#sam-function-onsuccess-type): String
```

## Properties
<a name="sam-property-function-onsuccess-properties"></a>

 `Destination`   <a name="sam-function-onsuccess-destination"></a>
目标资源的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::EventInvokeConfig`资源的`[OnSuccess](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventinvokeconfig-onsuccess)`属性。SAM 将向与该函数关联的自动生成的 IAM 角色添加任何必要的权限，以访问此属性中引用的资源。  
*其他说明*：如果类型为 Lambda/EventBridge，则必须填写目的地。

 `Type`   <a name="sam-function-onsuccess-type"></a>
目标中引用的资源类型。支持的类型有 `SQS`、`SNS`、`S3`、`Lambda` 和 `EventBridge`。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*其他说明*：如果类型为 SQS/SNS 且`Destination`属性留空，则 SQS/SNS 资源由 SAM 自动生成。要引用该资源，请使用 `<function-logical-id>.DestinationQueue`（对于 SQS）或 `<function-logical-id>.DestinationTopic`（对于 SQS）。如果类型为 Lambda/EventBridge，`Destination`则为必填项。

## 示例
<a name="sam-property-function-onsuccess--examples"></a>

### EventInvoke 包含 SQS 和 Lambda 目标的配置示例
<a name="sam-property-function-onsuccess--examples--eventinvoke-configuration-example-with-sqs-and-lambda-destinations"></a>

在此示例中，没有给出 SQS OnSuccess 配置的目标，因此 SAM 隐式创建了一个 SQS 队列并添加了所有必要的权限。同样在本示例中，在 OnFailure 配置中指定了在模板文件中声明的 Lambda 资源的目标，因此 SAM 向此 Lambda 函数添加了调用目标 Lambda 函数所需的权限。

#### YAML
<a name="sam-property-function-onsuccess--examples--eventinvoke-configuration-example-with-sqs-and-lambda-destinations--yaml"></a>

```
EventInvokeConfig:
  DestinationConfig:
    OnSuccess:
      Type: SQS
    OnFailure:
      Type: Lambda
      Destination: !GetAtt DestinationLambda.Arn  # Arn of a Lambda function declared in the template file.
```

### EventInvoke 带有 SNS 目标的配置示例
<a name="sam-property-function-onsuccess--examples--eventinvoke-configuration-example-with-sns-destination"></a>

在此示例中，为在 OnSuccess 配置的模板文件中声明的 SNS 主题提供了一个目标。

#### YAML
<a name="sam-property-function-onsuccess--examples--eventinvoke-configuration-example-with-sns-destination--yaml"></a>

```
EventInvokeConfig:
  DestinationConfig:
    OnSuccess:
      Type: SNS
      Destination:
        Ref: DestinationSNS       # Arn of an SNS topic declared in the tempate file
```

# EventSource
<a name="sam-property-function-eventsource"></a>

描述触发函数的事件源的对象。每个事件都由一个类型和一组依赖于该类型的属性组成。有关每个事件源的属性的更多信息，请参阅与具体类型对应的主题。

## 语法
<a name="sam-property-function-eventsource-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-eventsource-syntax.yaml"></a>

```
  [Properties](#sam-function-eventsource-properties): AlexaSkill | Api | CloudWatchEvent | CloudWatchLogs | Cognito | DocumentDB | DynamoDB | EventBridgeRule | HttpApi | IoTRule | Kinesis | MQ | MSK | S3 | Schedule | ScheduleV2 | SelfManagedKafka | SNS | SQS
  [Type](#sam-function-eventsource-type): String
```

## Properties
<a name="sam-property-function-eventsource-properties"></a>

 `Properties`   <a name="sam-function-eventsource-properties"></a>
描述此事件映射的属性的对象。这组属性必须符合定义的类型。  
*类型* [[[[[：[AlexaSkill](sam-property-function-alexaskill.md)\$1 Ap [i](sam-property-function-api.md) \$1 \$1 \$1 Co [gnito [CloudWatchEvent[CloudWatchLogs](sam-property-function-cloudwatchlogs.md)](sam-property-function-cloudwatchevent.md)](sam-property-function-cognito.md)\$1 documentDB \$1 D [ynamo [DB](sam-property-function-documentdb.md) \$1 \$1 \$1 [Io](sam-property-function-iotrule.md) \$1 [Kinesis [EventBridgeRule](sam-property-function-eventbridgerule.md)\$1 MQ [HttpApi](sam-property-function-httpapi.md)\$1 MS](sam-property-function-kinesis.md) K TRule \$1 S3 \$1 日程](sam-property-function-dynamodb.md)安排 \$1 Schedu [leV2 \$1 \$1](sam-property-function-mq.md)[SNS \$1 SQ](sam-property-function-msk.md) S [SelfManagedKafka](sam-property-function-selfmanagedkafka.md)](sam-property-function-sqs.md)](sam-property-function-sns.md)](sam-property-function-schedulev2.md)](sam-property-function-schedule.md)](sam-property-function-s3.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Type`   <a name="sam-function-eventsource-type"></a>
事件类型。  
*有效值*：`AlexaSkill`, `Api`, `CloudWatchEvent`, `CloudWatchLogs`, `Cognito`, `DocumentDB`, `DynamoDB`, `EventBridgeRule`, `HttpApi`, `IoTRule`, `Kinesis`, `MQ`, `MSK`, `S3`, `Schedule`, `ScheduleV2`, `SelfManagedKafka`, `SNS`, `SQS`   
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-eventsource--examples"></a>

### APIEvent
<a name="sam-property-function-eventsource--examples--apievent"></a>

使用 API 事件的示例

#### YAML
<a name="sam-property-function-eventsource--examples--apievent--yaml"></a>

```
ApiEvent:
  Type: Api
  Properties:
    Method: get
    Path: /group/{user}
    RestApiId: 
      Ref: MyApi
```

# AlexaSkill
<a name="sam-property-function-alexaskill"></a>

描述 `AlexaSkill` 事件源类型的对象。

## 语法
<a name="sam-property-function-alexaskill-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-alexaskill-syntax.yaml"></a>

```
  [SkillId](#sam-function-alexaskill-skillid): String
```

## Properties
<a name="sam-property-function-alexaskill-properties"></a>

 `SkillId`   <a name="sam-function-alexaskill-skillid"></a>
Alexa 技能的 ID。有关技能 ID 的更多信息，请参阅 Alexa Skills Kit 文档中的[为 Lambda 函数配置触发器](https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-an-aws-lambda-function.html#configuring-the-alexa-skills-kit-trigger)。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-alexaskill--examples"></a>

### AlexaSkillTrigger
<a name="sam-property-function-alexaskill--examples--alexaskilltrigger"></a>

Alexa Skill 事件示例

#### YAML
<a name="sam-property-function-alexaskill--examples--alexaskilltrigger--yaml"></a>

```
AlexaSkillEvent:
  Type: AlexaSkill
```

# Api
<a name="sam-property-function-api"></a>

描述 `Api` 事件源类型的对象。如果定义了 [AWS::Serverless::Api](sam-resource-api.md) 资源，则路径和方法值必须与 API 的 OpenAPI 定义中的操作相对应。

如果未定义 [AWS::Serverless::Api](sam-resource-api.md)，则函数的输入和输出表示 HTTP 请求和 HTTP 响应。

例如，使用 JavaScript API，可以通过返回带有 statusCode 和 body 密钥的对象来控制响应的状态代码和正文。

## 语法
<a name="sam-property-function-api-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-api-syntax.yaml"></a>

```
  [Auth](#sam-function-api-auth): ApiFunctionAuth
  [Method](#sam-function-api-method): String
  [Path](#sam-function-api-path): String
  [RequestModel](#sam-function-api-requestmodel): RequestModel
  [RequestParameters](#sam-function-api-requestparameters): List of [ String | RequestParameter ]
  [RestApiId](#sam-function-api-restapiid): String
  [ResponseTransferMode](#sam-function-api-responsetransfermode): String
  TimeoutInMillis: Integer
```

## Properties
<a name="sam-property-function-api-properties"></a>

 `Auth`   <a name="sam-function-api-auth"></a>
此特定 Api\$1路径\$1方法的身份验证配置。  
对于未指定 `DefaultAuthorizer` 时覆盖在单个路径上 API 的 `DefaultAuthorizer` 设置身份验证配置或覆盖默认 `ApiKeyRequired` 设置很有用。  
*类型*：[ApiFunctionAuth](sam-property-function-apifunctionauth.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Method`   <a name="sam-function-api-method"></a>
调用此函数的 HTTP 方法。选项包括 `DELETE`、`GET`、`HEAD`、`OPTIONS`、`PATCH`、`POST`、`PUT` 和 `ANY`。有关详细信息，请参阅*《API Gateway 开发人员指南》*中的[设置 HTTP 方法](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-settings-method-request.html#setup-method-add-http-method)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Path`   <a name="sam-function-api-path"></a>
调用此函数的 URI 路径。必须以 `/` 开头。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `RequestModel`   <a name="sam-function-api-requestmodel"></a>
用于此特定 Api\$1路径\$1方法 的请求模型。这应该引用 [AWS::Serverless::Api](sam-resource-api.md) 资源 `Models` 部分中指定的模型的名称。  
*类型*：[RequestModel](sam-property-function-requestmodel.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `RequestParameters`   <a name="sam-function-api-requestparameters"></a>
此特定 Api\$1Path\$1Method 的请求参数配置。所有参数名称必须以 `method.request` 开头，且必须限制为 `method.request.header`、`method.request.querystring`、或`method.request.path`。  
列表既可以包含参数名称字符串，也可以包含[RequestParameter](sam-property-function-requestparameter.md)对象。对于字符串，`Required` 和 `Caching` 属性将默认为 `false`。  
*类型*：[字符串 \$1 [RequestParameter](sam-property-function-requestparameter.md)] 列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `RestApiId`   <a name="sam-function-api-restapiid"></a>
 RestApi 资源的标识符，必须包含具有给定路径和方法的操作。通常，将其设置为引用此模板中定义的 [AWS::Serverless::Api](sam-resource-api.md) 资源。  
如果未定义此属性，则使用生成的`OpenApi`文档 AWS SAM 创建默认[AWS::Serverless::Api](sam-resource-api.md)资源。该资源包含所有路径和方法的并集，这些路径和方法由同一模板中的 `Api` 事件定义，但未指定 `RestApiId`。  
这不能引用其他模板中定义的 [AWS::Serverless::Api](sam-resource-api.md) 资源。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`ResponseTransferMode`  <a name="sam-function-api-responsetransfermode"></a>
Lambda 函数集成的响应传输模式。设置`RESPONSE_STREAM`为可启用通过 API Gateway 进行的 Lambda 响应流式传输，从而允许该函数将响应流回客户端。设置为时`RESPONSE_STREAM`，API Gateway 使用 Lambda InvokeWithResponseStreaming API。  
*类型*：字符串  
*必需*：否  
*有效值*：`BUFFERED` \$1 `RESPONSE_STREAM`  
*CloudFormation 兼容性*：此属性直接传递给的[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-integration.html#cfn-apigateway-method-integration-responsetransfermode](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-integration.html#cfn-apigateway-method-integration-responsetransfermode)属性`AWS::ApiGateway::Method Integration`。

`TimeoutInMillis`  <a name="sam-function-api-timeoutinmillis"></a>
自定义超时值，范围在 50 到 29,000 毫秒之间。  
当您指定此属性时， AWS SAM 会修改您的 OpenAPI 定义。必须使用 `DefinitionBody` 属性内联指定 OpenAPI 定义。
*类型*：整数  
*必需*：否  
*默认值*：29,000 毫秒或 29 秒  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-api--examples"></a>

### 基本示例
<a name="sam-property-function-api--examples--apievent"></a>

#### YAML
<a name="sam-property-function-api--examples--apievent--yaml"></a>

```
Events:
  ApiEvent:
    Type: Api
    Properties:
      Path: /path
      Method: get
      RequestParameters:
        - method.request.header.Authorization
        - method.request.querystring.keyword:
            Required: true
            Caching: false
```

# ApiFunctionAuth
<a name="sam-property-function-apifunctionauth"></a>

在事件级别为特定 API、路径和方法配置授权。

## 语法
<a name="sam-property-function-apifunctionauth-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-apifunctionauth-syntax.yaml"></a>

```
  [ApiKeyRequired](#sam-function-apifunctionauth-apikeyrequired): Boolean
  [AuthorizationScopes](#sam-function-apifunctionauth-authorizationscopes): List
  [Authorizer](#sam-function-apifunctionauth-authorizer): String
  [InvokeRole](#sam-function-apifunctionauth-invokerole): String
  OverrideApiAuth: Boolean
  [ResourcePolicy](#sam-function-apifunctionauth-resourcepolicy): ResourcePolicyStatement
```

## Properties
<a name="sam-property-function-apifunctionauth-properties"></a>

 `ApiKeyRequired`   <a name="sam-function-apifunctionauth-apikeyrequired"></a>
此 API、路径和方法需要 API 密钥。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AuthorizationScopes`   <a name="sam-function-apifunctionauth-authorizationscopes"></a>
适用于此 API、路径和方法的授权范围。  
如果您已指定 `DefaultAuthorizer` 属性，则您指定的范围将覆盖该属性应用的所有范围。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Authorizer`   <a name="sam-function-apifunctionauth-authorizer"></a>
特定函数的`Authorizer`。  
如果您为 `AWS::Serverless::Api` 资源指定了全局授权方，则可以通过将 `Authorizer` 设置为 `NONE` 来覆盖该授权方。有关示例，请参阅[覆盖 Amazon API Gateway REST API 的全局授权方](#sam-property-function-apifunctionauth--examples--override)。  
如果您使用 `AWS::Serverless::Api` 资源的 `DefinitionBody` 属性来描述您的 API，则必须使用 `OverrideApiAuth` 和 `Authorizer` 来覆盖您的全局授权方。请参阅`OverrideApiAuth`了解更多信息。
*有效值*：`AWS_IAM``NONE`、或 AWS SAM 模板中定义的任何授权者的逻辑 ID。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `InvokeRole`   <a name="sam-function-apifunctionauth-invokerole"></a>
指定用于 `AWS_IAM` 授权的 `InvokeRole`。  
*类型*：字符串  
*必需*：否  
*默认值*：`CALLER_CREDENTIALS`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*附加说明*：`CALLER_CREDENTIALS` 映射到 `arn:aws:iam:::<user>/`，后者使用调用者凭证来调用端点。

`OverrideApiAuth`  <a name="sam-function-apifunctionauth-overrideapiauth"></a>
指定为 `true` 以覆盖 `AWS::Serverless::Api` 资源的全局授权方配置。只有在您指定全局授权方并使用 `AWS::Serverless::Api` 资源的 `DefinitionBody` 属性来描述您的 API 时，才需要此属性。  
当你指定`OverrideApiAuth`为时`true`， AWS SAM 将使用为、或`ResourcePolicy`提供的任何值覆盖你的全局授权`ApiKeyRequired`者`Authorizer`。因此，使用 `OverrideApiAuth` 时还必须指定其中至少一个属性。有关示例，请参阅[指定 for 时 DefinitionBody 覆盖全局授权 AWS::Serverless::Api 方](#sam-property-function-apifunctionauth--examples--override2)。
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ResourcePolicy`   <a name="sam-function-apifunctionauth-resourcepolicy"></a>
在 API 上为此路径配置资源策略。  
*类型*：[ResourcePolicyStatement](sam-property-function-resourcepolicystatement.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-apifunctionauth--examples"></a>

### 函数身份验证
<a name="sam-property-function-apifunctionauth--examples--function-auth"></a>

以下示例指定了函数级别的授权。

#### YAML
<a name="sam-property-function-apifunctionauth--examples--function-auth--yaml"></a>

```
Auth:
  ApiKeyRequired: true
  Authorizer: NONE
```

### 覆盖 Amazon API Gateway REST API 的全局授权方
<a name="sam-property-function-apifunctionauth--examples--override"></a>

您可以为 `AWS::Serverless::Api` 资源指定全局授权方。以下是配置全局默认授权方的示例：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyApiWithLambdaRequestAuth:
    Type: AWS::Serverless::Api
    Properties:
      ...
      Auth:
        Authorizers:
          MyLambdaRequestAuth:
            FunctionArn: !GetAtt MyAuthFn.Arn
        DefaultAuthorizer: MyLambdaRequestAuth
```

要覆盖 AWS Lambda 函数的默认授权者，可以指定`Authorizer`为`NONE`。以下是示例：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  ...
  MyFn:
    Type: AWS::Serverless::Function
    Properties:
      ...
      Events:
        LambdaRequest:
          Type: Api
          Properties:
            RestApiId: !Ref MyApiWithLambdaRequestAuth
            Method: GET
            Auth:
              Authorizer: NONE
```

### 指定 for 时 DefinitionBody 覆盖全局授权 AWS::Serverless::Api 方
<a name="sam-property-function-apifunctionauth--examples--override2"></a>

当使用 `DefinitionBody` 属性描述 `AWS::Serverless::Api` 资源时，之前的覆盖方法不起作用。以下是对 `AWS::Serverless::Api` 资源使用 `DefinitionBody` 属性的示例：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyApiWithLambdaRequestAuth:
    Type: AWS::Serverless::Api
    Properties:
      ...
      DefinitionBody:
        swagger: 2.0
        ...
        paths:
          /lambda-request:
            ...
      Auth:
        Authorizers:
          MyLambdaRequestAuth:
            FunctionArn: !GetAtt MyAuthFn.Arn
        DefaultAuthorizer: MyLambdaRequestAuth
```

要覆盖全局授权方，请使用 `OverrideApiAuth` 属性。以下是使用 `OverrideApiAuth` 通过为 `Authorizer` 提供的值覆盖全局授权方的示例：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyApiWithLambdaRequestAuth:
    Type: AWS::Serverless::Api
    Properties:
      ...
      DefinitionBody:
        swagger: 2-0
        ...
        paths:
          /lambda-request:
            ...
      Auth:
        Authorizers:
          MyLambdaRequestAuth:
            FunctionArn: !GetAtt MyAuthFn.Arn
        DefaultAuthorizer: MyLambdaRequestAuth
    
    MyAuthFn:
      Type: AWS::Serverless::Function
      ...
    
    MyFn:
      Type: AWS::Serverless::Function
        Properties:
          ...
          Events:
            LambdaRequest:
              Type: Api
              Properties:
                RestApiId: !Ref MyApiWithLambdaRequestAuth
                Method: GET
                Auth:
                  Authorizer: NONE
                  OverrideApiAuth: true
                Path: /lambda-token
```

# ResourcePolicyStatement
<a name="sam-property-function-resourcepolicystatement"></a>

为 API 的所有方法和路径配置资源策略。有关资源策略的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API Gateway 资源策略控制 API 的访问权限](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html)。

## 语法
<a name="sam-property-function-resourcepolicystatement-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-resourcepolicystatement-syntax.yaml"></a>

```
  [AwsAccountBlacklist](#sam-function-resourcepolicystatement-awsaccountblacklist): List
  [AwsAccountWhitelist](#sam-function-resourcepolicystatement-awsaccountwhitelist): List
  [CustomStatements](#sam-function-resourcepolicystatement-customstatements): List
  [IntrinsicVpcBlacklist](#sam-function-resourcepolicystatement-intrinsicvpcblacklist): List
  [IntrinsicVpcWhitelist](#sam-function-resourcepolicystatement-intrinsicvpcwhitelist): List
  [IntrinsicVpceBlacklist](#sam-function-resourcepolicystatement-intrinsicvpceblacklist): List
  [IntrinsicVpceWhitelist](#sam-function-resourcepolicystatement-intrinsicvpcewhitelist): List
  [IpRangeBlacklist](#sam-function-resourcepolicystatement-iprangeblacklist): List
  [IpRangeWhitelist](#sam-function-resourcepolicystatement-iprangewhitelist): List
  [SourceVpcBlacklist](#sam-function-resourcepolicystatement-sourcevpcblacklist): List
  [SourceVpcWhitelist](#sam-function-resourcepolicystatement-sourcevpcwhitelist): List
```

## Properties
<a name="sam-property-function-resourcepolicystatement-properties"></a>

 `AwsAccountBlacklist`   <a name="sam-function-resourcepolicystatement-awsaccountblacklist"></a>
要封锁的 AWS 账户。  
*类型*：字符串列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AwsAccountWhitelist`   <a name="sam-function-resourcepolicystatement-awsaccountwhitelist"></a>
要允许的 AWS 账户。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：字符串列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `CustomStatements`   <a name="sam-function-resourcepolicystatement-customstatements"></a>
适用于此 API 的自定义资源策略语句列表。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpcBlacklist`   <a name="sam-function-resourcepolicystatement-intrinsicvpcblacklist"></a>
要屏蔽的虚拟私有云列表 (VPCs)，其中每个 VPC 都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内部函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpcWhitelist`   <a name="sam-function-resourcepolicystatement-intrinsicvpcwhitelist"></a>
 VPCs 要允许的列表，其中每个 VPC 都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内部函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpceBlacklist`   <a name="sam-function-resourcepolicystatement-intrinsicvpceblacklist"></a>
要阻止的 VPC 端点列表，其中每个 VPC 端点都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内置函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpceWhitelist`   <a name="sam-function-resourcepolicystatement-intrinsicvpcewhitelist"></a>
要允许的 VPC 端点列表，其中每个 VPC 端点都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内置函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IpRangeBlacklist`   <a name="sam-function-resourcepolicystatement-iprangeblacklist"></a>
要阻止的 IP 地址或地址范围。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IpRangeWhitelist`   <a name="sam-function-resourcepolicystatement-iprangewhitelist"></a>
要允许的 IP 地址或地址范围。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceVpcBlacklist`   <a name="sam-function-resourcepolicystatement-sourcevpcblacklist"></a>
要阻止的源 VPC 或 VPC 端点。源 VPC 名称必须以 `"vpc-"` 开头，源 VPC 端点名称必须以 `"vpce-"` 开头。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceVpcWhitelist`   <a name="sam-function-resourcepolicystatement-sourcevpcwhitelist"></a>
要允许的源 VPC 或 VPC 端点。源 VPC 名称必须以 `"vpc-"` 开头，源 VPC 端点名称必须以 `"vpce-"` 开头。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-resourcepolicystatement--examples"></a>

### 资源策略示例
<a name="sam-property-function-resourcepolicystatement--examples--resource-policy-example"></a>

以下示例屏蔽两个 IP 地址和一个源 VPC，并允许一个 AWS 账户。

#### YAML
<a name="sam-property-function-resourcepolicystatement--examples--resource-policy-example--yaml"></a>

```
Auth:
  ResourcePolicy:
    CustomStatements: [{
                         "Effect": "Allow",
                         "Principal": "*",
                         "Action": "execute-api:Invoke",
                         "Resource": "execute-api:/Prod/GET/pets",
                         "Condition": {
                           "IpAddress": {
                             "aws:SourceIp": "1.2.3.4"
                           }
                         }
                       }]
    IpRangeBlacklist:
      - "10.20.30.40"
      - "1.2.3.4"
    SourceVpcBlacklist:
      - "vpce-1a2b3c4d"
    AwsAccountWhitelist:
      - "111122223333"
    IntrinsicVpcBlacklist:
      - "{{resolve:ssm:SomeVPCReference:1}}" 
      - !Ref MyVPC
    IntrinsicVpceWhitelist:
      - "{{resolve:ssm:SomeVPCEReference:1}}" 
      - !Ref MyVPCE
```

# RequestModel
<a name="sam-property-function-requestmodel"></a>

为特定 Api\$1Path\$1 方法配置请求模型。

## 语法
<a name="sam-property-function-requestmodel-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-requestmodel-syntax.yaml"></a>

```
  [Model](#sam-function-requestmodel-model): String
  [Required](#sam-function-requestmodel-required): Boolean
  [ValidateBody](#sam-function-requestmodel-validatebody): Boolean
  [ValidateParameters](#sam-function-requestmodel-validateparameters): Boolean
```

## Properties
<a name="sam-property-function-requestmodel-properties"></a>

 `Model`   <a name="sam-function-requestmodel-model"></a>
在 [AWS::Serverless::Api](sam-resource-api.md) Models 属性中定义的模型的名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Required`   <a name="sam-function-requestmodel-required"></a>
在给定 API 端点的 OpenApi 定义的参数部分中添加一个`required`属性。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ValidateBody`   <a name="sam-function-requestmodel-validatebody"></a>
指定 API Gateway 是否使用 `Model` 验证请求正文。有关更多信息，请参阅*《API Gateway 开发人员指南》*中的[在 API Gateway 中启用请求验证](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html)。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ValidateParameters`   <a name="sam-function-requestmodel-validateparameters"></a>
指定 API Gateway 是否使用 `Model` 验证请求路径参数、查询字符串和标头。有关更多信息，请参阅*《API Gateway 开发人员指南》*中的[在 API Gateway 中启用请求验证](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html)。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-requestmodel--examples"></a>

### 请求模型
<a name="sam-property-function-requestmodel--examples--request-model"></a>

请求模型示例

#### YAML
<a name="sam-property-function-requestmodel--examples--request-model--yaml"></a>

```
RequestModel:
  Model: User
  Required: true
  ValidateBody: true
  ValidateParameters: true
```

# RequestParameter
<a name="sam-property-function-requestparameter"></a>

为特定 Api\$1路径\$1方法配置请求参数。

需要为请求参数指定 `Required` 或 `Caching` 属性

## 语法
<a name="sam-property-function-requestparameter-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-requestparameter-syntax.yaml"></a>

```
  [Caching](#sam-function-requestparameter-caching): Boolean
  [Required](#sam-function-requestparameter-required): Boolean
```

## Properties
<a name="sam-property-function-requestparameter-properties"></a>

 `Caching`   <a name="sam-function-requestparameter-caching"></a>
在 API Gateway OpenApi 定义中添加`cacheKeyParameters`章节  
*类型*：布尔值  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Required`   <a name="sam-function-requestparameter-required"></a>
此字段指定是否需要参数。  
*类型*：布尔值  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-requestparameter--examples"></a>

### 请求参数
<a name="sam-property-function-requestparameter--examples--request-parameter"></a>

设置请求参数的示例

#### YAML
<a name="sam-property-function-requestparameter--examples--request-parameter--yaml"></a>

```
RequestParameters:
  - method.request.header.Authorization:
      Required: true
      Caching: true
```

# CloudWatchEvent
<a name="sam-property-function-cloudwatchevent"></a>

描述 `CloudWatchEvent` 事件源类型的对象。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html)资源。

**重要说明**：[EventBridgeRule](sam-property-function-eventbridgerule.md)是首选使用的事件源类型，而不是`CloudWatchEvent`。 `EventBridgeRule`并`CloudWatchEvent`使用相同的底层服务、API 和 CloudFormation 资源。但是， AWS SAM 将仅向添加对新功能的支持`EventBridgeRule`。

## 语法
<a name="sam-property-function-cloudwatchevent-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-cloudwatchevent-syntax.yaml"></a>

```
  [Enabled](#sam-function-cloudwatchevent-enabled): Boolean
  [EventBusName](#sam-function-cloudwatchevent-eventbusname): String
  [Input](#sam-function-cloudwatchevent-input): String
  [InputPath](#sam-function-cloudwatchevent-inputpath): String
  [Pattern](#sam-function-cloudwatchevent-pattern): [EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)
  [State](#sam-function-cloudwatchevent-state): String
```

## Properties
<a name="sam-property-function-cloudwatchevent-properties"></a>

 `Enabled`   <a name="sam-function-cloudwatchevent-enabled"></a>
指示是否启用规则。  
要禁用该规则，请将此属性设置为 `false`。  
指定 `Enabled` 或 `State` 属性，但不能同时指定两者。
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state)`属性。如果此属性设置为，`true`则 AWS SAM 通过`ENABLED`，否则通过`DISABLED`。

 `EventBusName`   <a name="sam-function-cloudwatchevent-eventbusname"></a>
要与该规则关联的事件总线。如果省略此属性，则 AWS SAM 使用默认的事件总线。  
*类型*：字符串  
*必需*：否  
*默认*：默认事件总线  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventBusName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventbusname)`属性。

 `Input`   <a name="sam-function-cloudwatchevent-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-input)`属性。

 `InputPath`   <a name="sam-function-cloudwatchevent-inputpath"></a>
当您不希望将整个匹配事件传递给目标时，请使用 `InputPath` 属性描述要传递事件的哪一部分。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[InputPath](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath)`属性。

 `Pattern`   <a name="sam-function-cloudwatchevent-pattern"></a>
描述哪些事件路由到指定目标。有关更多信息，请参阅 *Amazon EventBridge 用户指南 EventBridge*[中的事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html)。  
*类型*：[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)`属性。

 `State`   <a name="sam-function-cloudwatchevent-state"></a>
规则的状态。  
*接受的值：*`DISABLED | ENABLED`  
指定 `Enabled` 或 `State` 属性，但不能同时指定两者。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state)`属性。

## 示例
<a name="sam-property-function-cloudwatchevent--examples"></a>

### CloudWatchEvent
<a name="sam-property-function-cloudwatchevent--examples--cloudwatchevent"></a>

以下是 `CloudWatchEvent` 事件源类型的示例。

#### YAML
<a name="sam-property-function-cloudwatchevent--examples--cloudwatchevent--yaml"></a>

```
CWEvent:
  Type: CloudWatchEvent
  Properties:
    Enabled: false
    Input: '{"Key": "Value"}'
    Pattern:
      detail:
        state:
          - running
```

# CloudWatchLogs
<a name="sam-property-function-cloudwatchlogs"></a>

描述 `CloudWatchLogs` 事件源类型的对象。

此事件生成 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-subscriptionfilter.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-subscriptionfilter.html) 资源、指定订阅筛选器并将其与指定的日志组关联。

## 语法
<a name="sam-property-function-cloudwatchlogs-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-cloudwatchlogs-syntax.yaml"></a>

```
  [FilterPattern](#sam-function-cloudwatchlogs-filterpattern): String
  [LogGroupName](#sam-function-cloudwatchlogs-loggroupname): String
```

## Properties
<a name="sam-property-function-cloudwatchlogs-properties"></a>

 `FilterPattern`   <a name="sam-function-cloudwatchlogs-filterpattern"></a>
限制传送到目标 AWS 资源的内容的筛选表达式。有关筛选器模式语法的更多信息，请参阅[筛选器和模式语法](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/FilterAndPatternSyntax.html)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Logs::SubscriptionFilter`资源的`[FilterPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-subscriptionfilter.html#cfn-cwl-subscriptionfilter-filterpattern)`属性。

 `LogGroupName`   <a name="sam-function-cloudwatchlogs-loggroupname"></a>
要与订阅筛选器关联的日志组。如果筛选模式与日志事件匹配，则所有上传到该日志组的日志事件都将被筛选并传送到指定的 AWS 资源。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Logs::SubscriptionFilter`资源的`[LogGroupName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-subscriptionfilter.html#cfn-cwl-subscriptionfilter-loggroupname)`属性。

## 示例
<a name="sam-property-function-cloudwatchlogs--examples"></a>

### Cloudwatchlogs 订阅筛选器
<a name="sam-property-function-cloudwatchlogs--examples--cloudwatchlogs-subscription-filter"></a>

Cloudwatchlog 订阅筛选示例

#### YAML
<a name="sam-property-function-cloudwatchlogs--examples--cloudwatchlogs-subscription-filter--yaml"></a>

```
CWLog:
  Type: CloudWatchLogs
  Properties:
    LogGroupName:
      Ref: CloudWatchLambdaLogsGroup
    FilterPattern: My pattern
```

# Cognito
<a name="sam-property-function-cognito"></a>

描述 `Cognito` 事件源类型的对象。

## 语法
<a name="sam-property-function-cognito-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-cognito-syntax.yaml"></a>

```
  [Trigger](#sam-function-cognito-trigger): List
  [UserPool](#sam-function-cognito-userpool): String
```

## Properties
<a name="sam-property-function-cognito-properties"></a>

 `Trigger`   <a name="sam-function-cognito-trigger"></a>
新用户群体的 Lambda 触发器配置信息。  
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Cognito::UserPool`资源的`[LambdaConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-lambdaconfig.html)`属性。

 `UserPool`   <a name="sam-function-cognito-userpool"></a>
对在同一模板中 UserPool 定义的引用  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-cognito--examples"></a>

### Cognito 事件
<a name="sam-property-function-cognito--examples--cognito-event"></a>

Cognito 事件示例

#### YAML
<a name="sam-property-function-cognito--examples--cognito-event--yaml"></a>

```
CognitoUserPoolPreSignup:
  Type: Cognito
  Properties:
    UserPool:
      Ref: MyCognitoUserPool
    Trigger: PreSignUp
```

# DocumentDB
<a name="sam-property-function-documentdb"></a>

描述 `DocumentDB` 事件源类型的对象。有关更多信息，请参阅*AWS Lambda 开发者*指南中的[AWS Lambda 与亚马逊 DocumentDB 配合使用](https://docs.aws.amazon.com/lambda/latest/dg/with-documentdb.html)。

## 语法
<a name="sam-property-function-documentdb-syntax"></a>

要在 AWS SAM 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-documentdb-syntax-yaml"></a>

```
BatchSize: Integer
Cluster: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
CollectionName: String
DatabaseName: String
Enabled: Boolean
FilterCriteria: [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
FullDocument: String
KmsKeyArn: String  
MaximumBatchingWindowInSeconds: Integer
SecretsManagerKmsKeyId: String
SourceAccessConfigurations: List
StartingPosition: String
StartingPositionTimestamp: Double
```

## Properties
<a name="sam-property-function-documentdb-properties"></a>

 `BatchSize`   <a name="sam-function-documentdb-batchsize"></a>
要在单个批次中检索的最大项目数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)`属性。

 `Cluster`   <a name="sam-function-documentdb-cluster"></a>
Amazon DocumentDB 集群的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ EventSourceArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn)`属性。

 `CollectionName`   <a name="sam-function-documentdb-collectionname"></a>
将使用的数据库中集合的名称。如果您未指定集合，Lambda 会使用所有集合。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping``DocumentDBEventSourceConfig`数据类型的`[ CollectionName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-documentdbeventsourceconfig.html#cfn-lambda-eventsourcemapping-documentdbeventsourceconfig-collectionname)`属性。

 `DatabaseName`   <a name="sam-function-documentdb-databasename"></a>
将使用的 Amazon DocumentDB 集群中数据库的名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping``DocumentDBEventSourceConfig`数据类型的`[ DatabaseName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-documentdbeventsourceconfig.html#cfn-lambda-eventsourcemapping-documentdbeventsourceconfig-databasename)`属性。

 `Enabled`   <a name="sam-function-documentdb-enabled"></a>
如果为 `true`，则事件源映射处于活动状态。要暂停轮询和调用，设置为 `false`。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)`属性。

 `FilterCriteria`   <a name="sam-function-documentdb-filtercriteria"></a>
定义用于确定 Lambda 是否应处理事件的条件的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的 [Lambda 事件筛选](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*类型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)`属性。

 `FullDocument`   <a name="sam-function-documentdb-fulldocument"></a>
确定 Amazon DocumentDB 在文档更新操作期间将向您的事件流发送的内容。如果设置为 `UpdateLookup`，Amazon DocumentDB 将发送一个描述所发生更改的增量以及完整文档的副本。否则，Amazon DocumentDB 将仅发送包含更改的部分文档。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping``DocumentDBEventSourceConfig`数据类型的`[ FullDocument](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-documentdbeventsourceconfig.html#cfn-lambda-eventsourcemapping-documentdbeventsourceconfig-fulldocument)`属性。

 `KmsKeyArn`   <a name="sam-function-documentdb-kmskeyarn"></a>
用于加密与此事件相关信息的密钥的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)`属性。

 `MaximumBatchingWindowInSeconds`   <a name="sam-function-documentdb-maximumbatchingwindowinseconds"></a>
在调用函数之前收集记录的最长时间（以秒为单位）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ MaximumBatchingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds)`属性。

 `SecretsManagerKmsKeyId`   <a name="sam-function-documentdb-secretsmanagerkmskeyid"></a>
来自 Secrets Manager 的客户托管密钥的 AWS Key Management Service (AWS KMS) AWS 密钥 ID。当您以不包含 `kms:Decrypt` 权限的 Lambda 执行角色使用来自 Secrets Manager 的客户托管密钥时，此为必需。  
此属性的值为 UUID。例如：`1abc23d4-567f-8ab9-cde0-1fab234c5d67`。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceAccessConfigurations`   <a name="sam-function-documentdb-sourceaccessconfigurations"></a>
身份验证协议或虚拟主机的数组。使用[SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-sourceaccessconfiguration.html)数据类型进行指定。  
对于 `DocumentDB` 事件源类型，唯一有效的配置类型是 `BASIC_AUTH`。  
+ `BASIC_AUTH` – 存储您的代理凭证的 Secrets Manager 密钥。要使用此类型，凭证必须采用以下格式：`{"username": "your-username", "password": "your-password"}`。只允许使用一个类型为 `BASIC_AUTH` 的对象。
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-sourceaccessconfigurations)`属性。

 `StartingPosition`   <a name="sam-function-documentdb-startingposition"></a>
在流中开始读取数据的位置。  
+ `AT_TIMESTAMP` – 指定开始读取记录的时间。
+ `LATEST` - 仅读取新记录。
+ `TRIM_HORIZON` - 处理所有可用的记录。
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ StartingPosition](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingposition)`属性。

 `StartingPositionTimestamp`   <a name="sam-function-documentdb-startingpositiontimestamp"></a>
开始读取的时间（以 Unix 时间秒为单位） 在 `StartingPosition` 被指定为 `AT_TIMESTAMP` 的情况下定义 `StartingPositionTimestamp`。  
*类型*：双精度  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ StartingPositionTimestamp](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingpositiontimestamp)`属性。

## 示例
<a name="sam-property-function-documentdb-examples"></a>

### Amazon DocumentDB 事件源
<a name="sam-property-function-documentdb-examples-example1"></a>

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
    ...
      Events:
        MyDDBEvent:
          Type: DocumentDB
          Properties:
            Cluster: "arn:aws:rds:us-west-2:123456789012:cluster:docdb-2023-01-01"
            BatchSize: 10
            MaximumBatchingWindowInSeconds: 5
            DatabaseName: "db1"
            CollectionName: "collection1"
            FullDocument: "UpdateLookup"
            SourceAccessConfigurations:
              - Type: BASIC_AUTH
                URI: "arn:aws:secretsmanager:us-west-2:123456789012:secret:doc-db"
```

# DynamoDB
<a name="sam-property-function-dynamodb"></a>

描述 `DynamoDB` 事件源类型的对象。*有关更多信息，请参阅开发者指南中的[AWS LambdaAWS Lambda 与亚马逊 DynamoDB 搭配使用](https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html)。*

AWS SAM 设置此事件类型时会生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)资源。

## 语法
<a name="sam-property-function-dynamodb-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-dynamodb-syntax.yaml"></a>

```
  [BatchSize](#sam-function-dynamodb-batchsize): Integer
  [BisectBatchOnFunctionError](#sam-function-dynamodb-bisectbatchonfunctionerror): Boolean
  [DestinationConfig](#sam-function-dynamodb-destinationconfig): [DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-destinationconfig)
  [Enabled](#sam-function-dynamodb-enabled): Boolean
  [FilterCriteria](#sam-function-dynamodb-filtercriteria): [FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
  [FunctionResponseTypes](#sam-function-dynamodb-functionresponsetypes): List
  KmsKeyArn: String          
  [MaximumBatchingWindowInSeconds](#sam-function-dynamodb-maximumbatchingwindowinseconds): Integer
  [MaximumRecordAgeInSeconds](#sam-function-dynamodb-maximumrecordageinseconds): Integer
  [MaximumRetryAttempts](#sam-function-dynamodb-maximumretryattempts): Integer
  [MetricsConfig](#sam-function-dynamodb-metricsconfig): [MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)
  [ParallelizationFactor](#sam-function-dynamodb-parallelizationfactor): Integer
  [StartingPosition](#sam-function-dynamodb-startingposition): String
  StartingPositionTimestamp: Double
  [Stream](#sam-function-dynamodb-stream): String
  [TumblingWindowInSeconds](#sam-function-dynamodb-tumblingwindowinseconds): Integer
```

## Properties
<a name="sam-property-function-dynamodb-properties"></a>

 `BatchSize`   <a name="sam-function-dynamodb-batchsize"></a>
要在单个批次中检索的最大项目数。  
*类型*：整数  
*必需*：否  
*默认值*：100  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)`属性。  
*最小值*：`1`  
*最大值*：`1000`

 `BisectBatchOnFunctionError`   <a name="sam-function-dynamodb-bisectbatchonfunctionerror"></a>
如果函数返回错误，则将批次拆分为两批并重试。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BisectBatchOnFunctionError](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-bisectbatchonfunctionerror)`属性。

 `DestinationConfig`   <a name="sam-function-dynamodb-destinationconfig"></a>
丢弃的记录的 Amazon Simple Queue Service (Amazon SQS) 队列或 Amazon Simple Notiﬁcation Service (Amazon SNS)主题目标。  
*类型*：[DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-destinationconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-destinationconfig)`属性。

 `Enabled`   <a name="sam-function-dynamodb-enabled"></a>
禁用事件源映射以暂停轮询和调用。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)`属性。

 `FilterCriteria`   <a name="sam-function-dynamodb-filtercriteria"></a>
定义用于确定 Lambda 是否应处理事件的条件的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的 [AWS Lambda 事件筛选](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*类型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)`属性。

 `FunctionResponseTypes`   <a name="sam-function-dynamodb-functionresponsetypes"></a>
当前应用于事件源映射的响应类型的列表。有关详细信息，请参阅《AWS Lambda 开发人员指南》**中的[报告批处理项目失败](https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#services-ddb-batchfailurereporting)。  
*有效值*：`ReportBatchItemFailures`  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FunctionResponseTypes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-functionresponsetypes)`属性。

 `KmsKeyArn`   <a name="sam-function-dynamodb-kmskeyarn"></a>
用于加密与此事件相关信息的密钥的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)`属性。

 `MaximumBatchingWindowInSeconds`   <a name="sam-function-dynamodb-maximumbatchingwindowinseconds"></a>
在调用函数之前收集记录的最长时间（以秒为单位）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumBatchingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds)`属性。

 `MaximumRecordAgeInSeconds`   <a name="sam-function-dynamodb-maximumrecordageinseconds"></a>
Lambda 发送到函数以进行处理的记录的最长期限。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumRecordAgeInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumrecordageinseconds)`属性。

 `MaximumRetryAttempts`   <a name="sam-function-dynamodb-maximumretryattempts"></a>
在函数返回错误时重试的最大次数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumRetryAttempts](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumretryattempts)`属性。

 `MetricsConfig`   <a name="sam-function-dynamodb-metricsconfig"></a>
一种选择性配置，用于获取增强型指标，这些指标针对事件源映射进行捕获，涵盖处理过程的每个阶段。有关示例，请参阅[MetricsConfig 事件](#sam-property-function-dynamodb-example-metricsconfigevent)。  
*类型*：[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)`属性。

 `ParallelizationFactor`   <a name="sam-function-dynamodb-parallelizationfactor"></a>
要从每个分片中同时处理的批次数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ParallelizationFactor](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-parallelizationfactor)`属性。

 `StartingPosition`   <a name="sam-function-dynamodb-startingposition"></a>
在流中开始读取数据的位置。  
+ `AT_TIMESTAMP` – 指定开始读取记录的时间。
+ `LATEST` - 仅读取新记录。
+ `TRIM_HORIZON` - 处理所有可用的记录。
*有效值*：`AT_TIMESTAMP` \$1 `LATEST` \$1 `TRIM_HORIZON`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[StartingPosition](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingposition)`属性。

 `StartingPositionTimestamp`   <a name="sam-function-dynamodb-startingpositiontimestamp"></a>
开始读取的时间（以 Unix 时间秒为单位） 在 `StartingPosition` 被指定为 `AT_TIMESTAMP` 的情况下定义 `StartingPositionTimestamp`。  
*类型*：双精度  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[StartingPositionTimestamp](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingpositiontimestamp)`属性。

 `Stream`   <a name="sam-function-dynamodb-stream"></a>
DynamoDB 流的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[EventSourceArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn)`属性。

 `TumblingWindowInSeconds`   <a name="sam-function-dynamodb-tumblingwindowinseconds"></a>
处理窗口的持续时间（以秒为单位）。有效范围为 1 到 900（15 分钟）。  
有关更多信息，请参阅《AWS Lambda 开发人员指南》**的[滚动窗口](https://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html#streams-tumbling)。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[TumblingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-tumblingwindowinseconds)`属性。

## 示例
<a name="sam-property-function-dynamodb--examples"></a>

### MetricsConfig 事件
<a name="sam-property-function-dynamodb-example-metricsconfigevent"></a>

以下是一个资源示例，它使用 `MetricsConfig` 属性来捕获其事件源映射的每个处理阶段。

```
Resources:
  FilteredEventsFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: s3://sam-demo-bucket/metricsConfig.zip
      Handler: index.handler
      Runtime: nodejs16.x
      Events:
        KinesisStream:
          Type: Kinesis
          Properties:
            Stream: !GetAtt KinesisStream.Arn
            StartingPosition: LATEST
            MetricsConfig:
              Metrics:
              - EventCount
```

### 现有 DynamoDB 表的 DynamoDB 事件源
<a name="sam-property-function-dynamodb--examples--dynamodb-event-source-for-existing-dynamodb-table"></a>

账户中已存在的 DynamoDB 表的 DynamoDB 事件源。 AWS 

#### YAML
<a name="sam-property-function-dynamodb--examples--dynamodb-event-source-for-existing-dynamodb-table--yaml"></a>

```
Events:
  DDBEvent:
    Type: DynamoDB
    Properties:
      Stream: arn:aws:dynamodb:us-east-1:123456789012:table/TestTable/stream/2016-08-11T21:21:33.291
      StartingPosition: TRIM_HORIZON
      BatchSize: 10
      Enabled: false
```

### 模板中声明的 DynamoDB 表的 DynamoDB 事件
<a name="sam-property-function-dynamodb--examples--dynamodb-event-for-dynamodb-table-declared-in-template"></a>

在同一模板文件中声明的 DynamoDB 表的 DynamoDB 事件。

#### YAML
<a name="sam-property-function-dynamodb--examples--dynamodb-event-for-dynamodb-table-declared-in-template--yaml"></a>

```
Events:
  DDBEvent:
    Type: DynamoDB
    Properties:
      Stream: 
        !GetAtt MyDynamoDBTable.StreamArn   # This must be the name of a DynamoDB table declared in the same template file
      StartingPosition: TRIM_HORIZON
      BatchSize: 10
      Enabled: false
```

# EventBridgeRule
<a name="sam-property-function-eventbridgerule"></a>

描述`EventBridgeRule`事件源类型的对象，它将您的无服务器函数设置为 Amazon EventBridge 规则的目标。有关更多信息，请参阅[什么是亚马逊 EventBridge？](https://docs.aws.amazon.com/eventbridge/latest/userguide/what-is-amazon-eventbridge.html) 在《*亚马逊 EventBridge 用户指南》*中。

AWS SAM 设置此事件类型时会生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html)资源。 AWS SAM 还会创建`AWS::Lambda::Permission`资源，该资源是调用 Lambda 所`EventBridgeRule`必需的。

## 语法
<a name="sam-property-function-eventbridgerule-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-eventbridgerule-syntax.yaml"></a>

```
  [DeadLetterConfig](#sam-function-eventbridgerule-deadletterconfig): DeadLetterConfig
  [EventBusName](#sam-function-eventbridgerule-eventbusname): String
  [Input](#sam-function-eventbridgerule-input): String
  [InputPath](#sam-function-eventbridgerule-inputpath): String
  InputTransformer: [InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-inputtransformer.html)
  [Pattern](#sam-function-eventbridgerule-pattern): [EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)
  [RetryPolicy](#sam-function-eventbridgerule-retrypolicy): [RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)
  RuleName: String 
  State: String
  [Target](#sam-function-eventbridgerule-target): Target
```

## Properties
<a name="sam-property-function-eventbridgerule-properties"></a>

 `DeadLetterConfig`   <a name="sam-function-eventbridgerule-deadletterconfig"></a>
配置亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的 Lambda 函数发送事件时，或者没有足够的权限调用 Lambda 函数 EventBridge 时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
[AWS::Serverless::Function](sam-resource-function.md) 资源类型具有类似的数据类型 `DeadLetterQueue`，用于处理成功调用目标 Lambda 函数后发生的故障。这些类型的故障示例包括 Lambda 节流或 Lambda 目标函数返回的错误。有关函数 `DeadLetterQueue` 属性的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-dlq)。
*类型*：[DeadLetterConfig](sam-property-function-deadletterconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule``Target`数据类型的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-deadletterconfig)`属性。此属性的 AWS SAM 版本包括其他子属性， AWS SAM 以备您想要创建死信队列时使用。

 `EventBusName`   <a name="sam-function-eventbridgerule-eventbusname"></a>
要与该规则关联的事件总线。如果省略此属性，则 AWS SAM 使用默认的事件总线。  
*类型*：字符串  
*必需*：否  
*默认*：默认事件总线  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventBusName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventbusname)`属性。

 `Input`   <a name="sam-function-eventbridgerule-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-input)`属性。

 `InputPath`   <a name="sam-function-eventbridgerule-inputpath"></a>
当您不希望将整个匹配事件传递给目标时，请使用 `InputPath` 属性描述要传递事件的哪一部分。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[InputPath](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath)`属性。

 `InputTransformer`   <a name="sam-function-eventbridgerule-inputtransformer"></a>
使您可以根据特定事件数据向目标提供自定义输入的设置。您可以从事件中提取一个或多个键值对，然后使用该数据将自定义输入发送到目标。有关更多信息，请参阅[亚马逊* EventBridge 用户指南中的亚马逊 EventBridge *输入转换](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html)。  
*类型*：[InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputtransformer)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-inputtransformer.html)`属性。

 `Pattern`   <a name="sam-function-eventbridgerule-pattern"></a>
描述哪些事件路由到指定目标。有关更多信息，请参阅[亚马逊* EventBridge 用户指南中的亚马逊 EventBridgeEventBridge *事件](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events.html)[和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-event-patterns.html)。  
*类型*：[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)`属性。

 `RetryPolicy`   <a name="sam-function-eventbridgerule-retrypolicy"></a>
包含有关重试策略设置的信息的 `RetryPolicy` 对象。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
*类型*：[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)`属性。

 `RuleName`   <a name="sam-function-eventbridgerule-rulename"></a>
 规则的名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-name)`属性。

 `State`   <a name="sam-function-eventbridgerule-state"></a>
规则的状态。  
*接受的值*：`DISABLED` \$1 `ENABLED` \$1 `ENABLED_WITH_ALL_CLOUDTRAIL_MANAGEMENT_EVENTS`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state) `属性。

 `Target`   <a name="sam-function-eventbridgerule-target"></a>
触发规则时 EventBridge 调用的 AWS 资源。您可以使用此属性来指定目标的逻辑 ID。如果未指定此属性，则 AWS SAM 生成目标的逻辑 ID。  
*类型*：[目标](sam-property-function-target.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule`资源的`[Targets](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-targets)`属性。 `Amazon EC2 RebootInstances API call`是目标属性的示例。此属性的 AWS SAM 版本仅允许您指定单个目标的逻辑 ID。

## 示例
<a name="sam-property-function-eventbridgerule--examples"></a>

### EventBridgeRule
<a name="sam-property-function-eventbridgerule--examples--eventbridgerule"></a>

以下是 `EventBridgeRule` 事件源类型的示例。

#### YAML
<a name="sam-property-function-eventbridgerule--examples--eventbridgerule--yaml"></a>

```
EBRule:
  Type: EventBridgeRule
  Properties:
    Input: '{"Key": "Value"}'
    Pattern:
      detail:
        state:
          - terminated
    RetryPolicy:
      MaximumRetryAttempts: 5
      MaximumEventAgeInSeconds: 900
    DeadLetterConfig:
      Type: SQS
      QueueLogicalId: EBRuleDLQ
    Target:
      Id: MyTarget
```

# DeadLetterConfig
<a name="sam-property-function-deadletterconfig"></a>

该对象用于指定亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，在向不存在的 Lambda 函数发送事件或调用 Lambda 函数的权限不足时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。

**注意**  
[AWS::Serverless::Function](sam-resource-function.md) 资源类型具有类似的数据类型 `DeadLetterQueue`，用于处理成功调用目标 Lambda 函数后发生的故障。此类故障的示例包括 Lambda 节流或 Lambda 目标函数返回的错误。有关函数 `DeadLetterQueue` 属性的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-dlq)。

## 语法
<a name="sam-property-function-deadletterconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-deadletterconfig-syntax.yaml"></a>

```
  [Arn](#sam-function-deadletterconfig-arn): String
  [QueueLogicalId](#sam-function-deadletterconfig-queuelogicalid): String
  [Type](#sam-function-deadletterconfig-type): String
```

## Properties
<a name="sam-property-function-deadletterconfig-properties"></a>

 `Arn`   <a name="sam-function-deadletterconfig-arn"></a>
指定作为死信队列目标的 Amazon SQS 队列的 Amazon 资源名称（ARN）。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``DeadLetterConfig`数据类型的`[Arn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-deadletterconfig.html#cfn-events-rule-deadletterconfig-arn)`属性。

 `QueueLogicalId`   <a name="sam-function-deadletterconfig-queuelogicalid"></a>
指定了 AWS SAM 创建的死信队列的自定义名称。`Type`  
如果未设置 `Type` 属性，则将忽略该属性。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Type`   <a name="sam-function-deadletterconfig-type"></a>
队列的类型。设置此属性后， AWS SAM 会自动创建死信队列并附加必要的[基于资源的策略](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html#dlq-perms)，以授予规则资源向队列发送事件的权限。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*有效值*：`SQS`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-deadletterconfig--examples"></a>

### DeadLetterConfig
<a name="sam-property-function-deadletterconfig--examples--deadletterconfig"></a>

DeadLetterConfig

#### YAML
<a name="sam-property-function-deadletterconfig--examples--deadletterconfig--yaml"></a>

```
DeadLetterConfig:
  Type: SQS
  QueueLogicalId: MyDLQ
```

# Target
<a name="sam-property-function-target"></a>

配置触发规则时 EventBridge 调用的 AWS 资源。

## 语法
<a name="sam-property-function-target-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-target-syntax.yaml"></a>

```
  [Id](#sam-function-target-id): String
```

## Properties
<a name="sam-property-function-target-properties"></a>

 `Id`   <a name="sam-function-target-id"></a>
目标的逻辑 ID。  
`Id` 的值可以包含字母数字字符、句点 (`.`)、连字符 (`-`) 和下划线 (`_`)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[Id](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-id)`属性。

## 示例
<a name="sam-property-function-target--examples"></a>

### Target
<a name="sam-property-function-target--examples--target"></a>

#### YAML
<a name="sam-property-function-target--examples--target--yaml"></a>

```
EBRule:
  Type: EventBridgeRule
  Properties:
    Target:
      Id: MyTarget
```

# HttpApi
<a name="sam-property-function-httpapi"></a>

描述带有类型的事件源的对象 HttpApi。

如果 API 上存在指定路径和方法的 OpenApi 定义，SAM 将为您添加 Lambda 集成和安全部分（如果适用）。

如果 API 上没有指定路径和方法的 OpenApi 定义，SAM 将为您创建此定义。

## 语法
<a name="sam-property-function-httpapi-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-httpapi-syntax.yaml"></a>

```
  [ApiId](#sam-function-httpapi-apiid): String
  [Auth](#sam-function-httpapi-auth): HttpApiFunctionAuth
  [Method](#sam-function-httpapi-method): String
  [Path](#sam-function-httpapi-path): String
  [PayloadFormatVersion](#sam-function-httpapi-payloadformatversion): String
  [RouteSettings](#sam-function-httpapi-routesettings): [RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)
  [TimeoutInMillis](#sam-function-httpapi-timeoutinmillis): Integer
```

## Properties
<a name="sam-property-function-httpapi-properties"></a>

 `ApiId`   <a name="sam-function-httpapi-apiid"></a>
此模板中定义的 [AWS::Serverless::HttpApi](sam-resource-httpapi.md) 资源的标识符。  
如果未定义，则`ServerlessHttpApi`使用生成的 OpenApi 文档创建默认[AWS::Serverless::HttpApi](sam-resource-httpapi.md)资源，该文档包含由此模板中定义的 Api 事件定义的所有路径和方法的并集，这些路径和方法未指定`ApiId`。  
这不能引用其他模板中定义的 [AWS::Serverless::HttpApi](sam-resource-httpapi.md) 资源。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Auth`   <a name="sam-function-httpapi-auth"></a>
此特定 Api\$1路径\$1方法的身份验证配置。  
在未指定 `DefaultAuthorizer` 的情况下，对于覆盖 API 的 `DefaultAuthorizer` 或在各个路径中设置身份验证配置很有用。  
*类型*：[HttpApiFunctionAuth](sam-property-function-httpapifunctionauth.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Method`   <a name="sam-function-httpapi-method"></a>
调用此函数的 HTTP 方法。  
如果未指定 `Path` 和 `Method`，SAM 会创建默认 API 路径，用于将未映射到其他端点的任何请求路由到此 Lambda 函数。每个 API 只能存在其中一个默认路径。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Path`   <a name="sam-function-httpapi-path"></a>
调用此函数的 URI 路径。必须以 `/` 开头。  
如果未指定 `Path` 和 `Method`，SAM 会创建默认 API 路径，用于将未映射到其他端点的任何请求路由到此 Lambda 函数。每个 API 只能存在其中一个默认路径。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `PayloadFormatVersion`   <a name="sam-function-httpapi-payloadformatversion"></a>
指定发送到集成的有效负载的格式。  
注意： PayloadFormatVersion 需要 SAM 修改您的 OpenAPI 定义，因此它仅适用于属性中 OpenApi 定义的内联定义。`DefinitionBody`  
*类型*：字符串  
*必需*：否  
*默认值*：2.0  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `RouteSettings`   <a name="sam-function-httpapi-routesettings"></a>
此 HTTP API 的每条路径的路由设置。有关路由设置的更多信息，请参阅 *API Gateway 开发者指南[AWS::ApiGatewayV2::Stage RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-stage-routesettings.html)*中的。  
注意：如果 RouteSettings 在 HttpApi 资源和事件源中同时指定，则将其 AWS SAM 合并，优先使用事件源属性。  
*类型*：[RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Stage`资源的`[RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)`属性。

 `TimeoutInMillis`   <a name="sam-function-httpapi-timeoutinmillis"></a>
自定义超时值，范围在 50 到 29,000 毫秒之间。  
注意： TimeoutInMillis 需要 SAM 修改您的 OpenAPI 定义，因此它仅适用于属性中 OpenApi 定义的内联定义。`DefinitionBody`  
*类型*：整数  
*必需*：否  
*默认值*：5000  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-httpapi--examples"></a>

### 默认 HttpApi 事件
<a name="sam-property-function-httpapi--examples--default-httpapi-event"></a>

HttpApi 使用默认路径的事件。此 API 中所有未映射的路径和方法都将路由到此端点。

#### YAML
<a name="sam-property-function-httpapi--examples--default-httpapi-event--yaml"></a>

```
Events:
  HttpApiEvent:
    Type: HttpApi
```

### HttpApi
<a name="sam-property-function-httpapi--examples--httpapi"></a>

HttpApi 使用特定路径和方法的事件。

#### YAML
<a name="sam-property-function-httpapi--examples--httpapi--yaml"></a>

```
Events:
  HttpApiEvent:
    Type: HttpApi
    Properties:
      Path: /
      Method: GET
```

### HttpApi 授权
<a name="sam-property-function-httpapi--examples--httpapi-authorization"></a>

HttpApi 使用授权者的事件。

#### YAML
<a name="sam-property-function-httpapi--examples--httpapi-authorization--yaml"></a>

```
Events:
  HttpApiEvent:
    Type: HttpApi
    Properties:
      Path: /authenticated
      Method: GET
      Auth:
        Authorizer: OpenIdAuth
        AuthorizationScopes:
          - scope1
          - scope2
```

# HttpApiFunctionAuth
<a name="sam-property-function-httpapifunctionauth"></a>

在事件级别配置授权。

为特定 API\$1路径\$1方法配置身份验证

## 语法
<a name="sam-property-function-httpapifunctionauth-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-httpapifunctionauth-syntax.yaml"></a>

```
  [AuthorizationScopes](#sam-function-httpapifunctionauth-authorizationscopes): List
  [Authorizer](#sam-function-httpapifunctionauth-authorizer): String
```

## Properties
<a name="sam-property-function-httpapifunctionauth-properties"></a>

 `AuthorizationScopes`   <a name="sam-function-httpapifunctionauth-authorizationscopes"></a>
适用于此 API、路径和方法的授权范围。  
此处列出的范围将覆盖`DefaultAuthorizer`应用的任何范围（如果存在）。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Authorizer`   <a name="sam-function-httpapifunctionauth-authorizer"></a>
特定函数的`Authorizer`。要使用 IAM 授权，请在模板的 `Globals` 部分指定 `AWS_IAM`，并为 `EnableIamAuthorizer` 指定 `true`。  
如果您已在 API 中指定了全局授权方并想公开特定函数，请通过将 `Authorizer` 设置为 `NONE` 来覆盖。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-httpapifunctionauth--examples"></a>

### 函数身份验证
<a name="sam-property-function-httpapifunctionauth--examples--function-auth"></a>

在函数级别指定授权

#### YAML
<a name="sam-property-function-httpapifunctionauth--examples--function-auth--yaml"></a>

```
Auth:
  Authorizer: OpenIdAuth
  AuthorizationScopes:
    - scope1
    - scope2
```

### IAM 授权
<a name="sam-property-function-httpapifunctionauth--examples--iam-authorization"></a>

在事件级别指定 IAM 授权。要在事件级别使用 `AWS_IAM` 授权，还必须在模板的 `Globals` 部分为 `EnableIamAuthorizer` 指定 `true`。有关更多信息，请参阅 [模板的 “全局” 部分 AWS SAM](sam-specification-template-anatomy-globals.md)。

#### YAML
<a name="sam-property-function-httpapifunctionauth--examples--iam-authorization--yaml"></a>

```
Globals:
  HttpApi:
    Auth:
      EnableIamAuthorizer: true

Resources:
  HttpApiFunctionWithIamAuth:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        ApiEvent:
          Type: HttpApi
          Properties:
            Path: /iam-auth
            Method: GET
            Auth:
              Authorizer: AWS_IAM
      Handler: index.handler
      InlineCode: |
        def handler(event, context):
          return {'body': 'HttpApiFunctionWithIamAuth', 'statusCode': 200}
      Runtime: python3.9
```

# IoTRule
<a name="sam-property-function-iotrule"></a>

描述 `IoTRule` 事件源类型的对象。

创建用于声明 AWS IoT 规则的[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iot-topicrule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iot-topicrule.html)资源。有关更多信息，请参阅 [CloudFormation 文档](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iot-topicrule.html)

## 语法
<a name="sam-property-function-iotrule-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-iotrule-syntax.yaml"></a>

```
  [AwsIotSqlVersion](#sam-function-iotrule-awsiotsqlversion): String
  [Sql](#sam-function-iotrule-sql): String
```

## Properties
<a name="sam-property-function-iotrule-properties"></a>

 `AwsIotSqlVersion`   <a name="sam-function-iotrule-awsiotsqlversion"></a>
评估规则时使用的 SQL 规则引擎的版本。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IoT::TopicRule TopicRulePayload`资源的`[AwsIotSqlVersion](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-iot-topicrule-topicrulepayload.html#cfn-iot-topicrule-topicrulepayload-awsiotsqlversion)`属性。

 `Sql`   <a name="sam-function-iotrule-sql"></a>
用于查询主题的 SQL 语句。有关更多信息，请参阅《AWS IoT 开发人员指南》**中的[AWS IoT SQL 参考](https://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html#aws-iot-sql-reference)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IoT::TopicRule TopicRulePayload`资源的`[Sql](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-iot-topicrule-topicrulepayload.html#cfn-iot-topicrule-topicrulepayload-sql)`属性。

## 示例
<a name="sam-property-function-iotrule--examples"></a>

### IoT 规则
<a name="sam-property-function-iotrule--examples--iot-rule"></a>

IoT 规则示例

#### YAML
<a name="sam-property-function-iotrule--examples--iot-rule--yaml"></a>

```
IoTRule:
  Type: IoTRule
  Properties:
    Sql: SELECT * FROM 'topic/test'
```

# Kinesis
<a name="sam-property-function-kinesis"></a>

描述 `Kinesis` 事件源类型的对象。有关更多信息，请参阅《*AWS Lambda 开发者*指南》中的[AWS Lambda 与 Amazon Kinesis 配合使用](https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html)。

AWS SAM 设置此事件类型时会生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)资源。

## 语法
<a name="sam-property-function-kinesis-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-kinesis-syntax.yaml"></a>

```
  [BatchSize](#sam-function-kinesis-batchsize): Integer
  [BisectBatchOnFunctionError](#sam-function-kinesis-bisectbatchonfunctionerror): Boolean
  [DestinationConfig](#sam-function-kinesis-destinationconfig): [DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-destinationconfig)
  [Enabled](#sam-function-kinesis-enabled): Boolean
  [FilterCriteria](#sam-function-kinesis-filtercriteria): [FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
  [FunctionResponseTypes](#sam-function-kinesis-functionresponsetypes): List
  KmsKeyArn: String          
  [MaximumBatchingWindowInSeconds](#sam-function-kinesis-maximumbatchingwindowinseconds): Integer
  [MaximumRecordAgeInSeconds](#sam-function-kinesis-maximumrecordageinseconds): Integer
  [MaximumRetryAttempts](#sam-function-kinesis-maximumretryattempts): Integer
  [MetricsConfig](#sam-function-kinesis-metricsconfig): [MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)
  [ParallelizationFactor](#sam-function-kinesis-parallelizationfactor): Integer
  [StartingPosition](#sam-function-kinesis-startingposition): String
  StartingPositionTimestamp: Double
  [Stream](#sam-function-kinesis-stream): String
  [TumblingWindowInSeconds](#sam-function-kinesis-tumblingwindowinseconds): Integer
```

## Properties
<a name="sam-property-function-kinesis-properties"></a>

 `BatchSize`   <a name="sam-function-kinesis-batchsize"></a>
要在单个批次中检索的最大项目数。  
*类型*：整数  
*必需*：否  
*默认值*：100  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)`属性。  
*最小值*：`1`  
*最大值*：`10000`

 `BisectBatchOnFunctionError`   <a name="sam-function-kinesis-bisectbatchonfunctionerror"></a>
如果函数返回错误，则将批次拆分为两批并重试。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BisectBatchOnFunctionError](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-bisectbatchonfunctionerror)`属性。

 `DestinationConfig`   <a name="sam-function-kinesis-destinationconfig"></a>
丢弃的记录的 Amazon Simple Queue Service (Amazon SQS) 队列或 Amazon Simple Notiﬁcation Service (Amazon SNS)主题目标。  
*类型*：[DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-destinationconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-destinationconfig)`属性。

 `Enabled`   <a name="sam-function-kinesis-enabled"></a>
禁用事件源映射以暂停轮询和调用。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)`属性。

 `FilterCriteria`   <a name="sam-function-kinesis-filtercriteria"></a>
定义用于确定 Lambda 是否应处理事件的条件的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的 [AWS Lambda 事件筛选](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*类型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)`属性。

 `FunctionResponseTypes`   <a name="sam-function-kinesis-functionresponsetypes"></a>
当前应用于事件源映射的响应类型的列表。有关详细信息，请参阅《AWS Lambda 开发人员指南》**中的[报告批处理项目失败](https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html#services-kinesis-batchfailurereporting)。  
*有效值*：`ReportBatchItemFailures`  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FunctionResponseTypes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-functionresponsetypes)`属性。

 `KmsKeyArn`   <a name="sam-function-kinesis-kmskeyarn"></a>
用于加密与此事件相关信息的密钥的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)`属性。

 `MaximumBatchingWindowInSeconds`   <a name="sam-function-kinesis-maximumbatchingwindowinseconds"></a>
在调用函数之前收集记录的最长时间（以秒为单位）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumBatchingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds)`属性。

 `MaximumRecordAgeInSeconds`   <a name="sam-function-kinesis-maximumrecordageinseconds"></a>
Lambda 发送到函数以进行处理的记录的最长期限。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumRecordAgeInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumrecordageinseconds)`属性。

 `MaximumRetryAttempts`   <a name="sam-function-kinesis-maximumretryattempts"></a>
在函数返回错误时重试的最大次数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumRetryAttempts](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumretryattempts)`属性。

 `MetricsConfig`   <a name="sam-function-kinesis-metricsconfig"></a>
一种选择性配置，用于获取增强型指标，这些指标针对事件源映射进行捕获，涵盖处理过程的每个阶段。有关示例，请参阅[MetricsConfig 事件](sam-property-function-dynamodb.md#sam-property-function-dynamodb-example-metricsconfigevent)。  
*类型*：[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)`属性。

 `ParallelizationFactor`   <a name="sam-function-kinesis-parallelizationfactor"></a>
要从每个分片中同时处理的批次数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ParallelizationFactor](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-parallelizationfactor)`属性。

 `StartingPosition`   <a name="sam-function-kinesis-startingposition"></a>
在流中开始读取数据的位置。  
+ `AT_TIMESTAMP` – 指定开始读取记录的时间。
+ `LATEST` - 仅读取新记录。
+ `TRIM_HORIZON` - 处理所有可用的记录。
*有效值*：`AT_TIMESTAMP` \$1 `LATEST` \$1 `TRIM_HORIZON`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[StartingPosition](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingposition)`属性。

 `StartingPositionTimestamp`   <a name="sam-function-kinesis-startingpositiontimestamp"></a>
开始读取的时间（以 Unix 时间秒为单位） 在 `StartingPosition` 被指定为 `AT_TIMESTAMP` 的情况下定义 `StartingPositionTimestamp`。  
*类型*：双精度  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[StartingPositionTimestamp](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingpositiontimestamp)`属性。

 `Stream`   <a name="sam-function-kinesis-stream"></a>
数据流的 Amazon 资源名称（ARN）或流使用者。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[EventSourceArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn)`属性。

 `TumblingWindowInSeconds`   <a name="sam-function-kinesis-tumblingwindowinseconds"></a>
处理窗口的持续时间（以秒为单位）。有效范围为 1 到 900（15 分钟）。  
有关更多信息，请参阅《AWS Lambda 开发人员指南》**的[滚动窗口](https://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html#streams-tumbling)。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[TumblingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-tumblingwindowinseconds)`属性。

## 示例
<a name="sam-property-function-kinesis--examples"></a>

### MetricsConfig 事件
<a name="sam-property-function-kinesis-example-metricsconfigevent"></a>

以下是一个资源示例，它使用 `MetricsConfig` 属性来捕获其事件源映射的每个处理阶段。

```
Resources:
  FilteredEventsFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: s3://sam-demo-bucket/metricsConfig.zip
      Handler: index.handler
      Runtime: nodejs16.x
      Events:
        KinesisStream:
          Type: Kinesis
          Properties:
            Stream: !GetAtt KinesisStream.Arn
            StartingPosition: LATEST
            MetricsConfig:
              Metrics:
              - EventCount
```

### Kinesis 事件源
<a name="sam-property-function-kinesis--examples--kinesis-event-source"></a>

下面是一个 Kinesis 事件源。

#### YAML
<a name="sam-property-function-kinesis--examples--kinesis-event-source--yaml"></a>

```
Events:
  KinesisEvent:
    Type: Kinesis
    Properties:
      Stream: arn:aws:kinesis:us-east-1:123456789012:stream/my-stream
      StartingPosition: TRIM_HORIZON
      BatchSize: 10
      Enabled: false
      FilterCriteria: 
        Filters: 
          - Pattern: '{"key": ["val1", "val2"]}'
```

# MQ
<a name="sam-property-function-mq"></a>

描述 `MQ` 事件源类型的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中[结合 Amazon MQ 使用 Lambda](https://docs.aws.amazon.com/lambda/latest/dg/with-mq.html)。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)资源。

**注意**  
要在虚拟私有云（VPC）中建立 Amazon MQ 队列并连接到公共网络中的 Lambda 函数，函数的执行角色必须包含以下权限：  
`ec2:CreateNetworkInterface`
`ec2:DeleteNetworkInterface`
`ec2:DescribeNetworkInterfaces`
`ec2:DescribeSecurityGroups`
`ec2:DescribeSubnets`
`ec2:DescribeVpcs`
有关更多信息，请参阅《*AWS Lambda 开发人员指南*》中的[执行角色权限](https://docs.aws.amazon.com/lambda/latest/dg/with-mq.html#events-mq-permissions)。

## 语法
<a name="sam-property-function-mq-syntax"></a>

要在 AWS SAM 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-mq-syntax.yaml"></a>

```
  [BatchSize](#sam-function-mq-batchsize): Integer
  [Broker](#sam-function-mq-broker): String
  DynamicPolicyName: Boolean
  [Enabled](#sam-function-mq-enabled): Boolean
  [FilterCriteria](#sam-function-mq-filtercriteria): [FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
  KmsKeyArn: String 
  [MaximumBatchingWindowInSeconds](#sam-function-mq-maximumbatchingwindowinseconds): Integer
  [Queues](#sam-function-mq-queues): List
  [SecretsManagerKmsKeyId](#sam-function-mq-secretsmanagerkmskeyid): String
  [SourceAccessConfigurations](#sam-function-mq-sourceaccessconfigurations): List
```

## Properties
<a name="sam-property-function-mq-properties"></a>

 `BatchSize`   <a name="sam-function-mq-batchsize"></a>
要在单个批次中检索的最大项目数。  
*类型*：整数  
*必需*：否  
*默认值*：100  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)`属性。  
*最小值*：`1`  
*最大值*：`10000`

 `Broker`   <a name="sam-function-mq-broker"></a>
Amazon MQ 代理的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[EventSourceArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn)`属性。

 `DynamicPolicyName`   <a name="sam-function-mq-dynamicpolicyname"></a>
默认情况下， AWS Identity and Access Management (IAM) 策略名称是`SamAutoGeneratedAMQPolicy`为了向后兼容。指定 `true` 对 IAM policy 使用自动生成的名称。此名称包含 Amazon MQ 事件源逻辑 ID。  
使用多个 Amazon MQ 事件源时，请指定 `true`，以避免重复的 IAM policy 名称。
*类型*：布尔值  
*必需*：否  
*默认值*：`false`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Enabled`   <a name="sam-function-mq-enabled"></a>
如果为 `true`，则事件源映射处于活动状态。要暂停轮询和调用，设置为 `false`。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)`属性。

 `FilterCriteria`   <a name="sam-function-mq-filtercriteria"></a>
定义用于确定 Lambda 是否应处理事件的条件的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的 [AWS Lambda 事件筛选](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*类型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)`属性。

 `KmsKeyArn`   <a name="sam-function-mq-kmskeyarn"></a>
用于加密与此事件相关信息的密钥的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)`属性。

 `MaximumBatchingWindowInSeconds`   <a name="sam-function-mq-maximumbatchingwindowinseconds"></a>
在调用函数之前收集记录的最长时间（以秒为单位）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumBatchingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds)`属性。

 `Queues`   <a name="sam-function-mq-queues"></a>
要使用的 Amazon MQ 代理目的地队列的名称。  
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Queues](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-queues)`属性。

 `SecretsManagerKmsKeyId`   <a name="sam-function-mq-secretsmanagerkmskeyid"></a>
来自的客户托管密钥的 AWS Key Management Service (AWS KMS) 密钥 ID AWS Secrets Manager。将来自 Secrets Manager 的客户托管密钥与不包含 `kms:Decrypt` 权限的 Lambda 执行角色一起使用时，此属性是必需的。  
此属性的值为 UUID。例如：`1abc23d4-567f-8ab9-cde0-1fab234c5d67`。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceAccessConfigurations`   <a name="sam-function-mq-sourceaccessconfigurations"></a>
身份验证协议或虚拟主机的数组。使用[SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-sourceaccessconfiguration.html)数据类型进行指定。  
对于 `MQ` 事件源类型，唯一有效的配置类型是 `BASIC_AUTH` 和 `VIRTUAL_HOST`。  
+ **`BASIC_AUTH`** – 存储您的代理凭证的 Secrets Manager 密钥。要使用此类型，凭证必须采用以下格式：`{"username": "your-username", "password": "your-password"}`。只允许使用一个类型为 `BASIC_AUTH` 的对象。
+ **`VIRTUAL_HOST`** - 您的 RabbitMQ 代理中虚拟主机的名称。Lambda 将使用此 RabbitMQ 的主机作为事件源。只允许使用一个类型为 `VIRTUAL_HOST` 的对象。
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-sourceaccessconfigurations)`属性。

## 示例
<a name="sam-property-function-mq--examples"></a>

### Amazon MQ 事件源
<a name="sam-property-function-mq--examples--amazon-mq-event-source"></a>

以下是 Amazon MQ 代理的 `MQ` 事件源类型示例。

#### YAML
<a name="sam-property-function-mq--examples--amazon-mq-event-source--yaml"></a>

```
Events:
  MQEvent:
    Type: MQ
    Properties:
      Broker: arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9
      Queues: List of queues
      SourceAccessConfigurations:
        - Type: BASIC_AUTH
          URI: arn:aws:secretsmanager:us-east-1:01234567890:secret:MyBrokerSecretName
      BatchSize: 200
      Enabled: true
```

# MSK
<a name="sam-property-function-msk"></a>

描述 `MSK` 事件源类型的对象。有关更多信息，请参阅*AWS Lambda 开发者指南*中的[AWS Lambda 与 Amazon MSK 搭配使用](https://docs.aws.amazon.com/lambda/latest/dg/with-msk.html)。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)资源。

要使用架构注册表，您需要为函数定义特定的 IAM 角色权限。有关所需配置的示例，请参阅[使用 IAM 角色完成设置](#sam-property-function-msk-example-complete)。

## 语法
<a name="sam-property-function-msk-syntax"></a>

要在 AWS SAM 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-msk-syntax.yaml"></a>

```
  [BatchSize](#sam-function-msk-batchsize): Integer
  [BisectBatchOnFunctionError](#sam-function-msk-bisectbatchonfunctionerror): Boolean
  [ConsumerGroupId](#sam-function-msk-consumergroupid): String
  DestinationConfig: [DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-destinationconfig.html)
  [Enabled](#sam-function-msk-enabled): Boolean
  [FilterCriteria](#sam-function-msk-filtercriteria): [FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
  [FunctionResponseTypes](#sam-function-msk-functionresponsetypes): List
  KmsKeyArn: String
  [MaximumBatchingWindowInSeconds](#sam-function-msk-maximumbatchingwindowinseconds): Integer
  [MaximumRecordAgeInSeconds](#sam-function-msk-maximumrecordageinseconds): Integer
  [MaximumRetryAttempts](#sam-function-msk-maximumretryattempts): Integer
  [LoggingConfig](#sam-function-msk-loggingconfig): [LoggingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-loggingconfig.html)
  [MetricsConfig](#sam-function-msk-metricsconfig): [MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig.html)
  [ProvisionedPollerConfig](#sam-function-msk-provisionedpollerconfig): [ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-provisionedpollerconfig)
  [SchemaRegistryConfig](#sam-function-msk-schemaregistryconfig): [SchemaRegistryConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-schemaregistryconfig.html)
  SourceAccessConfigurations: [SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-sourceaccessconfigurations)
  [StartingPosition](#sam-function-msk-startingposition): String
  StartingPositionTimestamp: Double
  [Stream](#sam-function-msk-stream): String
  [Topics](#sam-function-msk-topics): List
```

## Properties
<a name="sam-property-function-msk-properties"></a>

 `BatchSize`   <a name="sam-function-msk-batchsize"></a>
Lambda 从流或队列中提取并发送到函数的每个批处理中的最大记录数。Lambda 在单次调用中将批处理中的所有记录传递给函数，最高可传递同步调用的负载上限 (6 MB)。  
*默认值*：100  
*有效范围*：最小值为 1。最大值为 10,000。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)`属性。

 `BisectBatchOnFunctionError`   <a name="sam-function-msk-bisectbatchonfunctionerror"></a>
如果函数返回错误，则将批次拆分为两批并重试。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BisectBatchOnFunctionError](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-bisectbatchonfunctionerror)`属性。

 `ConsumerGroupId`   <a name="sam-function-msk-consumergroupid"></a>
用于配置如何从 Kafka 主题中读取事件的字符串。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[AmazonManagedKafkaConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)`属性。

 `DestinationConfig`   <a name="sam-function-msk-destinationconfig"></a>
一个配置对象，用于在 Lambda 处理事件后指定事件目的地。  
使用此属性指定来自 Amazon MSK 事件源的失败调用的目的地。  
*类型*：[DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-destinationconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-destinationconfig.html)`属性。

 `Enabled`   <a name="sam-function-msk-enabled"></a>
禁用事件源映射以暂停轮询和调用。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)`属性。

 `FilterCriteria`   <a name="sam-function-msk-filtercriteria"></a>
定义用于确定 Lambda 是否应处理事件的条件的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的 [AWS Lambda 事件筛选](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*类型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)`属性。

 `FunctionResponseTypes`   <a name="sam-function-msk-functionresponsetypes"></a>
当前应用于事件源映射的响应类型的列表。有关详细信息，请参阅《AWS Lambda 开发人员指南》**中的[报告批处理项目失败](https://docs.aws.amazon.com/lambda/latest/dg/kafka-retry-configurations.html)。  
*有效值*：`ReportBatchItemFailures`  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FunctionResponseTypes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-functionresponsetypes)`属性。

 `KmsKeyArn`   <a name="sam-function-msk-kmskeyarn"></a>
用于加密与此事件相关信息的密钥的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)`属性。

 `MaximumBatchingWindowInSeconds`   <a name="sam-function-msk-maximumbatchingwindowinseconds"></a>
在调用函数之前收集记录的最长时间（以秒为单位）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumBatchingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds)`属性。

 `MaximumRecordAgeInSeconds`   <a name="sam-function-msk-maximumrecordageinseconds"></a>
Lambda 发送到函数以进行处理的记录的最长期限。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumRecordAgeInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumrecordageinseconds)`属性。

 `MaximumRetryAttempts`   <a name="sam-function-msk-maximumretryattempts"></a>
在函数返回错误时重试的最大次数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumRetryAttempts](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumretryattempts)`属性。

 `LoggingConfig`   <a name="sam-function-msk-loggingconfig"></a>
一个配置对象，用于指定事件源映射的日志配置。  
*类型*：[LoggingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-loggingconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[LoggingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-loggingconfig.html)`属性。

 `MetricsConfig`   <a name="sam-function-msk-metricsconfig"></a>
一个配置对象，它为事件源映射指定指标配置。  
*类型*：[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig.html)`属性。

 `ProvisionedPollerConfig`   <a name="sam-function-msk-provisionedpollerconfig"></a>
用于增加计算事件源映射所使用的轮询器数量的配置。此配置允许最少 1 个轮询器和最多 2000 个轮询器。有关具体示例，请参阅 [ProvisionedPollerConfig 示例](#sam-property-function-msk-example-provisionedpollerconfig)。  
*类型*：[ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-provisionedpollerconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-provisionedpollerconfig)`属性。

`SchemaRegistryConfig`  <a name="sam-function-msk-schemaregistryconfig"></a>
将架构注册表与 Kafka 事件源配合使用的配置。  
此功能需要配置 `ProvisionedPollerConfig`。
*类型*: SchemaRegistryConfig  
*必需*：否  
*CloudFormation 兼容性：*此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[AmazonManagedKafkaEventSourceConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-amazonmanagedkafkaeventsourceconfig)`属性。

 `SourceAccessConfigurations`   <a name="sam-function-msk-sourceaccessconfigurations"></a>
用于保护与定义事件源的身份验证协议数组 VPC 组件或虚拟化主机。  
*有效值*：`CLIENT_CERTIFICATE_TLS_AUTH`  
*类型*：[SourceAccessConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-sourceaccessconfiguration.html) 列表  
*必需*：否  
*CloudFormation 兼容性：*此属性是`AWS::Lambda::EventSourceMapping`资源[AmazonManagedKafkaEventSourceConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-lambda-eventsourcemapping-amazonmanagedkafkaeventsourceconfig)属性的一部分。

 `StartingPosition`   <a name="sam-function-msk-startingposition"></a>
在流中开始读取数据的位置。  
+ `AT_TIMESTAMP` – 指定开始读取记录的时间。
+ `LATEST` - 仅读取新记录。
+ `TRIM_HORIZON` - 处理所有可用的记录。
*有效值*：`AT_TIMESTAMP` \$1 `LATEST` \$1 `TRIM_HORIZON`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[StartingPosition](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingposition)`属性。

 `StartingPositionTimestamp`   <a name="sam-function-msk-startingpositiontimestamp"></a>
开始读取的时间（以 Unix 时间秒为单位） 在 `StartingPosition` 被指定为 `AT_TIMESTAMP` 的情况下定义 `StartingPositionTimestamp`。  
*类型*：双精度  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[StartingPositionTimestamp](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingpositiontimestamp)`属性。

 `Stream`   <a name="sam-function-msk-stream"></a>
数据流的 Amazon 资源名称（ARN）或流使用者。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[EventSourceArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn)`属性。

 `Topics`   <a name="sam-function-msk-topics"></a>
Kafka 主题的名称。  
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Topics](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-topics)`属性。

## 示例
<a name="sam-property-function-msk--examples"></a>

### 通过 IAM 角色完成设置
<a name="sam-property-function-msk-example-complete"></a>

以下示例展示了完整的配置，包括使用架构注册表所需的 IAM 角色配置：

```
Parameters:
  PreCreatedSubnetOne:
    Type: String
  PreCreatedSubnetTwo:
    Type: String
  MskClusterName4:
    Type: String

Resources:
  MyLambdaExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17		 	 	 '
        Statement:
        - Action: [sts:AssumeRole]
          Effect: Allow
          Principal:
            Service: [lambda.amazonaws.com]
      Policies:
      - PolicyName: KafkaClusterPermissions
        PolicyDocument:
          Statement:
          - Action: [kafka:DescribeClusterV2, kafka:GetBootstrapBrokers]
            Effect: Allow
            Resource: 'arn:aws:kafka:us-east-1:123456789012:cluster/*'
      - PolicyName: KafkaAuthPolicy
        PolicyDocument:
          Statement:
          - Action: [secretsmanager:GetSecretValue, kms:Decrypt]
            Effect: "Allow"
            Resource: ['arn:aws:secretsmanager:us-west-2:123456789012:secret:kafkaSecret-******',
                        'arn:aws:kms:us-west-2:123456789012:key/keyId']
      - PolicyName: ENIPolicy
        PolicyDocument:
          Statement:
          - Action: [ec2:CreateNetworkInterface,
              ec2:DescribeNetworkInterfaces, ec2:DescribeVpcs, ec2:DeleteNetworkInterface,
              ec2:DescribeSubnets, ec2:DescribeSecurityGroups]
            Effect: Allow
            Resource: '*'
      - PolicyName: SchemaRegistryPolicy
        PolicyDocument:
          Statement:
          - Action: [glue:GetRegistry]
            Effect: Allow
            Resource: 'arn:aws:glue:{region}:{account-id}:registry/{registry-name}'
      - PolicyName: SchemaVersionsPolicy
        PolicyDocument:
          Statement:
          - Action: [glue:GetSchemaVersions]
            Effect: Allow
            Resource: '*'
      ManagedPolicyArns:
      - !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
      Tags:
      - {Value: SAM, Key: lambda:createdBy}

  MyMskCluster:
    Type: AWS::MSK::Cluster
    Properties:
      BrokerNodeGroupInfo:
        ClientSubnets:
        - Ref: PreCreatedSubnetOne
        - Ref: PreCreatedSubnetTwo
        InstanceType: kafka.t3.small
        StorageInfo:
          EBSStorageInfo:
            VolumeSize: 1
      ClusterName:
        Ref: MskClusterName4
      KafkaVersion: 3.8.x
      NumberOfBrokerNodes: 2

  MyMskStreamProcessor:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs18.x
      Handler: index.handler
      CodeUri: ${codeuri}
      Role:
        Fn::GetAtt: [MyLambdaExecutionRole, Arn]
      Events:
        MyMskEvent:
          Type: MSK
          Properties:
            StartingPosition: LATEST
            Stream:
              Ref: MyMskCluster
            SourceAccessConfigurations:
            - Type: SASL_SCRAM_512_AUTH
              URI: !Sub arn:${AWS::Partition}:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
            Topics:
            - SchemaRegistryTestTopic
            ProvisionedPollerConfig:
              MinimumPollers: 1
            SchemaRegistryConfig:
              AccessConfigs:
              - Type: BASIC_AUTH
                URI: !Sub arn:${AWS::Partition}:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
              SchemaValidationConfigs:
              - Attribute: KEY
              EventRecordFormat: JSON
              SchemaRegistryURI: !Sub arn:${AWS::Partition}:glue:us-west-2:123456789012:registry/myregistry
```

### ProvisionedPollerConfig 示例
<a name="sam-property-function-msk-example-provisionedpollerconfig"></a>

```
ProvisionedPollerConfig:
  MinimumPollers: 1
  MaximumPollers: 200
```

### 现有集群的 Amazon MSK 示例
<a name="sam-property-function-msk--examples--amazon-msk-example-for-existing-cluster"></a>

以下示例显示了 AWS 账户中已存在的 Amazon MSK 集群的 `MSK` 事件源类型。

#### YAML
<a name="sam-property-function-msk--examples--amazon-msk-example-for-existing-cluster--yaml"></a>

```
Events:
  MSKEvent:
    Type: MSK
    Properties:
      StartingPosition: LATEST
      Stream: arn:aws:kafka:us-east-1:012345678012:cluster/exampleClusterName/abcdefab-1234-abcd-5678-cdef0123ab01-2
      Topics:
        - MyTopic
```

### 在同一模板中声明的集群的 Amazon MSK 示例
<a name="sam-property-function-msk--examples--amazon-msk-example-for-cluster-declared-in-same-template"></a>

以下是在同一模板文件中声明的 Amazon MSK 集群的 `MSK` 事件源类型的示例。

#### YAML
<a name="sam-property-function-msk--examples--amazon-msk-example-for-cluster-declared-in-same-template--yaml"></a>

```
Events:
  MSKEvent:
    Type: MSK
    Properties:
      StartingPosition: LATEST
      Stream:
        Ref: MyMskCluster   # This must be the name of an MSK cluster declared in the same template file
      Topics:
        - MyTopic
```

#### 带架构注册表的 MSK 事件源
<a name="sam-property-function-msk-example-schemaregistry"></a>

以下是一个配置了架构注册表的 `MSK` 事件源类型的示例。

```
Events:
  MSKEvent:
    Type: MSK
    Properties:
      StartingPosition: LATEST
      Stream:
        Ref: MyMskCluster
      Topics:
        - SchemaRegistryTestTopic
      ProvisionedPollerConfig:
        MinimumPollers: 1
      SchemaRegistryConfig:
        SchemaRegistryURI: !Sub arn:${AWS::Partition}:glue:us-west-2:123456789012:registry/myregistry
        EventRecordFormat: JSON
        SchemaValidationConfigs:
          - Attribute: KEY
          - Attribute: VALUE
```

#### 带 Confluent 架构注册表的 MSK 事件源
<a name="sam-property-function-msk-example-schemaregistry-confluent"></a>

以下是一个配置了 Confluent 架构注册表的 `MSK` 事件源类型的示例。

```
Events:
  MSKEvent:
    Type: MSK
    Properties:
      StartingPosition: LATEST
      Stream:
        Ref: MyMskCluster
      Topics:
        - SchemaRegistryTestTopic
      ProvisionedPollerConfig:
        MinimumPollers: 1
      SchemaRegistryConfig:
        SchemaRegistryURI: https://my-schema-registry.confluent.cloud
        AccessConfigs:
          - Type: BASIC_AUTH
            URI: !Sub arn:${AWS::Partition}:secretsmanager:us-west-2:123456789012:secret:my-secret
        EventRecordFormat: JSON
        SchemaValidationConfigs:
          - Attribute: KEY
          - Attribute: VALUE
```

# S3
<a name="sam-property-function-s3"></a>

描述 `S3` 事件源类型的对象。

## 语法
<a name="sam-property-function-s3-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-s3-syntax.yaml"></a>

```
  [Bucket](#sam-function-s3-bucket): String
  [Events](#sam-function-s3-events): String | List
  [Filter](#sam-function-s3-filter): [NotificationFilter](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfiguration-config-filter.html)
```

## Properties
<a name="sam-property-function-s3-properties"></a>

 `Bucket`   <a name="sam-function-s3-bucket"></a>
S3 桶名称。此存储桶必须存在于同一模板中。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性类似于`AWS::S3::Bucket`资源的`[BucketName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket.html#cfn-s3-bucket-name)`属性。在 SAM 中此为必填字段。此字段仅接受对此模板中创建的 S3 存储桶的引用

 `Events`   <a name="sam-function-s3-events"></a>
调用 Lambda 函数的 Amazon S3 桶事件。有关有效值的列表，请参阅 [Amazon S3 支持的事件类型](https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html#supported-notification-event-types)。  
*类型*：字符串 \$1 列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::S3::Bucket``LambdaConfiguration`数据类型的`[Event](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfig-lambdaconfig.html#cfn-s3-bucket-notificationconfig-lambdaconfig-event)`属性。

 `Filter`   <a name="sam-function-s3-filter"></a>
确定哪些 Amazon S3 对象调用 Lambda 函数的筛选规则。有关 Amazon S3 键名筛选的信息，请参阅*《Amazon Simple Storage Service 用户指南》*中的[配置 Amazon S3 事件通知](https://docs.aws.amazon.com/AmazonS3/latest/dev/NotificationHowTo.html)。  
*类型*：[NotificationFilter](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfiguration-config-filter.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::S3::Bucket``LambdaConfiguration`数据类型的`[Filter](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-s3-bucket-notificationconfiguration-config-filter.html)`属性。

## 示例
<a name="sam-property-function-s3--examples"></a>

### S3 事件
<a name="sam-property-function-s3--examples--s3-event"></a>

S3 事件示例。

#### YAML
<a name="sam-property-function-s3--examples--s3-event--yaml"></a>

```
Events:
  S3Event:
    Type: S3
    Properties:
      Bucket:
        Ref: ImagesBucket     # This must be the name of an S3 bucket declared in the same template file
      Events: s3:ObjectCreated:*
      Filter:
        S3Key:
          Rules:
          - Name: prefix      # or "suffix"
            Value: value      # The value to search for in the S3 object key names
```

# Schedule
<a name="sam-property-function-schedule"></a>

描述`Schedule`事件源类型的对象，它将您的无服务器函数设置为按计划触发的 Amazon EventBridge 规则的目标。有关更多信息，请参阅[什么是亚马逊 EventBridge？](https://docs.aws.amazon.com/eventbridge/latest/userguide/what-is-amazon-eventbridge.html) 在《*亚马逊 EventBridge 用户指南》*中。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html)资源。

**注意**  
EventBridge 现在提供了一种新的日程安排功能，即 [Amazon EventBridge Scheduler](https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html)。Amazon EventBridge Scheduler 是一款无服务器调度程序，允许您通过一个中央托管服务创建、运行和管理任务。 EventBridge Scheduler具有高度可定制性，与 EventBridge 计划规则相比，可扩展性更高，具有更广泛的目标 API 操作和 AWS 服务。  
建议您使用 EventBridge Scheduler 按计划调用目标。要在 AWS SAM 模板中定义此事件源类型，请参阅[ScheduleV2](sam-property-function-schedulev2.md)。

## 语法
<a name="sam-property-function-schedule-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-schedule-syntax.yaml"></a>

```
  [DeadLetterConfig](#sam-function-schedule-deadletterconfig): DeadLetterConfig
  [Description](#sam-function-schedule-description): String
  [Enabled](#sam-function-schedule-enabled): Boolean
  [Input](#sam-function-schedule-input): String
  [Name](#sam-function-schedule-name): String
  [RetryPolicy](#sam-function-schedule-retrypolicy): [RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)
  [Schedule](#sam-function-schedule-schedule): String
  [State](#sam-function-schedule-state): String
```

## Properties
<a name="sam-property-function-schedule-properties"></a>

 `DeadLetterConfig`   <a name="sam-function-schedule-deadletterconfig"></a>
配置亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的 Lambda 函数发送事件时，或者没有足够的权限调用 Lambda 函数 EventBridge 时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
[AWS::Serverless::Function](sam-resource-function.md) 资源类型具有类似的数据类型 `DeadLetterQueue`，用于处理成功调用目标 Lambda 函数后发生的故障。这些类型的故障示例包括 Lambda 节流或 Lambda 目标函数返回的错误。有关函数 `DeadLetterQueue` 属性的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-dlq)。
*类型*：[DeadLetterConfig](sam-property-function-scheduledeadletterconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule``Target`数据类型的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-deadletterconfig)`属性。此属性的 AWS SAM 版本包括其他子属性， AWS SAM 以备您想要创建死信队列时使用。

 `Description`   <a name="sam-function-schedule-description"></a>
规则的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-description)`属性。

 `Enabled`   <a name="sam-function-schedule-enabled"></a>
指示是否启用规则。  
要禁用该规则，请将此属性设置为 `false`。  
指定 `Enabled` 或 `State` 属性，但不能同时指定两者。
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state)`属性。如果此属性设置为，`true`则 AWS SAM 通过`ENABLED`，否则通过`DISABLED`。

 `Input`   <a name="sam-function-schedule-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-input)`属性。

 `Name`   <a name="sam-function-schedule-name"></a>
 规则的名称。如果您不指定名称，则 CloudFormation 会生成一个唯一的物理 ID 并将该 ID 用作规则名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-name)`属性。

 `RetryPolicy`   <a name="sam-function-schedule-retrypolicy"></a>
包含有关重试策略设置的信息的 `RetryPolicy` 对象。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
*类型*：[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)`属性。

 `Schedule`   <a name="sam-function-schedule-schedule"></a>
决定运行规则的时间和频率的计划表达式。有关更多信息，请参阅[规则的计划表达式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[ScheduleExpression](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-scheduleexpression)`属性。

 `State`   <a name="sam-function-schedule-state"></a>
规则的状态。  
*接受的值：*`DISABLED | ENABLED`  
指定 `Enabled` 或 `State` 属性，但不能同时指定两者。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state)`属性。

## 示例
<a name="sam-property-function-schedule--examples"></a>

### CloudWatch 安排活动
<a name="sam-property-function-schedule--examples--cloudwatch-schedule-event"></a>

CloudWatch 安排活动示例

#### YAML
<a name="sam-property-function-schedule--examples--cloudwatch-schedule-event--yaml"></a>

```
CWSchedule:
  Type: Schedule
  Properties:
    Schedule: 'rate(1 minute)'
    Name: TestSchedule
    Description: test schedule
    Enabled: false
```

# DeadLetterConfig
<a name="sam-property-function-scheduledeadletterconfig"></a>

用于指定亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列的对象，目标调用失败后 EventBridge 在该队列中发送事件。例如，在向不存在的 Lambda 函数发送事件或调用 Lambda 函数的权限不足时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。

**注意**  
[AWS::Serverless::Function](sam-resource-function.md) 资源类型具有类似的数据类型 `DeadLetterQueue`，用于处理成功调用目标 Lambda 函数后发生的故障。此类故障的示例包括 Lambda 节流或 Lambda 目标函数返回的错误。有关函数 `DeadLetterQueue` 属性的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-dlq)。

## 语法
<a name="sam-property-function-scheduledeadletterconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-scheduledeadletterconfig-syntax.yaml"></a>

```
  [Arn](#sam-function-scheduledeadletterconfig-arn): String
  [QueueLogicalId](#sam-function-scheduledeadletterconfig-queuelogicalid): String
  [Type](#sam-function-scheduledeadletterconfig-type): String
```

## Properties
<a name="sam-property-function-scheduledeadletterconfig-properties"></a>

 `Arn`   <a name="sam-function-scheduledeadletterconfig-arn"></a>
指定作为死信队列目标的 Amazon SQS 队列的 Amazon 资源名称（ARN）。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``DeadLetterConfig`数据类型的`[Arn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-deadletterconfig.html#cfn-events-rule-deadletterconfig-arn)`属性。

 `QueueLogicalId`   <a name="sam-function-scheduledeadletterconfig-queuelogicalid"></a>
指定了 AWS SAM 创建的死信队列的自定义名称。`Type`  
如果未设置 `Type` 属性，则将忽略该属性。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Type`   <a name="sam-function-scheduledeadletterconfig-type"></a>
队列的类型。设置此属性后， AWS SAM 会自动创建死信队列并附加必要的[基于资源的策略](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html#dlq-perms)，以授予规则资源向队列发送事件的权限。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*有效值*：`SQS`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-scheduledeadletterconfig--examples"></a>

### DeadLetterConfig
<a name="sam-property-function-scheduledeadletterconfig--examples--deadletterconfig"></a>

DeadLetterConfig

#### YAML
<a name="sam-property-function-scheduledeadletterconfig--examples--deadletterconfig--yaml"></a>

```
DeadLetterConfig:
  Type: SQS
  QueueLogicalId: MyDLQ
```

# ScheduleV2
<a name="sam-property-function-schedulev2"></a>

描述`ScheduleV2`事件源类型的对象，它将您的无服务器函数设置为按计划触发的 Amazon S EventBridge cheduler 事件的目标。有关更多信息，请参阅[什么是 Amazon EventBridge 日程安排](https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html)？ 在《*EventBridge 日程安排器用户指南》*中。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html)资源。

## 语法
<a name="sam-property-function-schedulev2-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-schedulev2-syntax.yaml"></a>

```
[DeadLetterConfig](#sam-function-schedulev2-deadletterconfig): DeadLetterConfig
[Description](#sam-function-schedulev2-description): String
[EndDate](#sam-function-schedulev2-enddate): String
[FlexibleTimeWindow](#sam-function-schedulev2-flexibletimewindow): FlexibleTimeWindow
[GroupName](#sam-function-schedulev2-groupname): String
[Input](#sam-function-schedulev2-input): String
[KmsKeyArn](#sam-function-schedulev2-kmskeyarn): String
[Name](#sam-function-schedulev2-name): String
OmitName: Boolean
[PermissionsBoundary](#sam-function-schedulev2-permissionsboundary): String
[RetryPolicy](#sam-function-schedulev2-retrypolicy): RetryPolicy
[RoleArn](#sam-function-schedulev2-rolearn): String
[ScheduleExpression](#sam-function-schedulev2-schedule): String
[ScheduleExpressionTimezone](#sam-function-schedulev2-scheduleexpressiontimezone): String
[StartDate](#sam-function-schedulev2-startdate): String
[State](#sam-function-schedulev2-state): String
```

## Properties
<a name="sam-property-function-schedulev2-properties"></a>

 `DeadLetterConfig`   <a name="sam-function-schedulev2-deadletterconfig"></a>
配置亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的 Lambda 函数发送事件时，或者没有足够的权限调用 Lambda 函数 EventBridge 时，调用可能会失败。*有关更多信息，请参阅《日[ EventBridge 程安排器用户指南》中的为调度程序配置死信队列](https://docs.aws.amazon.com/scheduler/latest/UserGuide/configuring-schedule-dlq.html)。EventBridge *  
[AWS::Serverless::Function](sam-resource-function.md) 资源类型具有类似的数据类型 `DeadLetterQueue`，用于处理成功调用目标 Lambda 函数后发生的故障。这些类型的故障示例包括 Lambda 节流或 Lambda 目标函数返回的错误。有关函数 `DeadLetterQueue` 属性的更多信息，请参阅*《AWS Lambda 开发人员指南》*中的[死信队列](https://docs.aws.amazon.com/lambda/latest/dg/invocation-async.html#invocation-dlq)。
*类型*：[DeadLetterConfig](sam-property-function-scheduledeadletterconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Scheduler::Schedule``Target`数据类型的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-deadletterconfig)`属性。此属性的 AWS SAM 版本包括其他子属性， AWS SAM 以备您想要创建死信队列时使用。

 `Description`   <a name="sam-function-schedulev2-description"></a>
计划的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-description)`属性。

 `EndDate`   <a name="sam-function-schedulev2-enddate"></a>
以 UTC 为单位的日期，在此日期之前计划可以调用其目标。根据计划的重复表达式，调用可能会在您指定的 **EndDate** 或之前停止。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[EndDate](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-enddate)`属性。

 `FlexibleTimeWindow`   <a name="sam-function-schedulev2-flexibletimewindow"></a>
允许配置可以调用计划的窗口。  
*类型*：[FlexibleTimeWindow](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-flexibletimewindow)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[FlexibleTimeWindow](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-flexibletimewindow)`属性。

 `GroupName`   <a name="sam-function-schedulev2-groupname"></a>
将与此计划关联的计划组名称。如果未定义，则使用默认组。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[GroupName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-groupname)`属性。

 `Input`   <a name="sam-function-schedulev2-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-input)`属性。

 `KmsKeyArn`   <a name="sam-function-schedulev2-kmskeyarn"></a>
将用于加密客户数据的 KMS 密钥的 ARN。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-kmskeyarn)`属性。

 `Name`   <a name="sam-function-schedulev2-name"></a>
计划的名称。如果您未指定名称，则 AWS SAM 会生成格式为的名称，`Function-Logical-IDEvent-Source-Name`并使用该 ID 作为计划名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-name)`属性。

`OmitName`  <a name="sam-function-schedulev2-omitname"></a>
默认情况下， AWS SAM 生成并使用格式为的计划名称*<Function-logical-ID><event-source-name>*。将此属性设置`true`为 CloudFormation 生成唯一的物理 ID，然后改用该物理 ID 作为计划名称。  
*类型*：布尔值  
*必需*：否  
*默认值*：`false`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `PermissionsBoundary`   <a name="sam-function-schedulev2-permissionsboundary"></a>
用于为角色设置权限边界的策略的 ARN。  
如果已定义，`PermissionsBoundary`则 AWS SAM 将对计划程序计划的目标 IAM 角色应用相同的边界。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IAM::Role`资源的`[PermissionsBoundary](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-permissionsboundary)`属性。

 `RetryPolicy`   <a name="sam-function-schedulev2-retrypolicy"></a>
包含有关重试策略设置的信息的 **RetryPolicy** 对象。  
*类型*：[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-retrypolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule``Target`数据类型的`[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-retrypolicy)`属性。

 `RoleArn`   <a name="sam-function-schedulev2-rolearn"></a>
调用计划时， EventBridge 计划程序将用于目标的 IAM 角色的 ARN。  
*类型*：[RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule``Target`数据类型的`[RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)`属性。

 `ScheduleExpression`   <a name="sam-function-schedulev2-scheduleexpression"></a>
决定运行调度器计划事件的时间和频率的计划表达式。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[ScheduleExpression](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-scheduleexpression)`属性。

 `ScheduleExpressionTimezone`   <a name="sam-function-schedulev2-scheduleexpressiontimezone"></a>
评估计划表达式的时区。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[ScheduleExpressionTimezone](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-scheduleexpressiontimezone)`属性。

 `StartDate`   <a name="sam-function-schedulev2-startdate"></a>
以 UTC 为单位的日期，在此日期之后计划可以调用目标。根据计划的重复表达式，调用可能会在您指定的 **StartDate** 或之后发生。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[StartDate](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-startdate)`属性。

 `State`   <a name="sam-function-schedulev2-state"></a>
调度器计划的状态。  
*接受的值：*`DISABLED | ENABLED`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-state)`属性。

## 示例
<a name="sam-property-function-schedulev2--examples"></a>

### 定义 ScheduleV2 资源的基本示例
<a name="sam-property-function-schedulev2--examples--example1"></a>

```
Resources:
  Function:
    Properties:
      ...
      Events:
        ScheduleEvent:
          Type: ScheduleV2
          Properties:
            ScheduleExpression: "rate(1 minute)"
        ComplexScheduleEvent:
          Type: ScheduleV2
          Properties:
            ScheduleExpression: rate(1 minute)
            FlexibleTimeWindow:
              Mode: FLEXIBLE
              MaximumWindowInMinutes: 5
            StartDate: '2022-12-28T12:00:00.000Z'
            EndDate: '2023-01-28T12:00:00.000Z'
            ScheduleExpressionTimezone: UTC
            RetryPolicy:
              MaximumRetryAttempts: 5
              MaximumEventAgeInSeconds: 300
            DeadLetterConfig:
              Type: SQS
```

**注意**  
生成的 ScheduleV2 物理 ID 不包括堆栈名称。

# SelfManagedKafka
<a name="sam-property-function-selfmanagedkafka"></a>

描述 `SelfManagedKafka` 事件源类型的对象。*有关更多信息，请参阅《开发人员指南》中的[AWS Lambda 与自行管理的 Apache Kafka 配合使用](https://docs.aws.amazon.com/lambda/latest/dg/with-kafka.html)。AWS Lambda *

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html)资源。

要使用架构注册表，您需要为函数定义特定的 IAM 角色权限。有关所需配置的示例，请参阅[使用 IAM 角色完成设置](sam-property-function-msk.md#sam-property-function-msk-example-complete)。

## 语法
<a name="sam-property-function-selfmanagedkafka-syntax"></a>

要在 AWS SAM 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-selfmanagedkafka-syntax.yaml"></a>

```
  [BatchSize](#sam-function-selfmanagedkafka-batchsize): Integer
  [BisectBatchOnFunctionError](#sam-function-selfmanagedkafka-bisectbatchonfunctionerror): Boolean
  [ConsumerGroupId](#sam-function-selfmanagedkafka-consumergroupid): String
  DestinationConfig: [DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-destinationconfig.html)
  [Enabled](#sam-function-selfmanagedkafka-enabled): Boolean
  [FilterCriteria](#sam-function-selfmanagedkafka-filtercriteria): [FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
  [KafkaBootstrapServers](#sam-function-selfmanagedkafka-kafkabootstrapservers): List
  [FunctionResponseTypes](#sam-function-selfmanagedkafka-functionresponsetypes): List
  KmsKeyArn: String
  [LoggingConfig](#sam-function-selfmanagedkafka-loggingconfig): LoggingConfig
  [MaximumRecordAgeInSeconds](#sam-function-selfmanagedkafka-maximumrecordageinseconds): Integer
  [MaximumRetryAttempts](#sam-function-selfmanagedkafka-maximumretryattempts): Integer
  [MetricsConfig](#sam-function-selfmanagedkafka-metricsconfig): MetricsConfig
  [ProvisionedPollerConfig](#sam-function-selfmanagedkafka-provisionedpollerconfig): [ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-provisionedpollerconfig)
  [SchemaRegistryConfig](#sam-function-selfmanagedkafka-schemaregistryconfig): [SchemaRegistryConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-schemaregistryconfig.html)
  [SourceAccessConfigurations](#sam-function-selfmanagedkafka-sourceaccessconfigurations): [SourceAccessConfigurations](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-sourceaccessconfigurations)
  StartingPosition: String
  StartingPositionTimestamp: Double
  [Topics](#sam-function-selfmanagedkafka-topics): List
```

## Properties
<a name="sam-property-function-selfmanagedkafka-properties"></a>

 `BatchSize`   <a name="sam-function-selfmanagedkafka-batchsize"></a>
Lambda 从流中提取并发送到函数的每个批处理中的最大记录数。  
*类型*：整数  
*必需*：否  
*默认值*：100  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)`属性。  
*最小值*：`1`  
*最大值*：`10000`

 `BisectBatchOnFunctionError`   <a name="sam-function-selfmanagedkafka-bisectbatchonfunctionerror"></a>
如果函数返回错误，则将批次拆分为两批并重试。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BisectBatchOnFunctionError](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-bisectbatchonfunctionerror)`属性。

 `ConsumerGroupId`   <a name="sam-function-selfmanagedkafka-consumergroupid"></a>
用于配置如何从 Kafka 主题中读取事件的字符串。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[SelfManagedKafkaEventSourceConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-selfmanagedkafkaeventsourceconfig)`属性。

 `DestinationConfig`   <a name="sam-function-selfmanagedkafka-destinationconfig"></a>
一个配置对象，用于在 Lambda 处理事件后指定事件目的地。  
使用此属性指定来自管理 Kafka 事件源的失败调用的目的地。  
*类型*：[DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-destinationconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ DestinationConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-destinationconfig)`属性。

 `Enabled`   <a name="sam-function-selfmanagedkafka-enabled"></a>
禁用事件源映射以暂停轮询和调用。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)`属性。

 `FilterCriteria`   <a name="sam-function-selfmanagedkafka-filtercriteria"></a>
定义用于确定 Lambda 是否应处理事件的条件的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的 [AWS Lambda 事件筛选](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*类型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-filtercriteria)`属性。

 `KafkaBootstrapServers`   <a name="sam-function-selfmanagedkafka-kafkabootstrapservers"></a>
Kafka 代理的引导服务器列表。包括端口，例如 `broker.example.com:xxxx`  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionResponseTypes`   <a name="sam-function-selfmanagedkafka-functionresponsetypes"></a>
当前应用于事件源映射的响应类型的列表。有关详细信息，请参阅《AWS Lambda 开发人员指南》**中的[报告批处理项目失败](https://docs.aws.amazon.com/lambda/latest/dg/kafka-retry-configurations.html)。  
*有效值*：`ReportBatchItemFailures`  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FunctionResponseTypes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-functionresponsetypes)`属性。

 `KmsKeyArn`   <a name="sam-function-selfmanagedkafka-kmskeyarn"></a>
用于加密与此事件相关信息的密钥的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)`属性。

 `LoggingConfig`   <a name="sam-function-selfmanagedkafka-loggingconfig"></a>
您的事件源的日志配置。  
*类型*：[LoggingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-loggingconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[LoggingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-loggingconfig)`属性。

 `MaximumRecordAgeInSeconds`   <a name="sam-function-selfmanagedkafka-maximumrecordageinseconds"></a>
Lambda 发送到函数以进行处理的记录的最长期限。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumRecordAgeInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumrecordageinseconds)`属性。

 `MetricsConfig`   <a name="sam-function-selfmanagedkafka-metricsconfig"></a>
您的事件源的指标配置。  
*类型*：[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-metricsconfig)`属性。

 `MaximumRetryAttempts`   <a name="sam-function-selfmanagedkafka-maximumretryattempts"></a>
在函数返回错误时重试的最大次数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumRetryAttempts](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumretryattempts)`属性。

 `ProvisionedPollerConfig`   <a name="sam-function-selfmanagedkafka-provisionedpollerconfig"></a>
用于增加计算事件源映射所使用的轮询器数量的配置。此配置允许最少 1 个轮询器和最多 2000 个轮询器。有关具体示例，请参阅 [ProvisionedPollerConfig 示例](#sam-property-function-selfmanagedkafka-example-provisionedpollerconfig)。  
*类型*：[ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-provisionedpollerconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-provisionedpollerconfig)`属性。

`SchemaRegistryConfig`  <a name="sam-function-selfmanagedkafka-schemaregistryconfig"></a>
将架构注册表与自托管 Kafka 事件源配合使用的配置。  
此功能需要配置 `ProvisionedPollerConfig`。
*类型*：[SchemaRegistryConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-schemaregistryconfig)  
*必需*：否  
*CloudFormation 兼容性：*此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[SelfManagedKafkaEventSourceConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-selfmanagedkafkaeventsourceconfig)`属性。

 `SourceAccessConfigurations`   <a name="sam-function-selfmanagedkafka-sourceaccessconfigurations"></a>
用于保护与定义事件源的身份验证协议数组 VPC 组件或虚拟化主机。  
*有效值*：`BASIC_AUTH | CLIENT_CERTIFICATE_TLS_AUTH | SASL_SCRAM_256_AUTH | SASL_SCRAM_512_AUTH | SERVER_ROOT_CA_CERTIFICATE`  
*类型*：[SourceAccessConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-sourceaccessconfiguration) 列表  
*是否必需*：是  
*CloudFormation 兼容性：*此属性是`AWS::Lambda::EventSourceMapping`资源`[SelfManagedKafkaEventSourceConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-selfmanagedkafkaeventsourceconfig)`属性的一部分。

 `StartingPosition`   <a name="sam-function-selfmanagedkafka-startingposition"></a>
在流中开始读取数据的位置。  
+ `AT_TIMESTAMP` – 指定开始读取记录的时间。
+ `LATEST` - 仅读取新记录。
+ `TRIM_HORIZON` - 处理所有可用的记录。
*有效值*：`AT_TIMESTAMP` \$1 `LATEST` \$1 `TRIM_HORIZON`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[StartingPosition](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingposition)`属性。

 `StartingPositionTimestamp`   <a name="sam-function-selfmanagedkafka-startingpositiontimestamp"></a>
开始读取的时间（以 Unix 时间秒为单位） 在 `StartingPosition` 被指定为 `AT_TIMESTAMP` 的情况下定义 `StartingPositionTimestamp`。  
*类型*：双精度  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[StartingPositionTimestamp](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-startingpositiontimestamp)`属性。

 `Topics`   <a name="sam-function-selfmanagedkafka-topics"></a>
Kafka 主题的名称。  
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Topics](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-topics)`属性。

## 示例
<a name="sam-property-function-selfmanagedkafka--examples"></a>

### 通过 IAM 角色完成设置
<a name="sam-property-function-selfmanagedkafka-example-complete"></a>

以下示例展示了完整的配置，包括使用架构注册表所需的 IAM 角色配置：

```
Parameters:
  PreCreatedSubnetOne:
    Type: String
  PreCreatedSubnetTwo:
    Type: String

Resources:
  MyLambdaExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: '2012-10-17		 	 	 '
        Statement:
        - Action: [sts:AssumeRole]
          Effect: Allow
          Principal:
            Service: [lambda.amazonaws.com]
      Policies:
      - PolicyName: KafkaAuthPolicy
        PolicyDocument:
          Statement:
          - Action: [secretsmanager:GetSecretValue, kms:Decrypt]
            Effect: "Allow"
            Resource: ['arn:aws:secretsmanager:us-west-2:123456789012:secret:kafkaSecret-******',
                        'arn:aws:kms:us-west-2:123456789012:key/keyId']
      - PolicyName: ENIPolicy
        PolicyDocument:
          Statement:
          - Action: [ec2:CreateNetworkInterface,
              ec2:DescribeNetworkInterfaces, ec2:DescribeVpcs, ec2:DeleteNetworkInterface,
              ec2:DescribeSubnets, ec2:DescribeSecurityGroups]
            Effect: Allow
            Resource: '*'
      - PolicyName: SchemaRegistryPolicy
        PolicyDocument:
          Statement:
          - Action: [glue:GetRegistry]
            Effect: Allow
            Resource: 'arn:aws:glue:{region}:{account-id}:registry/{registry-name}'
      - PolicyName: SchemaVersionsPolicy
        PolicyDocument:
          Statement:
          - Action: [glue:GetSchemaVersions]
            Effect: Allow
            Resource: '*'
      ManagedPolicyArns:
      - !Sub arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
      Tags:
      - {Value: SAM, Key: lambda:createdBy}

  MyKafkaProcessor:
    Type: AWS::Serverless::Function
    Properties:
      Runtime: nodejs18.x
      Handler: index.handler
      CodeUri: ${codeuri}
      Role:
        Fn::GetAtt: [MyLambdaExecutionRole, Arn]
      Events:
        SelfManagedKafkaEvent:
          Type: SelfManagedKafka
          Properties:
            KafkaBootstrapServers:
              - my-kafka-broker-1:9092
              - my-kafka-broker-2:9092
            Topics:
              - SchemaRegistryTestTopic
            StartingPosition: LATEST
            SourceAccessConfigurations:
              - Type: VPC_SUBNET
                URI: subnet:subnet-12345678
              - Type: VPC_SECURITY_GROUP
                URI: security_group:sg-12345678
              - Type: BASIC_AUTH
                URI: !Sub arn:${AWS::Partition}:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
            ProvisionedPollerConfig:
              MinimumPollers: 1
            SchemaRegistryConfig:
              AccessConfigs:
              - Type: BASIC_AUTH
                URI: !Sub arn:${AWS::Partition}:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
              SchemaValidationConfigs:
              - Attribute: KEY
              EventRecordFormat: JSON
              SchemaRegistryURI: !Sub arn:${AWS::Partition}:glue:us-west-2:123456789012:registry/myregistry
```

### ProvisionedPollerConfig 示例
<a name="sam-property-function-selfmanagedkafka-example-provisionedpollerconfig"></a>

```
ProvisionedPollerConfig:
  MinimumPollers: 1
  MaximumPollers: 200
```

### 自行管理的 Kafka 事件源
<a name="sam-property-function-selfmanagedkafka--examples--self-managed-kafka-event-source"></a>

以下是 `SelfManagedKafka` 事件源类型的示例。

#### YAML
<a name="sam-property-function-selfmanagedkafka--examples--self-managed-kafka-event-source--yaml"></a>

```
Events:
  SelfManagedKafkaEvent:
    Type: SelfManagedKafka
    Properties:
      BatchSize: 1000
      Enabled: true
      KafkaBootstrapServers:
        - abc.xyz.com:xxxx
      SourceAccessConfigurations:
        -  Type: BASIC_AUTH
           URI: arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c
      Topics:
        - MyKafkaTopic
```

### 带有 AWS Glue 架构注册表的自管理 Kafka 事件源
<a name="sam-property-function-selfmanagedkafka-example-schemaregistry"></a>

以下是使用 AWS Glue 架构注册表配置`SelfManagedKafka`的事件源类型的示例。

```
Events:
  SelfManagedKafkaEvent:
    Type: SelfManagedKafka
    Properties:
      KafkaBootstrapServers:
        - abc.xyz.com:9092
      Topics:
        - SchemaRegistryTestTopic
      StartingPosition: LATEST
      ProvisionedPollerConfig:
        MinimumPollers: 1
      SchemaRegistryConfig:
        SchemaRegistryURI: !Sub arn:${AWS::Partition}:glue:us-west-2:123456789012:registry/myregistry
        EventRecordFormat: JSON
        SchemaValidationConfigs:
          - Attribute: KEY
          - Attribute: VALUE
      SourceAccessConfigurations:
        - Type: VPC_SUBNET
          URI: subnet:subnet-12345678
        - Type: VPC_SECURITY_GROUP
          URI: security_group:sg-12345678
```

### 自托管 Kafka 事件源与 Confluent 架构注册表
<a name="sam-property-function-selfmanagedkafka-example-schemaregistry-confluent"></a>

以下是一个配置了 Confluent 架构注册表的 `SelfManagedKafka` 事件源类型的示例。

```
Events:
  SelfManagedKafkaEvent:
    Type: SelfManagedKafka
    Properties:
      KafkaBootstrapServers:
        - abc.xyz.com:9092
      Topics:
        - SchemaRegistryTestTopic
      StartingPosition: LATEST
      ProvisionedPollerConfig:
        MinimumPollers: 1
      SchemaRegistryConfig:
        SchemaRegistryURI: https://my-schema-registry.confluent.cloud
        AccessConfigs:
          - Type: BASIC_AUTH
            URI: !Sub arn:${AWS::Partition}:secretsmanager:us-west-2:123456789012:secret:my-secret
        EventRecordFormat: JSON
        SchemaValidationConfigs:
          - Attribute: KEY
          - Attribute: VALUE
      SourceAccessConfigurations:
        - Type: VPC_SUBNET
          URI: subnet:subnet-12345678
        - Type: VPC_SECURITY_GROUP
          URI: security_group:sg-12345678
        - Type: BASIC_AUTH
          URI: !Sub arn:${AWS::Partition}:secretsmanager:us-west-2:123456789012:secret:kafka-secret
```

# SNS
<a name="sam-property-function-sns"></a>

描述 `SNS` 事件源类型的对象。

如果设置了此事件类型，SAM 会生成 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html) 资源

## 语法
<a name="sam-property-function-sns-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-sns-syntax.yaml"></a>

```
  [FilterPolicy](#sam-function-sns-filterpolicy): [SnsFilterPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html#cfn-sns-subscription-filterpolicy)
  FilterPolicyScope: String
  RedrivePolicy: Json
  [Region](#sam-function-sns-region): String
  [SqsSubscription](#sam-function-sns-sqssubscription): Boolean | SqsSubscriptionObject
  [Topic](#sam-function-sns-topic): String
```

## Properties
<a name="sam-property-function-sns-properties"></a>

 `FilterPolicy`   <a name="sam-function-sns-filterpolicy"></a>
分配给订阅的筛选策略 JSON。有关更多信息，请参阅[GetSubscriptionAttributes](https://docs.aws.amazon.com/sns/latest/api/API_GetSubscriptionAttributes.html)《亚马逊简单通知服务 API 参考》。  
*类型*：[SnsFilterPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html#cfn-sns-subscription-filterpolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::SNS::Subscription`资源的`[FilterPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html#cfn-sns-subscription-filterpolicy)`属性。

 `FilterPolicyScope`   <a name="sam-function-sns-filterpolicyscope"></a>
此属性允许您使用以下字符串值类型之一来选择筛选范围：  
+ `MessageAttributes` – 筛选条件应用于消息属性。
+ `MessageBody` – 筛选条件应用于消息正文。
*类型*：字符串  
*必需*：否  
*默认值*：`MessageAttributes`  
*CloudFormation 兼容性*：此属性直接传递给`AWS::SNS::Subscription`资源的` [ FilterPolicyScope](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html#cfn-sns-subscription-filterpolicyscope)`属性。

 `RedrivePolicy`   <a name="sam-function-sns-redrivepolicy"></a>
指定后，将无法传输的消息发送到指定的 Amazon SQS 死信队列。由于客户端错误（例如，在无法访问订阅的端点时）或服务器错误（例如，在支持订阅的端点的服务变得不可用时）而无法传输的消息将保留在死信队列中，以进行进一步分析或重新处理。  
有关重新驱动策略和死信队列的更多信息，请参阅*《Amazon Simple Queue Service 开发人员指南》*中的 [Amazon SQS 死信队列](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html)。  
*类型*：Json  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::SNS::Subscription`资源的`[ RedrivePolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html#cfn-sns-subscription-redrivepolicy)`属性。

 `Region`   <a name="sam-function-sns-region"></a>
对于跨区域订阅，为主题所在的区域。  
如果未指定区域，则 CloudFormation 使用呼叫者的区域作为默认区域。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::SNS::Subscription`资源的`[Region](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html#cfn-sns-subscription-region)`属性。

 `SqsSubscription`   <a name="sam-function-sns-sqssubscription"></a>
将此属性设置为 true，或指定 `SqsSubscriptionObject` 以在 SQS 队列中启用批处理 SNS 主题通知。将此属性设置为 `true` 可创建新的 SQS 队列，而指定 `SqsSubscriptionObject` 则使用现有的 SQS 队列。  
*类型*：布尔值 \$1 [SqsSubscriptionObject](sam-property-function-sqssubscriptionobject.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Topic`   <a name="sam-function-sns-topic"></a>
要订阅的主题的 ARN。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::SNS::Subscription`资源的`[TopicArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html#topicarn)`属性。

## 示例
<a name="sam-property-function-sns--examples"></a>

### SNS 事件源示例
<a name="sam-property-function-sns--examples--sns-event-source-example"></a>

SNS 事件源示例

#### YAML
<a name="sam-property-function-sns--examples--sns-event-source-example--yaml"></a>

```
Events:
  SNSEvent:
    Type: SNS
    Properties:
      Topic: arn:aws:sns:us-east-1:123456789012:my_topic
      SqsSubscription: true
      FilterPolicy:
        store:
          - example_corp
        price_usd:
          - numeric:
              - ">="
              - 100
```

# SqsSubscriptionObject
<a name="sam-property-function-sqssubscriptionobject"></a>

为 SNS 事件指定现有 SQS 队列选项

## 语法
<a name="sam-property-function-sqssubscriptionobject-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-sqssubscriptionobject-syntax.yaml"></a>

```
  [BatchSize](#sam-function-sqssubscriptionobject-batchsize): String
  [Enabled](#sam-function-sqssubscriptionobject-enabled): Boolean
  [QueueArn](#sam-function-sqssubscriptionobject-queuearn): String
  [QueuePolicyLogicalId](#sam-function-sqssubscriptionobject-queuepolicylogicalid): String
  [QueueUrl](#sam-function-sqssubscriptionobject-queueurl): String
```

## Properties
<a name="sam-property-function-sqssubscriptionobject-properties"></a>

 `BatchSize`   <a name="sam-function-sqssubscriptionobject-batchsize"></a>
要在 SQS 队列单个批次中检索的最大项目数。  
*类型*：字符串  
*必需*：否  
*默认值*：10  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Enabled`   <a name="sam-function-sqssubscriptionobject-enabled"></a>
禁用 SQS 事件源映射以暂停轮询和调用。  
*类型*：布尔值  
*必需*：否  
*默认值*：True  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `QueueArn`   <a name="sam-function-sqssubscriptionobject-queuearn"></a>
指定现有 SQS 队列 arn。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `QueuePolicyLogicalId`   <a name="sam-function-sqssubscriptionobject-queuepolicylogicalid"></a>
为资源提供一个自定义 LogicalID 名称。[AWS::SQS::QueuePolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sqs-policy.html)  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `QueueUrl`   <a name="sam-function-sqssubscriptionobject-queueurl"></a>
指定与 `QueueArn` 属性关联的队列 URL。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-function-sqssubscriptionobject--examples"></a>

### SNS 事件的现有 SQS
<a name="sam-property-function-sqssubscriptionobject--examples--existing-sqs-for-sns-event"></a>

添加现有 SQS 队列以订阅 SNS 主题的示例。

#### YAML
<a name="sam-property-function-sqssubscriptionobject--examples--existing-sqs-for-sns-event--yaml"></a>

```
QueuePolicyLogicalId: CustomQueuePolicyLogicalId
QueueArn:
  Fn::GetAtt: MyCustomQueue.Arn
QueueUrl:
  Ref: MyCustomQueue
BatchSize: 5
```

# SQS
<a name="sam-property-function-sqs"></a>

描述 `SQS` 事件源类型的对象。有关更多信息，请参阅*AWS Lambda 开发者*指南中的[AWS Lambda 与 Amazon SQS 配合使用](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html)。

如果设置了此事件类型，SAM 会生成 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html) 资源

## 语法
<a name="sam-property-function-sqs-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-sqs-syntax.yaml"></a>

```
  [BatchSize](#sam-function-sqs-batchsize): Integer
  [Enabled](#sam-function-sqs-enabled): Boolean
  [FilterCriteria](#sam-function-sqs-filtercriteria): [FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)
  [FunctionResponseTypes](#sam-function-sqs-functionresponsetypes): List
  KmsKeyArn: String
  [MaximumBatchingWindowInSeconds](#sam-function-sqs-maximumbatchingwindowinseconds): Integer
  [MetricsConfig](#sam-function-sqs-metricsconfig): [MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)
  [ProvisionedPollerConfig](#sam-function-sqs-provisionedpollerconfig): [ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-provisionedpollerconfig)
  [Queue](#sam-function-sqs-queue): String
  ScalingConfig: [ScalingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-scalingconfig.html)
```

## Properties
<a name="sam-property-function-sqs-properties"></a>

 `BatchSize`   <a name="sam-function-sqs-batchsize"></a>
要在单个批次中检索的最大项目数。  
*类型*：整数  
*必需*：否  
*默认值*：10  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[BatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-batchsize)`属性。  
*最小值*：`1`  
*最大值*：`10000`

 `Enabled`   <a name="sam-function-sqs-enabled"></a>
禁用事件源映射以暂停轮询和调用。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[Enabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-enabled)`属性。

 `FilterCriteria`   <a name="sam-function-sqs-filtercriteria"></a>
定义用于确定 Lambda 是否应处理事件的条件的对象。有关更多信息，请参阅《AWS Lambda 开发人员指南》**中的 [AWS Lambda 事件筛选](https://docs.aws.amazon.com/lambda/latest/dg/invocation-eventfiltering.html)。  
*类型*：[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FilterCriteria](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-filtercriteria.html)`属性。

 `FunctionResponseTypes`   <a name="sam-function-sqs-functionresponsetypes"></a>
 当前应用于事件源映射的响应类型的列表。有关详细信息，请参阅*《AWS Lambda 开发人员指南》*中的[报告批处理项目失败](https://docs.aws.amazon.com/lambda/latest/dg/with-sqs.html#services-sqs-batchfailurereporting)。  
 *有效值*：`ReportBatchItemFailures`  
 *类型*：列表   
 *必需*：否   
 *CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[FunctionResponseTypes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-functionresponsetypes)`属性。

 `KmsKeyArn`   <a name="sam-function-sqs-kmskeyarn"></a>
用于加密与此事件相关信息的密钥的 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-kmskeyarn)`属性。

 `MaximumBatchingWindowInSeconds`   <a name="sam-function-sqs-maximumbatchingwindowinseconds"></a>
在调用函数之前收集记录的最长时间（以秒为单位）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MaximumBatchingWindowInSeconds](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-maximumbatchingwindowinseconds)`属性。

 `MetricsConfig`   <a name="sam-function-sqs-metricsconfig"></a>
一种选择性配置，用于获取增强型指标，这些指标针对事件源映射进行捕获，涵盖处理过程的每个阶段。有关示例，请参阅[MetricsConfig 事件](sam-property-function-dynamodb.md#sam-property-function-dynamodb-example-metricsconfigevent)。  
*类型*：[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[MetricsConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-metricsconfig)`属性。

 `ProvisionedPollerConfig`   <a name="sam-function-sqs-provisionedpollerconfig"></a>
用于增加计算事件源映射所使用的轮询器数量的配置。此配置允许最少 2 个轮询器和最多 2000 个轮询器。有关具体示例，请参阅 [ProvisionedPollerConfig 示例](#sam-property-function-sqs-example-provisionedpollerconfig)。  
*类型*：[ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-provisionedpollerconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ProvisionedPollerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-provisionedpollerconfig)`属性。

 `Queue`   <a name="sam-function-sqs-queue"></a>
队列的 ARN。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[EventSourceArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-eventsourcemapping.html#cfn-lambda-eventsourcemapping-eventsourcearn)`属性。

 `ScalingConfig`   <a name="sam-function-sqs-scalingconfig"></a>
扩展 SQS 轮询器的配置，以控制调用速率并设置最大并发调用次数。  
*类型*：`[ScalingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-scalingconfig.html)`  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::EventSourceMapping`资源的`[ ScalingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-eventsourcemapping-scalingconfig.html)`属性。

## 示例
<a name="sam-property-function-sqs--examples"></a>

### MetricsConfig 事件
<a name="sam-property-function-sqs-example-metricsconfigevent"></a>

以下是一个资源示例，它使用 `MetricsConfig` 属性来捕获其事件源映射的每个处理阶段。

```
Resources:
  FilteredEventsFunction:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: s3://sam-demo-bucket/metricsConfig.zip
      Handler: index.handler
      Runtime: nodejs16.x
      Events:
        KinesisStream:
          Type: Kinesis
          Properties:
            Stream: !GetAtt KinesisStream.Arn
            StartingPosition: LATEST
            MetricsConfig:
              Metrics:
              - EventCount
```

### 基本 SQS 事件
<a name="sam-property-function-sqs--examples--sqs-event"></a>

```
Events:
  SQSEvent:
    Type: SQS
    Properties:
      Queue: arn:aws:sqs:us-west-2:012345678901:my-queue
      BatchSize: 10
      Enabled: false
      FilterCriteria:
        Filters:
          - Pattern: '{"key": ["val1", "val2"]}'
```

### 为您的 SQS 队列配置部分批量报告
<a name="sam-property-function-sqs--examples--sqs-partial-batch"></a>

```
Events:
  SQSEvent:
    Type: SQS
    Properties:
      Enabled: true
      FunctionResponseTypes:
        - ReportBatchItemFailures
      Queue: !GetAtt MySqsQueue.Arn
      BatchSize: 10
```

### 带有配置了扩展的 SQS 事件的 Lambda 函数
<a name="sam-property-function-sqs--examples--sqs-event-scaling"></a>

```
MyFunction:
  Type: AWS::Serverless::Function
  Properties:
    ...
    Events:
      MySQSEvent:
        Type: SQS
        Properties:
          ...
          ScalingConfig:
            MaximumConcurrency: 10
```

### ProvisionedPollerConfig 示例
<a name="sam-property-function-sqs-example-provisionedpollerconfig"></a>

```
MyFunction:
  Type: AWS::Serverless::Function
  Properties:
    Handler: index.handler
    Runtime: nodejs18.x
    Timeout: 30
    Events:
      SQSEvent:
        Type: SQS
        Properties:
          Queue: !GetAtt MyQueue.Arn
          BatchSize: 10
          Enabled: True
          ProvisionedPollerConfig:
            MaximumPollers: 300
            MinimumPollers: 10
```

# FunctionCode
<a name="sam-property-function-functioncode"></a>

Lambda 函数的[部署程序包](https://docs.aws.amazon.com/lambda/latest/dg/deployment-package-v2.html)。

## 语法
<a name="sam-property-function-functioncode-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-functioncode-syntax.yaml"></a>

```
  [Bucket](#sam-function-functioncode-bucket): String
  [Key](#sam-function-functioncode-key): String
  [Version](#sam-function-functioncode-version): String
```

## Properties
<a name="sam-property-function-functioncode-properties"></a>

 `Bucket`   <a name="sam-function-functioncode-bucket"></a>
与您的函数位于同一 AWS 区域的 Amazon S3 存储桶。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``Code`数据类型的`[S3Bucket](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-s3bucket)`属性。

 `Key`   <a name="sam-function-functioncode-key"></a>
部署程序包的 Amazon S3 密钥。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``Code`数据类型的`[S3Key](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-s3key)`属性。

 `Version`   <a name="sam-function-functioncode-version"></a>
对于版本控制的对象，指要使用的部署程序包对象的版本。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function``Code`数据类型的`[S3ObjectVersion](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-code.html#cfn-lambda-function-code-s3objectversion)`属性。

## 示例
<a name="sam-property-function-functioncode--examples"></a>

### FunctionCode
<a name="sam-property-function-functioncode--examples--functioncode"></a>

`CodeUri`：函数代码示例

#### YAML
<a name="sam-property-function-functioncode--examples--functioncode--yaml"></a>

```
CodeUri:
  Bucket: sam-s3-demo-bucket-name
  Key: mykey-name
  Version: 121212
```

# FunctionUrlConfig
<a name="sam-property-function-functionurlconfig"></a>

使用指定的配置参数创建 AWS Lambda 函数 URL。Lambda 函数 URL 是一个 HTTPS 端点，可用于调用函数。

默认情况下，您创建的函数 URL 使用 Lambda 函数的 `$LATEST` 版本。如果为 Lambda 函数指定 `AutoPublishAlias`，则端点会连接到指定的函数别名。

有关更多信息，请参阅*AWS Lambda 开发人员*指南 URLs中的 [Lambda 函数](https://docs.aws.amazon.com/lambda/latest/dg/lambda-urls.html)。

## 语法
<a name="sam-property-function-functionurlconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-functionurlconfig-syntax.yaml"></a>

```
[AuthType](#sam-function-functionurlconfig-authtype): String
[Cors](#sam-function-functionurlconfig-cors): [Cors](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html)
[InvokeMode](#sam-function-functionurlconfig-invokemode): String
```

## Properties
<a name="sam-property-function-functionurlconfig-properties"></a>

 `AuthType`   <a name="sam-function-functionurlconfig-authtype"></a>
函数 URL 的身份验证类型。要使用 AWS Identity and Access Management (IAM) 来授权请求，请将设置为`AWS_IAM`。对于开放式访问，设置为 `NONE`。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Url`资源的`[AuthType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-url.html#cfn-lambda-url-authtype)`属性。

 `Cors`   <a name="sam-function-functionurlconfig-cors"></a>
适用于函数 URL 的 cross-origin resource sharing (CORS)（跨源资源共享）设置。  
*类型*：[Cors](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Url`资源的`[Cors](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-url-cors.html)`属性。

 `InvokeMode`  <a name="sam-function-functionurlconfig-invokemode"></a>
将会调用函数 URL 的模式。要让函数在调用完成后返回响应，请设置为 `BUFFERED`。要让函数流式传输响应，请设置为 `RESPONSE_STREAM`。默认值为 `BUFFERED`。  
*有效值*：`BUFFERED` 或 `RESPONSE_STREAM`  
*类型*：字符串  
*必需*：否  
*AWS CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Url`资源的[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-url.html#cfn-lambda-url-invokemode](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-url.html#cfn-lambda-url-invokemode)属性。

## 示例
<a name="sam-property-function-functionurlconfig--examples"></a>

### 函数 URL
<a name="sam-property-function-functionurlconfig--examples--function-url"></a>

以下示例创建了带函数 URL 的 Lambda 函数。函数 URL 使用 IAM 授权。

#### YAML
<a name="sam-property-function-functionurlconfig--examples--function-url--yaml"></a>

```
HelloWorldFunction:
  Type: AWS::Serverless::Function
  Properties:
    CodeUri: hello_world/
    Handler: index.handler
    Runtime: nodejs20.x
    FunctionUrlConfig:
      AuthType: AWS_IAM
      InvokeMode: RESPONSE_STREAM

Outputs:
  MyFunctionUrlEndpoint:
      Description: "My Lambda Function URL Endpoint"
      Value:
        Fn::GetAtt: HelloWorldFunctionUrl.FunctionUrl
```

# CapacityProviderConfig
<a name="sam-property-function-capacityproviderconfig"></a>

配置要将函数的已发布版本附加到的容量提供商。这使该函数能够在 Lambda 管理的客户拥有的 EC2 实例上运行。

**注意**  
此配置决定了函数的计算类型，需要在首次部署函数时进行指定。创建函数资源后，无法添加或删除它。

## 语法
<a name="sam-property-function-capacityproviderconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-capacityproviderconfig-syntax.yaml"></a>

```
[Arn](#sam-function-capacityproviderconfig-arn): String
[ExecutionEnvironmentMemoryGiBPerVCpu](#sam-function-capacityproviderconfig-executionenvironmentmemorygibpervcpu): Float
[PerExecutionEnvironmentMaxConcurrency](#sam-function-capacityproviderconfig-perexecutionenvironmentmaxconcurrency): Integer
```

## Properties
<a name="sam-property-function-capacityproviderconfig-properties"></a>

 `Arn`   <a name="sam-function-capacityproviderconfig-arn"></a>
用于此功能的容量提供者的 ARN。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是 SAM 所独有的。

 `ExecutionEnvironmentMemoryGiBPerVCpu`   <a name="sam-function-capacityproviderconfig-executionenvironmentmemorygibpervcpu"></a>
每个执行环境的内存（以 GiB 为单位）与 vCPU 的比例。  
每个 CPU 的内存比率不能超过函数的总内存 2048MB。支持的 memory-to-CPU比率为每个 CPU 2 GB、4GB 或 8GB。
*类型*：浮动  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[ExecutionEnvironmentMemoryGiBPerVCpu](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-lambdamanagedinstancescapacityproviderconfig)`属性。

 `PerExecutionEnvironmentMaxConcurrency`   <a name="sam-function-capacityproviderconfig-perexecutionenvironmentmaxconcurrency"></a>
每个执行环境（沙箱）的最大并发执行数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[PerExecutionEnvironmentMaxConcurrency](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-lambdamanagedinstancescapacityproviderconfig)`属性。

## 示例
<a name="sam-property-function-capacityproviderconfig-examples"></a>

### 容量提供程序配置
<a name="sam-property-function-capacityproviderconfig-examples-basic"></a>

以下示例显示了引用容量提供程序资源的容量提供程序配置。

```
CapacityProviderConfig:
  Arn: !GetAtt MyCapacityProvider.Arn
  ExecutionEnvironmentMemoryGiBPerVCpu: 4.0
  PerExecutionEnvironmentMaxConcurrency: 100
```

# FunctionScalingConfig
<a name="sam-property-function-functionscalingconfig"></a>

配置 Lambda 函数版本的扩展行为，控制可以创建的执行环境（沙箱）的数量。此配置适用于 \$1LATEST.PUBLISTED 和数字函数版本。

## 语法
<a name="sam-property-function-functionscalingconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-function-functionscalingconfig-syntax.yaml"></a>

```
[MinExecutionEnvironments](#sam-function-functionscalingconfig-minexecutionenvironments): Integer
[MaxExecutionEnvironments](#sam-function-functionscalingconfig-maxexecutionenvironments): Integer
```

## Properties
<a name="sam-property-function-functionscalingconfig-properties"></a>

 `MinExecutionEnvironments`   <a name="sam-function-functionscalingconfig-minexecutionenvironments"></a>
要为函数版本维护的最小执行环境数量。  
*类型*：整数  
*必需*：否  
*默认值*：`3`  
*最小值*：`0`  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[MinExecutionEnvironments](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-functionscalingconfig-minexecutionenvironments)`属性。

 `MaxExecutionEnvironments`   <a name="sam-function-functionscalingconfig-maxexecutionenvironments"></a>
可以为该函数版本创建的最大执行环境数量。  
*类型*：整数  
*必需*：否  
*默认值*：`3`  
*最小值*：`0`  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::Function`资源的`[MaxExecutionEnvironments](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-functionscalingconfig-maxexecutionenvironments)`属性。

## 示例
<a name="sam-property-function-functionscalingconfig-examples"></a>

### 函数缩放配置
<a name="sam-property-function-functionscalingconfig-examples-basic"></a>

以下示例显示了具有最小和最大执行环境的函数扩展配置。

```
FunctionScalingConfig:
  MinExecutionEnvironments: 5
  MaxExecutionEnvironments: 100
```

# AWS::Serverless::GraphQLApi
<a name="sam-resource-graphqlapi"></a>

使用 AWS Serverless Application Model (AWS SAM) `AWS::Serverless::GraphQLApi` 资源类型为您的无服务器应用程序创建和配置 AWS AppSync GraphQL API。

要了解更多信息 AWS AppSync，请参阅[什么是 AWS AppSync？](https://docs.aws.amazon.com/appsync/latest/devguide/what-is-appsync.html) 在《*AWS AppSync 开发人员指南》*中。

## 语法
<a name="sam-resource-graphqlapi-syntax"></a>

### YAML
<a name="sam-resource-graphqlapi-syntax-yaml"></a>

```
LogicalId:
  Type: AWS::Serverless::GraphQLApi
  Properties:
    ApiKeys: ApiKeys
    Auth: Auth
    Cache: [AWS::AppSync::ApiCache](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-apicache.html)
    DataSources: DataSource
    DomainName: [AWS::AppSync::DomainName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-domainname.html)
    Functions: Function
    Logging: [LogConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-logconfig.html)
    Name: String
    Resolvers: Resolver
    SchemaInline: String
    SchemaUri: String
    Tags:
    - [Tag](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html)
    XrayEnabled: Boolean
```

## Properties
<a name="sam-resource-graphqlapi-properties"></a>

`ApiKeys`  <a name="sam-graphqlapi-apikeys"></a>
创建可用于执行需要 API 密钥的 GraphQL 操作的唯一密钥。  
*类型*：[ApiKeys](sam-property-graphqlapi-apikeys.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`Auth`  <a name="sam-graphqlapi-auth"></a>
为您的 GraphQL API 配置身份验证。  
*类型*：[身份验证](sam-property-graphqlapi-auth.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`Cache`  <a name="sam-graphqlapi-cache"></a>
`CreateApiCache` 操作的输入。  
*类型*：[AWS::AppSync::ApiCache](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-apicache.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给[AWS::AppSync::ApiCache](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-apicache.html)资源。

`DataSources`  <a name="sam-graphqlapi-datasources"></a>
为中的函数创建 AWS AppSync 要连接的数据源。 AWS SAM 支持 Amazon DynamoDB AWS Lambda 和数据源。  
*类型*：[DataSource](sam-property-graphqlapi-datasource.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`DomainName`  <a name="sam-graphqlapi-domainname"></a>
GraphQL API 的自定义域名。  
*类型*：[AWS::AppSync::DomainName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-domainname.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给[AWS::AppSync::DomainName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-domainname.html)资源。 AWS SAM 自动生成[AWS::AppSync::DomainNameApiAssociation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-domainnameapiassociation.html)资源。

`Functions`  <a name="sam-graphqlapi-functions"></a>
在中配置函数GraphQL APIs 以执行某些操作。  
*类型*：[函数](sam-property-graphqlapi-function.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`Logging`  <a name="sam-graphqlapi-logging"></a>
为您的 GraphQL API 配置亚马逊 CloudWatch 日志。  
如果不指定此属性， AWS SAM 将生成`CloudWatchLogsRoleArn`并设置以下值：  
+ `ExcludeVerboseContent: true`
+ `FieldLogLevel: ALL`
要选择退出日志记录，请指定以下内容：  

```
Logging: false
```
*类型*：[LogConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-logconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[LogConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-logconfig)`属性。

`LogicalId`  <a name="sam-graphqlapi-logicalid"></a>
您的 GraphQL API 的唯一名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-name)`属性。

`Name`  <a name="sam-graphqlapi-name"></a>
GraphQL API 的名称。指定此属性以覆盖 `LogicalId` 值。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-name)`属性。

`Resolvers`  <a name="sam-graphqlapi-resolvers"></a>
为 GraphQL API 的字段配置解析程序。 AWS SAM 支持 [JavaScript 管道解析程序](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html#anatomy-of-a-pipeline-resolver-js)。  
*类型*：[解析程序](sam-property-graphqlapi-resolver.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`SchemaInline`  <a name="sam-graphqlapi-schemainline"></a>
GraphQL 架构的 SDL 格式的文本表示。  
*类型*：字符串  
*必填*：条件性。您必须指定 `SchemaInline` 或 `SchemaUri`。  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLSchema`资源的`[Definition](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlschema.html#cfn-appsync-graphqlschema-definition)`属性。

`SchemaUri`  <a name="sam-graphqlapi-schemauri"></a>
架构的 Amazon Simple Storage Service (Amazon S3) 存储桶 URI 或本地文件夹的路径。  
如果您指定本地文件夹的路径，则 CloudFormation 要求在部署之前先将文件上传到 Amazon S3。您可以使用 AWS SAM CLI 来简化此过程。有关更多信息，请参阅 [如何在 AWS SAM 部署时上传本地文件](deploy-upload-local-files.md)。  
*类型*：字符串  
*必填*：条件性。您必须指定 `SchemaInline` 或 `SchemaUri`。  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLSchema`资源的`[DefinitionS3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlschema.html#cfn-appsync-graphqlschema-definitions3location)`属性。

`Tags`  <a name="sam-graphqlapi-tags"></a>
此 GraphQL API 的标签（键值对）。使用标签标识和分类资源。  
*类型：*[标签](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html)列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[Tag](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-tags)`属性。

`XrayEnabled`  <a name="sam-graphqlapi-xrayenabled"></a>
指明是否对此资源使用 [AWS X-Ray 跟踪](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html)。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[XrayEnabled](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-xrayenabled)`属性。

## 返回值
<a name="sam-resource-graphqlapi-return-values"></a>

有关返回值的列表，请参阅[《CloudFormation 用户指南》](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#aws-resource-appsync-graphqlapi-return-values.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#aws-resource-appsync-graphqlapi-return-values.html)。

## 示例
<a name="sam-resource-graphqlapi-examples"></a>

### 以 DynamoDB 为数据来源的 GraphQL API
<a name="sam-resource-graphqlapi-examples-example1"></a>

在此示例中，我们创建了一个使用 DynamoDB 表作为数据来源的 GraphQL API。

**schema.graphql**

```
schema {
  query: Query
  mutation: Mutation
}

type Query {
  getPost(id: String!): Post
}

type Mutation {
  addPost(author: String!, title: String!, content: String!): Post!
}

type Post {
  id: String!
  author: String
  title: String
  content: String
  ups: Int!
  downs: Int!
  version: Int!
}
```

**template.yaml**

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  DynamoDBPostsTable:
    Type: AWS::Serverless::SimpleTable

  MyGraphQLAPI:
    Type: AWS::Serverless::GraphQLApi
    Properties:
      SchemaUri: ./sam_graphql_api/schema.graphql
      Auth:
        Type: AWS_IAM
      DataSources:
        DynamoDb:
          PostsDataSource:
            TableName: !Ref DynamoDBPostsTable
            TableArn: !GetAtt DynamoDBPostsTable.Arn
      Functions:
        preprocessPostItem:
          Runtime:
            Name: APPSYNC_JS
            Version: 1.0.0
          DataSource: NONE
          CodeUri: ./sam_graphql_api/preprocessPostItem.js
        createPostItem:
          Runtime:
            Name: APPSYNC_JS
            Version: "1.0.0"
          DataSource: PostsDataSource
          CodeUri: ./sam_graphql_api/createPostItem.js
        getPostFromTable:
          Runtime:
            Name: APPSYNC_JS
            Version: "1.0.0"
          DataSource: PostsDataSource
          CodeUri: ./sam_graphql_api/getPostFromTable.js
      Resolvers:
        Mutation:
          addPost:
            Runtime:
              Name: APPSYNC_JS
              Version: "1.0.0"
            Pipeline:
            - preprocessPostItem
            - createPostItem
        Query:
          getPost:
            CodeUri: ./sam_graphql_api/getPost.js
            Runtime:
              Name: APPSYNC_JS
              Version: "1.0.0"
            Pipeline:
            - getPostFromTable
```

**createPostItem.js**

```
import { util } from "@aws-appsync/utils";

export function request(ctx) {
  const { key, values } = ctx.prev.result;
  return {
    operation: "PutItem",
    key: util.dynamodb.toMapValues(key),
    attributeValues: util.dynamodb.toMapValues(values),
  };
}

export function response(ctx) {
  return ctx.result;
}
```

**getPostFromTable.js**

```
import { util } from "@aws-appsync/utils";

export function request(ctx) {
  return dynamoDBGetItemRequest({ id: ctx.args.id });
}

export function response(ctx) {
  return ctx.result;
}

/**
 * A helper function to get a DynamoDB item
 */
function dynamoDBGetItemRequest(key) {
  return {
    operation: "GetItem",
    key: util.dynamodb.toMapValues(key),
  };
}
```

**preprocessPostItem.js**

```
import { util } from "@aws-appsync/utils";

export function request(ctx) {
  const id = util.autoId();
  const { ...values } = ctx.args;
  values.ups = 1;
  values.downs = 0;
  values.version = 1;
  return { payload: { key: { id }, values: values } };
}

export function response(ctx) {
  return ctx.result;
}
```

解析程序代码如下：

**getPost.js**

```
export function request(ctx) {
  return {};
}

export function response(ctx) {
  return ctx.prev.result;
}
```

### 以 Lambda 函数为数据来源的 GraphQL API
<a name="sam-resource-graphqlapi-examples-example2"></a>

在此示例中，我们创建了一个使用 Lambda 函数作为数据来源的 GraphQL API。

**template.yaml**

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs20.x
      CodeUri: ./lambda

  MyGraphQLAPI:
    Type: AWS::Serverless::GraphQLApi
    Properties:
      Name: MyApi
      SchemaUri: ./gql/schema.gql
      Auth:
        Type: API_KEY
      ApiKeys:
        MyApiKey:
          Description: my api key
      DataSources:
        Lambda:
          MyLambdaDataSource:
            FunctionArn: !GetAtt MyLambdaFunction.Arn
      Functions:
        lambdaInvoker:
          Runtime:
            Name: APPSYNC_JS
            Version: 1.0.0
          DataSource: MyLambdaDataSource
          CodeUri: ./gql/invoker.js
      Resolvers:
        Mutation:
          addPost:
            Runtime:
              Name: APPSYNC_JS
              Version: 1.0.0
            Pipeline:
            - lambdaInvoker
        Query:
          getPost:
            Runtime:
              Name: APPSYNC_JS
              Version: 1.0.0
            Pipeline:
            - lambdaInvoker

Outputs:
  MyGraphQLAPI:
    Description: AppSync API
    Value: !GetAtt MyGraphQLAPI.GraphQLUrl
  MyGraphQLAPIMyApiKey:
    Description: API Key for authentication
    Value: !GetAtt MyGraphQLAPIMyApiKey.ApiKey
```

**schema.graphql**

```
schema {
  query: Query
  mutation: Mutation
}
type Query {
  getPost(id: ID!): Post
}
type Mutation {
  addPost(id: ID!, author: String!, title: String, content: String): Post!
}
type Post {
  id: ID!
  author: String!
  title: String
  content: String
  ups: Int
  downs: Int
}
```

函数如下：

**lambda/index.js**

```
exports.handler = async (event) => {
  console.log("Received event {}", JSON.stringify(event, 3));

  const posts = {
    1: {
      id: "1",
      title: "First book",
      author: "Author1",
      content: "Book 1 has this content",
      ups: "100",
      downs: "10",
    },
  };

  console.log("Got an Invoke Request.");
  let result;
  switch (event.field) {
    case "getPost":
      return posts[event.arguments.id];
    case "addPost":
      // return the arguments back
      return event.arguments;
    default:
      throw new Error("Unknown field, unable to resolve " + event.field);
  }
};
```

**invoker.js**

```
import { util } from "@aws-appsync/utils";

export function request(ctx) {
  const { source, args } = ctx;
  return {
    operation: "Invoke",
    payload: { field: ctx.info.fieldName, arguments: args, source },
  };
}

export function response(ctx) {
  return ctx.result;
}
```

# ApiKeys
<a name="sam-property-graphqlapi-apikeys"></a>

创建可用于执行需要 API 密钥的 GraphQL 操作的唯一密钥。

## 语法
<a name="sam-property-graphqlapi-apikeys-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-apikeys-syntax-yaml"></a>

```
LogicalId:
  ApiKeyId: String
  Description: String
  ExpiresOn: Double
```

## Properties
<a name="sam-property-graphqlapi-apikeys-properties"></a>

`ApiKeyId`  <a name="sam-graphqlapi-apikeys-apikeyid"></a>
您的 API 密钥的唯一名称。指定以覆盖 `LogicalId` 值。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::ApiKey`资源的`[ApiKeyId](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-apikey.html#cfn-appsync-apikey-apikeyid)`属性。

`Description`  <a name="sam-graphqlapi-apikeys-description"></a>
您的 API 键的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::ApiKey`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-apikey.html#cfn-appsync-apikey-description)`属性。

`ExpiresOn`  <a name="sam-graphqlapi-apikeys-expireson"></a>
API 密钥到期的时间。日期表示为自纪元以来的秒数，向下舍入到最接近的小时。  
*类型*：双精度  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::ApiKey`资源的`[Expires](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-apikey.html#cfn-appsync-apikey-expires)`属性。

`LogicalId`  <a name="sam-graphqlapi-apikeys-logicalid"></a>
您的 API 密钥的唯一名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::ApiKey`资源的`[ApiKeyId](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-apikey.html#cfn-appsync-apikey-apikeyid)`属性。

# Auth
<a name="sam-property-graphqlapi-auth"></a>

为 GraphQL API 配置授权。

## 语法
<a name="sam-property-graphqlapi-auth-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-auth-syntax-yaml"></a>

```
Additional:
- AuthProvider
LambdaAuthorizer: [LambdaAuthorizerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-lambdaauthorizerconfig.html)
OpenIDConnect: [OpenIDConnectConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-openidconnectconfig.html)
Type: String
UserPool: [UserPoolConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-userpoolconfig.html)
```

## Properties
<a name="sam-property-graphqlapi-auth-properties"></a>

`Additional`  <a name="sam-graphqlapi-auth-additional"></a>
GraphQL API 的其他授权类型列表。  
*类型*：清单 [AuthProvider](sam-property-graphqlapi-auth-authprovider.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`LambdaAuthorizer`  <a name="sam-graphqlapi-auth-lambdaauthorizer"></a>
为 Lambda 函数授权方指定可选的授权配置。如果 `Type` 被指定为 `AWS_LAMBDA`，则可以配置此可选属性。  
*类型*:[LambdaAuthorizerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-lambdaauthorizerconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[ LambdaAuthorizerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-lambdaauthorizerconfig.html)`属性。

`OpenIDConnect`  <a name="sam-graphqlapi-auth-openidconnect"></a>
为您的 OpenID Connect 合规服务指定可选的授权配置。如果 `Type` 被指定为 `OPENID_CONNECT`，则可以配置此可选属性。  
*类型*：[Open IDConnect Config](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-openidconnectconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[ OpenIDConnectConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-openidconnectconfig.html)`属性。

`Type`  <a name="sam-graphqlapi-auth-type"></a>
应用程序和您的 AWS AppSync GraphQL API 之间的默认授权类型。  
有关允许值的列表和描述，请参阅*《AWS AppSync 开发人员指南》*中的[授权和身份验证](https://docs.aws.amazon.com/appsync/latest/devguide/security-authz.html)。  
当您指定 Lambda 授权方 () 时， AWS SAM 会创建一个 AWS Identity and Access Management (IAM`AWS_LAMBDA`) 策略来在您的 API GraphQL 和 Lambda 函数之间配置权限。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[AuthenticationType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-authenticationtype)`属性。

`UserPool`  <a name="sam-graphqlapi-auth-userpool"></a>
指定可选的授权配置，以使用 Amazon Cognito 用户群体。如果 `Type` 被指定为 `AMAZON_COGNITO_USER_POOLS`，则可以配置此可选属性。  
*类型*:[UserPoolConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-userpoolconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi`资源的`[ UserPoolConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-userpoolconfig.html)`属性。

## 示例
<a name="sam-property-graphqlapi-auth-examples"></a>

### 配置默认授权类型和其他授权类型
<a name="sam-property-graphqlapi-auth-examples-example1"></a>

在此示例中，首先将 Lambda 授权方配置为 GraphQL API 的默认授权类型。

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyGraphQLAPI:
    Type: AWS::Serverless::GraphQLApi
    Properties:
      Auth:
        Type: AWS_LAMBDA
        LambdaAuthorizer:
          AuthorizerUri: !GetAtt Authorizer1.Arn
          AuthorizerResultTtlInSeconds: 10
          IdentityValidationExpression: hello
```

然后，在 AWS SAM 模板中添加以下内容，为 GraphQL API 配置其他授权类型：

```
        Additional:
        - Type: AWS_IAM
        - Type: API_KEY
        - Type: OPENID_CONNECT
          OpenIDConnect:
            AuthTTL: 10
            ClientId: myId
            IatTTL: 10
            Issuer: prod
```

这将生成以下 AWS SAM 模板：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyGraphQLAPI:
    Type: AWS::Serverless::GraphQLApi
    Properties:
      Auth:
        Type: AWS_LAMBDA
        LambdaAuthorizer:
          AuthorizerUri: !GetAtt Authorizer1.Arn
          AuthorizerResultTtlInSeconds: 10
          IdentityValidationExpression: hello
        Additional:
        - Type: AWS_IAM
        - Type: API_KEY
        - Type: OPENID_CONNECT
          OpenIDConnect:
            AuthTTL: 10
            ClientId: myId
            IatTTL: 10
            Issuer: prod
```

# AuthProvider
<a name="sam-property-graphqlapi-auth-authprovider"></a>

您的其他 GraphQL API 授权类型的可选授权配置。

## 语法
<a name="sam-property-graphqlapi-auth-authprovider-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-auth-authprovider-syntax-yaml"></a>

```
LambdaAuthorizer: [LambdaAuthorizerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-lambdaauthorizerconfig.html)
OpenIDConnect: [OpenIDConnectConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-openidconnectconfig.html)
Type: String
UserPool: [UserPoolConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-userpoolconfig.html)
```

## Properties
<a name="sam-property-graphqlapi-auth-authprovider-properties"></a>

`LambdaAuthorizer`  <a name="sam-graphqlapi-auth-authprovider-lambdaauthorizer"></a>
为您的 AWS Lambda 函数授权方指定可选的授权配置。如果 `Type` 被指定为 `AWS_LAMBDA`，则可以配置此可选属性。  
*类型*:[ LambdaAuthorizerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-lambdaauthorizerconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi``[ AdditionalAuthenticationProvider](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-additionalauthenticationprovider.html)`对象的`[ LambdaAuthorizerConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-lambdaauthorizerconfig.html)`属性。

`OpenIDConnect`  <a name="sam-graphqlapi-auth-authprovider-openidconnect"></a>
为您的 OpenID Connect 合规服务指定可选的授权配置。如果 `Type` 被指定为 `OPENID_CONNECT`，则可以配置此可选属性。  
*类型*：[Open IDConnect Config](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-openidconnectconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi``[ AdditionalAuthenticationProvider](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-additionalauthenticationprovider.html)`对象的`[ OpenIDConnectConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-openidconnectconfig.html)`属性。

`Type`  <a name="sam-graphqlapi-auth-authprovider-type"></a>
应用程序和您的 AWS AppSync GraphQL API 之间的默认授权类型。  
有关允许值的列表和描述，请参阅*《AWS AppSync 开发人员指南》*中的[授权和身份验证](https://docs.aws.amazon.com/appsync/latest/devguide/security-authz.html)。  
当您指定 Lambda 授权方 () 时， AWS SAM 会创建一个 AWS Identity and Access Management (IAM`AWS_LAMBDA`) 策略来在您的 API GraphQL 和 Lambda 函数之间配置权限。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi``[ AdditionalAuthenticationProvider](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-additionalauthenticationprovider.html)`对象的`[ AuthenticationType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-additionalauthenticationprovider.html#cfn-appsync-graphqlapi-additionalauthenticationprovider-authenticationtype)`属性。

`UserPool`  <a name="sam-graphqlapi-auth-authprovider-userpool"></a>
指定可选的授权配置，以使用 Amazon Cognito 用户群体。如果 `Type` 被指定为 `AMAZON_COGNITO_USER_POOLS`，则可以配置此可选属性。  
*类型*:[ UserPoolConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-graphqlapi.html#cfn-appsync-graphqlapi-userpoolconfig)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::GraphQLApi``[ AdditionalAuthenticationProvider](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-additionalauthenticationprovider.html)`对象的`[ UserPoolConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-graphqlapi-userpoolconfig.html)`属性。

# DataSource
<a name="sam-property-graphqlapi-datasource"></a>

配置可与 GraphQL API 解析程序连接的数据源。您可以使用 AWS Serverless Application Model (AWS SAM) 模板来配置与以下数据源的连接：
+ Amazon DynamoDB
+ AWS Lambda

要了解有关数据源的更多信息，请参阅*《AWS AppSync 开发人员指南》*中的[附加数据源](https://docs.aws.amazon.com/appsync/latest/devguide/attaching-a-data-source.html)。

## 语法
<a name="sam-property-graphqlapi-datasource-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-datasource-syntax-yaml"></a>

```
DynamoDb: DynamoDb
Lambda: Lambda
```

## Properties
<a name="sam-property-graphqlapi-datasource-properties"></a>

`DynamoDb`  <a name="sam-graphqlapi-datasource-dynamodb"></a>
将 DynamoDB 表配置为 GraphQL API 解析程序的数据源。  
*类型*：[DynamoDb](sam-property-graphqlapi-datasource-dynamodb.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`Lambda`  <a name="sam-graphqlapi-datasource-lambda"></a>
将 Lambda 函数配置为 GraphQL API 解析程序的数据源。  
*类型*：[Lambda](sam-property-graphqlapi-datasource-lambda.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

# DynamoDb
<a name="sam-property-graphqlapi-datasource-dynamodb"></a>

将 Amazon DynamoDB 表配置为 GraphQL API 解析程序的数据源。

## 语法
<a name="sam-property-graphqlapi-datasource-dynamodb-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-datasource-dynamodb-syntax-yaml"></a>

```
LogicalId:
  DeltaSync: [DeltaSyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-deltasyncconfig.html)
  Description: String
  Name: String
  Permissions: List
  Region: String
  ServiceRoleArn: String
  TableArn: String
  TableName: String
  UseCallerCredentials: Boolean
  Versioned: Boolean
```

## Properties
<a name="sam-property-graphqlapi-datasource-dynamodb-properties"></a>

`DeltaSync`  <a name="sam-graphqlapi-datasource-dynamodb-deltasync"></a>
描述增量同步配置。  
*类型*：[DeltaSyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-deltasyncconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource DynamoDBConfig`对象的`[DeltaSyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-dynamodbconfig.html#cfn-appsync-datasource-dynamodbconfig-deltasyncconfig)`属性。

`Description`  <a name="sam-graphqlapi-datasource-dynamodb-description"></a>
数据源的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-description)`属性。

`LogicalId`  <a name="sam-graphqlapi-datasource-dynamodb-logicalid"></a>
数据源的唯一名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-name)`属性。

`Name`  <a name="sam-graphqlapi-datasource-dynamodb-name"></a>
数据源的名称。指定此属性以覆盖 `LogicalId` 值。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-name)`属性。

`Permissions`  <a name="sam-graphqlapi-datasource-dynamodb-permissions"></a>
使用 [AWS SAM 连接器](managing-permissions-connectors.md) 配置对数据源的权限。您可以在列表中提供以下任何值：  
+ `Read` - 允许解析程序读取数据源。
+ `Write` - 允许解析程序将数据写入到数据源。
AWS SAM 使用在部署时转换的`AWS::Serverless::Connector`资源来配置您的权限。要了解有关生成的资源的信息，请参阅[CloudFormation 指定时生成的资源 AWS::Serverless::Connector](sam-specification-generated-resources-connector.md)。  
您可以指定 `Permissions` 或 `ServiceRoleArn`，但不能同时指定两者。如果两者都未指定，则 AWS SAM 将生成默认值为 `Read` and `Write`。要撤消对数据源的访问权限，请从模板中移除 DynamoDB 对象。 AWS SAM 
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。它类似于 `AWS::Serverless::Connector` 资源的 `Permissions` 属性。

`Region`  <a name="sam-graphqlapi-datasource-dynamodb-region"></a>
你的 AWS 区域 DynamoDB 表的。如果未指定，则 AWS SAM 使用`[AWS::Region](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/pseudo-parameter-reference.html#cfn-pseudo-param-region)`。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource DynamoDBConfig`对象的`[AwsRegion](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-dynamodbconfig.html#cfn-appsync-datasource-dynamodbconfig-awsregion)`属性。

`ServiceRoleArn`  <a name="sam-graphqlapi-datasource-dynamodb-servicerolearn"></a>
数据 AWS Identity and Access Management 源的 (IAM) 服务角色 ARN。在访问数据源时，系统将代入此角色。  
您可以指定 `Permissions` 或 `ServiceRoleArn`，但不能同时指定两者。  
*类型*：字符串  
*必填项*：否。 如果未指定，则 AWS SAM 应用的默认值`Permissions`。  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource`资源的`[ServiceRoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-servicerolearn)`属性。

`TableArn`  <a name="sam-graphqlapi-datasource-dynamodb-tablearn"></a>
DynamoDB 表的 ARN。  
*类型*：字符串  
*必填*：条件性。如果未指定 `ServiceRoleArn`，则需要有 `TableArn`。  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`TableName`  <a name="sam-graphqlapi-datasource-dynamodb-tablename"></a>
表名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource DynamoDBConfig`对象的`[TableName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-dynamodbconfig.html#cfn-appsync-datasource-dynamodbconfig-tablename)`属性。

`UseCallerCredentials`  <a name="sam-graphqlapi-datasource-dynamodb-usecallercredentials"></a>
设置为 `true` 以将 IAM 与此数据源一起使用。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource DynamoDBConfig`对象的`[UseCallerCredentials](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-dynamodbconfig.html#cfn-appsync-datasource-dynamodbconfig-usecallercredentials)`属性。

`Versioned`  <a name="sam-graphqlapi-datasource-dynamodb-versioned"></a>
设置为 `true` 以将[冲突检测、冲突解决和同步](https://docs.aws.amazon.com/appsync/latest/devguide/conflict-detection-and-sync.html)与该数据源一起使用。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource DynamoDBConfig`对象的`[Versioned](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-dynamodbconfig.html#cfn-appsync-datasource-dynamodbconfig-versioned)`属性。

# Lambda
<a name="sam-property-graphqlapi-datasource-lambda"></a>

将 AWS Lambda 函数配置为 GraphQL API 解析器的数据源。

## 语法
<a name="sam-property-graphqlapi-datasource-lambda-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-datasource-lambda-syntax-yaml"></a>

```
LogicalId:
  Description: String
  FunctionArn: String
  Name: String
  ServiceRoleArn: String
```

## Properties
<a name="sam-property-graphqlapi-datasource-lambda-properties"></a>

`Description`  <a name="sam-graphqlapi-datasource-lambda-description"></a>
数据源的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-description)`属性。

`FunctionArn`  <a name="sam-graphqlapi-datasource-lambda-functionarn"></a>
Lambda 函数的 ARN。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource LambdaConfig`对象的`[LambdaFunctionArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-datasource-lambdaconfig.html#cfn-appsync-datasource-lambdaconfig-lambdafunctionarn)`属性。

`LogicalId`  <a name="sam-graphqlapi-datasource-lambda-logicalid"></a>
数据源的唯一名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-name)`属性。

`Name`  <a name="sam-graphqlapi-datasource-lambda-name"></a>
数据源的名称。指定此属性以覆盖 `LogicalId` 值。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-name)`属性。

`ServiceRoleArn`  <a name="sam-graphqlapi-datasource-lambda-servicerolearn"></a>
数据 AWS Identity and Access Management 源的 (IAM) 服务角色 ARN。在访问数据源时，系统将代入此角色。  
要撤销对数据源的访问权限，请从 AWS SAM 模板中移除 Lambda 对象。
*类型*：字符串  
*必填项*：否。 如果未指定， AWS SAM 将使用配置`Write`权限[AWS SAM 连接器](managing-permissions-connectors.md)。  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::DataSource`资源的`[ServiceRoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-servicerolearn)`属性。

# 函数
<a name="sam-property-graphqlapi-function"></a>

在中配置函数GraphQL APIs 以执行某些操作。

## 语法
<a name="sam-property-graphqlapi-function-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-function-syntax-yaml"></a>

```
LogicalId:
  CodeUri: String
  DataSource: String
  Description: String
  Id: String
  InlineCode: String
  MaxBatchSize: Integer
  Name: String
  Runtime: Runtime
  Sync: [SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-functionconfiguration-syncconfig.html)
```

## Properties
<a name="sam-property-graphqlapi-function-properties"></a>

`CodeUri`  <a name="sam-graphqlapi-function-codeuri"></a>
函数代码的 Amazon Simple Storage Service (Amazon S3) URI 或本地文件夹路径。  
如果您指定本地文件夹的路径，则 CloudFormation 要求在部署之前先将文件上传到 Amazon S3。您可以使用 AWS SAM CLI 来简化此过程。有关更多信息，请参阅 [如何在 AWS SAM 部署时上传本地文件](deploy-upload-local-files.md)。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration`资源的`[CodeS3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-codes3location)`属性。

`DataSource`  <a name="sam-graphqlapi-function-datasource"></a>
此函数将附加到的数据源的名称。  
+ 要引用 `AWS::Serverless::GraphQLApi` 资源中的数据源，请指定其逻辑 ID。
+ 要引用 `AWS::Serverless::GraphQLApi` 资源之外的数据源，请使用 `Fn::GetAtt` 内置函数提供其 `Name` 属性。例如 `!GetAtt MyLambdaDataSource.Name`。
+ 要引用其他堆栈中的数据源，请使用 `[Fn::ImportValue](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html)`。
如果指定了变体，`[NONE | None | none]`则 AWS SAM 将为该`AWS::AppSync::DataSource``[Type](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-datasource.html#cfn-appsync-datasource-type)`对象生成一个`None`值。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration`资源的`[DataSourceName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-datasourcename)`属性。

`Description`  <a name="sam-graphqlapi-function-description"></a>
函数的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-description)`属性。

`Id`  <a name="sam-graphqlapi-function-id"></a>
位于 `AWS::Serverless::GraphQLApi` 资源外的函数的函数 ID。  
+ 要在同一 AWS SAM 模板中引用函数，请使用`Fn::GetAtt`内部函数。例如 `Id: !GetAtt createPostItemFunc.FunctionId`。
+ 要引用其他堆栈中的函数，请使用 `[Fn::ImportValue](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html)`。
使用时`Id`，不允许使用所有其他属性。 AWS SAM 将自动传递您引用的函数的函数 ID。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`InlineCode`  <a name="sam-graphqlapi-function-inlinecode"></a>
包含请求和响应函数的函数代码。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration`资源的`[Code](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-code)`属性。

`LogicalId`  <a name="sam-graphqlapi-function-logicalid"></a>
函数的唯一名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-name)`属性。

`MaxBatchSize`  <a name="sam-graphqlapi-function-maxbatchsize"></a>
向 `BatchInvoke` 操作中单个 AWS Lambda 函数发送的解析程序请求输入的最大数量。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration`资源的[MaxBatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-maxbatchsize)属性。

`Name`  <a name="sam-graphqlapi-function-name"></a>
函数的名称。指定以覆盖 `LogicalId` 值。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-name)`属性。

`Runtime`  <a name="sam-graphqlapi-function-runtime"></a>
描述 AWS AppSync 管道解析器或 AWS AppSync 函数使用的运行时。指定要使用的运行时的名称和版本。  
*类型*：[运行时](sam-property-graphqlapi-function-runtime.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。它类似于 `AWS::AppSync::FunctionConfiguration` 资源的 `[Runtime](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-runtime)` 属性。

`Sync`  <a name="sam-graphqlapi-function-sync"></a>
描述函数的同步配置。  
指定在调用函数时要使用的冲突检测策略和解决策略。  
*类型*：[SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-functionconfiguration-syncconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration`资源的`[SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-functionconfiguration.html#cfn-appsync-functionconfiguration-syncconfig)`属性。

# 运行时
<a name="sam-property-graphqlapi-function-runtime"></a>

管道解析程序或函数的运行时间。指定要使用的名称和版本。

## 语法
<a name="sam-property-graphqlapi-function-runtime-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-function-runtime-syntax-yaml"></a>

```
Name: String
Version: String
```

## Properties
<a name="sam-property-graphqlapi-function-runtime-properties"></a>

`Name`  <a name="sam-graphqlapi-function-runtime-name"></a>
要使用的运行时系统的名称。当前，允许的唯一值为 `APPSYNC_JS`。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration AppSyncRuntime`对象的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-functionconfiguration-appsyncruntime.html#cfn-appsync-functionconfiguration-appsyncruntime-name)`属性。

`Version`  <a name="sam-graphqlapi-function-runtime-version"></a>
要使用的运行时系统的版本。当前允许的唯一版本为 `1.0.0`。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::FunctionConfiguration AppSyncRuntime`对象的`[RuntimeVersion](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-functionconfiguration-appsyncruntime.html#cfn-appsync-functionconfiguration-appsyncruntime-runtimeversion)`属性。

# 解析程序
<a name="sam-property-graphqlapi-resolver"></a>

为 GraphQL API 的字段配置解析器。 AWS Serverless Application Model (AWS SAM) 支持[JavaScript 管道解析器](https://docs.aws.amazon.com/appsync/latest/devguide/resolver-reference-overview-js.html)。

## 语法
<a name="sam-property-graphqlapi-resolver-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-resolver-syntax-yaml"></a>

```
OperationType:
  LogicalId:
    Caching: [CachingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-cachingconfig.html)
    CodeUri: String
    FieldName: String
    InlineCode: String 
    MaxBatchSize: Integer
    Pipeline: List
    Runtime: Runtime
    Sync: [SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-syncconfig.html)
```

## Properties
<a name="sam-property-graphqlapi-resolver-properties"></a>

`Caching`  <a name="sam-graphqlapi-resolver-caching"></a>
激活了缓存的解析程序的缓存配置。  
*类型*：[CachingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-cachingconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver`资源的`[CachingConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-cachingconfig)`属性。

`CodeUri`  <a name="sam-graphqlapi-resolver-codeuri"></a>
解析程序函数代码的 Amazon Simple Storage Service (Amazon S3) URI 或本地文件夹路径。  
如果您指定本地文件夹的路径，则 CloudFormation 要求在部署之前先将文件上传到 Amazon S3。您可以使用 AWS SAM CLI 来简化此过程。有关更多信息，请参阅 [如何在 AWS SAM 部署时上传本地文件](deploy-upload-local-files.md)。  
如果两者均未提供`CodeUri`或`InlineCode`，则 AWS SAM 将生成`InlineCode`将请求重定向到第一个管道函数并接收来自最后一个管道函数的响应。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver`资源的`[CodeS3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-codes3location)`属性。

`FieldName`  <a name="sam-graphqlapi-resolver-fieldname"></a>
解析程序的名称。指定此属性以覆盖 `LogicalId` 值。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver`资源的`[FieldName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-fieldname)`属性。

`InlineCode`  <a name="sam-graphqlapi-resolver-inlinecode"></a>
包含请求和响应函数的解析程序代码。  
如果两者均未提供`CodeUri`或`InlineCode`，则 AWS SAM 将生成`InlineCode`将请求重定向到第一个管道函数并接收来自最后一个管道函数的响应。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver`资源的`[Code](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-code)`属性。

`LogicalId`  <a name="sam-graphqlapi-resolver-logicalid"></a>
解析程序的唯一名称。在 GraphQL 架构中，解析程序名称应与其使用的字段名称相匹配。对`LogicalId` 也使用这个字段名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`MaxBatchSize`  <a name="sam-graphqlapi-resolver-maxbatchsize"></a>
向 `BatchInvoke` 操作中单个 AWS Lambda 函数发送的解析程序请求输入的最大数量。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver`资源的`[MaxBatchSize](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-maxbatchsize)`属性。

`OperationType`  <a name="sam-graphqlapi-resolver-operationtype"></a>
与解析程序关联的 GraphQL 操作类型。例如，`Query`、`Mutation` 或 `Subscription`。您可以按`LogicalId` 将多个解析程序嵌套在单个`OperationType`中。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver`资源的`[TypeName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-typename)`属性。

`Pipeline`  <a name="sam-graphqlapi-resolver-pipeline"></a>
与管道解决程序关联的函数。在列表中按逻辑 ID 指定函数。  
*类型*：列表  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。它类似于 `AWS::AppSync::Resolver` 资源的 `[PipelineConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-pipelineconfig)` 属性。

`Runtime`  <a name="sam-graphqlapi-resolver-runtime"></a>
管道解析程序或函数的运行时间。指定要使用的名称和版本。  
*类型*：[运行时](sam-property-graphqlapi-resolver-runtime.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。它类似于 `AWS::AppSync::Resolver` 资源的 `[Runtime](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-runtime)` 属性。

`Sync`  <a name="sam-graphqlapi-resolver-sync"></a>
描述解析程序的同步配置。  
指定在调用解析程序时要使用的冲突检测策略和解决策略。  
*类型*：[SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-syncconfig.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver`资源的`[SyncConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-appsync-resolver.html#cfn-appsync-resolver-syncconfig)`属性。

## 示例
<a name="sam-property-graphqlapi-resolver-examples"></a>

### 使用 AWS SAM 生成的解析器函数代码并将字段另存为变量
<a name="sam-property-graphqlapi-resolver-examples-example1"></a>

以下是我们的示例使用的 GraphQL 架构：

```
schema {
  query: Query
  mutation: Mutation
}

type Query {
  getPost(id: ID!): Post
}

type Mutation {
  addPost(author: String!, title: String!, content: String!): Post!
}

type Post {
  id: ID!
  author: String
  title: String
  content: String
}
```

以下是我们 AWS SAM 模板的片段：

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
...
Resources:
  MyGraphQLApi:
    Type: AWS::Serverless::GraphQLApi
    Properties:
      ...
      Functions:
        preprocessPostItem:
          ...
        createPostItem:
          ...
      Resolvers:
        Mutation:
          addPost:
            Runtime:
              Name: APPSYNC_JS
              Version: 1.0.0
            Pipeline:
            - preprocessPostItem
            - createPostItem
```

在我们的 AWS SAM 模板中，我们没有指定`CodeUri`或`InlineCode`。部署时， AWS SAM 会自动为我们的解析器生成以下内联代码：

```
export function request(ctx) {
  return {};
}

export function response(ctx) {
  return ctx.prev.result;
}
```

这个默认的解析程序代码会将请求重定向到第一个管道函数，并接收来自最后一个管道函数的响应。

在第一个管道函数中，可以使用提供的 `args` 字段来解析请求对象并创建变量。然后就可以在函数中使用这些变量。以下是 `preprocessPostItem` 函数的示例：

```
import { util } from "@aws-appsync/utils";

export function request(ctx) {
  const author = ctx.args.author;
  const title = ctx.args.title;
  const content = ctx.args.content;
  
  // Use variables to process data
  
}

export function response(ctx) {
  return ctx.result;
}
```

# 运行时
<a name="sam-property-graphqlapi-resolver-runtime"></a>

管道解析程序或函数的运行时间。指定要使用的名称和版本。

## 语法
<a name="sam-property-graphqlapi-resolver-runtime-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-graphqlapi-resolver-runtime-syntax-yaml"></a>

```
Name: String
Version: String
```

## Properties
<a name="sam-property-graphqlapi-resolver-runtime-properties"></a>

`Name`  <a name="sam-graphqlapi-resolver-runtime-name"></a>
要使用的运行时系统的名称。当前，允许的唯一值为 `APPSYNC_JS`。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver AppSyncRuntime`对象的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-appsyncruntime.html#cfn-appsync-resolver-appsyncruntime-name)`属性。

`Version`  <a name="sam-graphqlapi-resolver-runtime-version"></a>
要使用的运行时系统的版本。当前允许的唯一版本为 `1.0.0`。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::AppSync::Resolver AppSyncRuntime`对象的`[RuntimeVersion](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-appsync-resolver-appsyncruntime.html#cfn-appsync-resolver-appsyncruntime-runtimeversion)`属性。

# AWS::Serverless::HttpApi
<a name="sam-resource-httpapi"></a>

创建 Amazon API Gateway HTTP API，这使您能够以比 REST 更低的延迟和更低的成本 RESTful APIs 进行创作 APIs。有关更多信息，请参阅《*API Gateway 开发者指南》APIs中的 “使用* [HTTP](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html)”。

我们建议您使用 CloudFormation 挂钩或 IAM 策略来验证 API Gateway 资源是否附加了授权者来控制对它们的访问。

有关使用 CloudFormation 挂钩的更多信息，请参阅 *CloudFormation CLI 用户指南*和[apigw-enforce-authorizer](https://github.com/aws-cloudformation/aws-cloudformation-samples/tree/main/hooks/python-hooks/apigw-enforce-authorizer/) GitHub 存储库中的[注册挂钩](https://docs.aws.amazon.com/cloudformation-cli/latest/userguide/registering-hook-python.html)。

有关使用 IAM 策略的更多信息，请参阅*《API Gateway 开发人员指南》*中的[要求 API 路由具有授权](https://docs.aws.amazon.com/apigateway/latest/developerguide/security_iam_id-based-policy-examples.html#security_iam_id-based-policy-examples-require-authorization)。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-httpapi-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-resource-httpapi-syntax.yaml"></a>

```
Type: AWS::Serverless::HttpApi
Properties:
  [AccessLogSettings](#sam-httpapi-accesslogsettings): [AccessLogSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-accesslogsettings)
  [Auth](#sam-httpapi-auth): HttpApiAuth
  [CorsConfiguration](#sam-httpapi-corsconfiguration): String | HttpApiCorsConfiguration
  [DefaultRouteSettings](#sam-httpapi-defaultroutesettings): [RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)
  [DefinitionBody](#sam-httpapi-definitionbody): JSON
  [DefinitionUri](#sam-httpapi-definitionuri): String | HttpApiDefinition
  [Description](#sam-httpapi-description): String
  [DisableExecuteApiEndpoint](#sam-httpapi-disableexecuteapiendpoint): Boolean
  [Domain](#sam-httpapi-domain): HttpApiDomainConfiguration
  [FailOnWarnings](#sam-httpapi-failonwarnings): Boolean
  Name: String
  PropagateTags: Boolean
  [RouteSettings](#sam-httpapi-routesettings): [RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)
  [StageName](#sam-httpapi-stagename): String
  [StageVariables](#sam-httpapi-stagevariables): [Json](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-stagevariables)
  [Tags](#sam-httpapi-tags): Map
```

## Properties
<a name="sam-resource-httpapi-properties"></a>

 `AccessLogSettings`   <a name="sam-httpapi-accesslogsettings"></a>
某个阶段的访问日志记录的设置。  
*类型*：[AccessLogSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-accesslogsettings)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Stage`资源的`[AccessLogSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-accesslogsettings)`属性。

 `Auth`   <a name="sam-httpapi-auth"></a>
配置授权，以控制对 API Gateway HTTP API 的访问。  
有关更多信息，请参阅《*API Gateway 开发*者指南》中的 “[ APIs 使用 JWT 授权者控制 HTTP 访问权限](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html)”。  
*类型*：[HttpApiAuth](sam-property-httpapi-httpapiauth.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `CorsConfiguration`   <a name="sam-httpapi-corsconfiguration"></a>
管理所有 API Gateway HTTP 的跨源资源共享 (CORS)。 APIs以字符串形式指定要允许的域，或者指定一个 `HttpApiCorsConfiguration` 对象。请注意，CORS AWS SAM 需要修改你的 OpenAPI 定义，因此 CORS 只有在指定`DefinitionBody`了该属性时才起作用。  
有关更多信息，请参阅*《API Gateway 开发人员指南》*中的[为 HTTP API 配置 CORS](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html)。  
如果`CorsConfiguration`在 OpenAPI 定义和属性级别都进行了设置，则会将两个配置源 AWS SAM 合并，且属性优先。如果将此属性设置为 `true`，则允许所有来源。
*类型*：字符串 \$1 [HttpApiCorsConfiguration](sam-property-httpapi-httpapicorsconfiguration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `DefaultRouteSettings`   <a name="sam-httpapi-defaultroutesettings"></a>
此 HTTP API 的默认路由设置。这些设置适用于所有路由，除非被某些路由的 `RouteSettings` 属性覆盖。  
*类型*：[RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Stage`资源的`[RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)`属性。

 `DefinitionBody`   <a name="sam-httpapi-definitionbody"></a>
描述您的 HTTP API 的 OpenAPI 定义。如果您未指定 a `DefinitionUri` 或 a`DefinitionBody`，则会根据您的模板配置`DefinitionBody`为您 AWS SAM 生成。  
*类型*：JSON  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGatewayV2::Api`资源的`[Body](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.html#cfn-apigatewayv2-api-body)`属性。如果提供了某些属性，则 AWS SAM 可以在将内容传递给`DefinitionBody`之前将其插入或修改 CloudFormation。属性包括相应`EventSource` HttpApi `AWS::Serverless::Function`资源的类型`Auth`和类型。

 `DefinitionUri`   <a name="sam-httpapi-definitionuri"></a>
定义 HTTP API 的 OpenAPI 定义的 Amazon Simple Storage Service (Amazon S3) URI、本地文件路径或位置对象。此属性引用的 Amazon S3 对象必须是有效的 OpenAPI 定义文件。如果您未指定`DefinitionUri`或`DefinitionBody`已指定，则会根据您的模板配置`DefinitionBody`为您 AWS SAM 生成。  
如果您提供本地文件路径，则模板必须经过包含 `sam deploy` 或 `sam package` 命令的工作流程，才能使定义正确转换。  
您引用的外部 OpenApi 定义文件不支持内部函数。`DefinitionUri`要将 OpenApi 定义导入到模板中，请使用带[有 Include 转换](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/create-reusable-transform-function-snippets-and-add-to-your-template-with-aws-include-transform.html)的`DefinitionBody`属性。  
*类型*：字符串 \$1 [HttpApiDefinition](sam-property-httpapi-httpapidefinition.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGatewayV2::Api`资源的`[BodyS3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.html#cfn-apigatewayv2-api-bodys3location)`属性。嵌套的 Amazon S3 属性的命名有所不同。

 `Description`   <a name="sam-httpapi-description"></a>
HTTP API 资源的描述。  
当您指定时`Description`， AWS SAM 将通过设置`description`字段来修改 HTTP API 资源的OpenApi 定义。以下情况将导致错误：  
+ 该`DefinitionBody`属性是使用 Open API 定义中设置的`description`字段指定的，这会导致 AWS SAM 无法解决的`description`字段冲突。
+ 该`DefinitionUri`属性已指定 — AWS SAM 不会修改从 Amazon S3 检索到的开放 API 定义。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `DisableExecuteApiEndpoint`   <a name="sam-httpapi-disableexecuteapiendpoint"></a>
指定客户端是否可以使用默认 `execute-api` 端点 `https://{api_id}.execute-api.{region}.amazonaws.com` 调用您的 HTTP API。默认情况下，客户端可以使用默认端点调用您的 API。如果要求客户端仅使用自定义域名调用 API，请禁用默认端点。  
要使用此属性，您必须指定 `DefinitionBody` 属性而不是 `DefinitionUri` 属性，或在 OpenAPI 定义中使用 `disableExecuteApiEndpoint` 定义 `x-amazon-apigateway-endpoint-configuration`。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGatewayV2::Api`资源的`[ DisableExecuteApiEndpoint](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.html#cfn-apigatewayv2-api-disableexecuteapiendpoint)`属性。它直接传递给 `[ x-amazon-apigateway-endpoint-configuration](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-endpoint-configuration.html)` 扩展的 `disableExecuteApiEndpoint` 属性，然后添加到 `AWS::ApiGatewayV2::Api` 资源的 ` [ Body](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.html#cfn-apigatewayv2-api-body)` 属性中。

 `Domain`   <a name="sam-httpapi-domain"></a>
为此 API Gateway HTTP API 配置自定义域。  
*类型*：[HttpApiDomainConfiguration](sam-property-httpapi-httpapidomainconfiguration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FailOnWarnings`   <a name="sam-httpapi-failonwarnings"></a>
指定在遇到警告时是回滚 (`true`) 还是不回滚 (`false`) HTTP API 创建。默认值为 `false`。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Api`资源的`[FailOnWarnings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.html#cfn-apigatewayv2-api-failonwarnings)`属性。

`Name`  <a name="sam-httpapi-name"></a>
HTTP API 资源的名称。  
当您指定时`Name`， AWS SAM 将通过设置该字段来修改 HTTP API 资源的 OpenAPI 定义。`title`以下情况将导致错误：  
+ 该`DefinitionBody`属性是使用 Open API 定义中设置的`title`字段指定的，这会导致 AWS SAM 无法解决的`title`字段冲突。
+ 该`DefinitionUri`属性已指定 — AWS SAM 不会修改从 Amazon S3 检索到的开放 API 定义。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`PropagateTags`  <a name="sam-httpapi-propagatetags"></a>
指明是否将 `Tags` 属性中的标签传递给 [AWS::Serverless::HttpApi](sam-specification-generated-resources-httpapi.md) 生成的资源。指定 `True` 以在生成的资源中传播标签。  
*类型*：布尔值  
*必需*：否  
*默认值*：`False`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `RouteSettings`   <a name="sam-httpapi-routesettings"></a>
此 HTTP API 的每个路由的路由设置。有关更多信息，请参阅 *API Gateway 开发者指南 APIs中的使用* [HTTP 路由](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-routes.html)。  
*类型*：[RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Stage`资源的`[RouteSettings](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-routesettings)`属性。

 `StageName`   <a name="sam-httpapi-stagename"></a>
API 阶段的名称。如果未指定名称，则 AWS SAM 使用 API Gateway 中的`$default`阶段。  
*类型*：字符串  
*必需*：否  
*默认值*：\$1default  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Stage`资源的`[StageName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-stagename)`属性。

 `StageVariables`   <a name="sam-httpapi-stagevariables"></a>
一个定义阶段变量的映射。变量名可以包含字母数字和下划线字符。这些值必须匹配 [A-Za-z0-9-.\$1\$1:/?\$1&=,]\$1。  
*类型*：[Json](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-stagevariables)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Stage`资源的`[StageVariables](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-stage.html#cfn-apigatewayv2-stage-stagevariables)`属性。

 `Tags`   <a name="sam-httpapi-tags"></a>
指定要添加到此 API Gateway 阶段的标签的映射（字符串到字符串）。密钥的长度可以在 1 到 128 个 Unicode 字符之间，并且不能包含前缀 `aws:`。您可以使用以下任一字符：Unicode 字母、数字、空格、`_`、`.`、`/`、`=`、`+` 和 `-` 的组合。值的长度可以在 1 到 256 个 Unicode 字符之间。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*其他说明*：该`Tags`属性 AWS SAM 需要修改您的 OpenAPI 定义，因此只有在指定了该`DefinitionBody`属性时才会添加标签，如果指定了该属性，则不会添加任何标签。`DefinitionUri` AWS SAM 自动添加`httpapi:createdBy:SAM`标签。标签还会添加到 `AWS::ApiGatewayV2::Stage` 资源和 `AWS::ApiGatewayV2::DomainName` 资源（如果已指定 `DomainName`）。

## 返回值
<a name="sam-resource-httpapi-return-values"></a>

### Ref
<a name="sam-resource-httpapi-return-values-ref"></a>

在将此资源的逻辑 ID 传递给内置 `Ref` 函数时，`Ref` 会返回底层 `AWS::ApiGatewayV2::Api` 资源的 API ID，例如 `a1bcdef2gh`。

有关使用 `Ref` 函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。

## 示例
<a name="sam-resource-httpapi--examples"></a>

### 简单 HttpApi
<a name="sam-resource-httpapi--examples--simple-httpapi"></a>

以下示例显示了设置由 Lambda 函数支持的 HTTP API 端点所需的最低要求。此示例使用 AWS SAM 创建的默认 HTTP API。

#### YAML
<a name="sam-resource-httpapi--examples--simple-httpapi--yaml"></a>

```
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS SAM template with a simple API definition
Resources:
  ApiFunction:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        ApiEvent:
          Type: HttpApi
      Handler: index.handler
      InlineCode: |
        def handler(event, context):
            return {'body': 'Hello World!', 'statusCode': 200}
      Runtime: python3.7
Transform: AWS::Serverless-2016-10-31
```

### HttpApi 使用身份验证
<a name="sam-resource-httpapi--examples--httpapi-with-auth"></a>

以下示例说明如何在 HTTP API 端点上设置授权。

#### YAML
<a name="sam-resource-httpapi--examples--httpapi-with-auth--yaml"></a>

```
Properties:
  FailOnWarnings: true
  Auth:
    DefaultAuthorizer: OAuth2
    Authorizers:
      OAuth2:
        AuthorizationScopes:
          - scope4
        JwtConfiguration:
          issuer: "https://www.example.com/v1/connect/oauth2"
          audience:
            - MyApi
        IdentitySource: "$request.querystring.param"
```

### HttpApi 使用 OpenAPI 定义
<a name="sam-resource-httpapi--examples--httpapi-with-openapi-definition"></a>

以下示例说明如何将 OpenAPI 定义添加到模板。

请注意，对于引用此 HTTP API HttpApi 的事件，请 AWS SAM 填写所有缺失的 Lambda 集成。 AWS SAM 还会添加 HttpApi 事件引用的任何缺失路径。

#### YAML
<a name="sam-resource-httpapi--examples--httpapi-with-openapi-definition--yaml"></a>

```
Properties:
  FailOnWarnings: true
  DefinitionBody:
    info:
      version: '1.0'
      title:
        Ref: AWS::StackName
    paths:
      "/":
        get:
          security:
          - OpenIdAuth:
            - scope1
            - scope2
          responses: {}
    openapi: 3.0.1
    securitySchemes:
      OpenIdAuth:
        type: openIdConnect
        x-amazon-apigateway-authorizer:
          identitySource: "$request.querystring.param"
          type: jwt
          jwtConfiguration:
            audience:
            - MyApi
            issuer: https://www.example.com/v1/connect/oidc
          openIdConnectUrl: https://www.example.com/v1/connect/oidc/.well-known/openid-configuration
```

### HttpApi 使用配置设置
<a name="sam-resource-httpapi--examples--httpapi-with-configuration-settings"></a>

以下示例说明如何将 HTTP API 和阶段配置添加到模板。

#### YAML
<a name="sam-resource-httpapi--examples--httpapi-with-configuration-settings--yaml"></a>

```
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Parameters:
  StageName:
    Type: String
    Default: Prod
    
Resources:
  HttpApiFunction:
    Type: AWS::Serverless::Function
    Properties:
      InlineCode: |
          def handler(event, context):
              import json
              return {
                  "statusCode": 200,
                  "body": json.dumps(event),
              }
      Handler: index.handler
      Runtime: python3.7
      Events:
        ExplicitApi: # warning: creates a public endpoint
          Type: HttpApi
          Properties:
            ApiId: !Ref HttpApi
            Method: GET
            Path: /path
            TimeoutInMillis: 15000
            PayloadFormatVersion: "2.0"
            RouteSettings:
              ThrottlingBurstLimit: 600

  HttpApi:
    Type: AWS::Serverless::HttpApi
    Properties:
      StageName: !Ref StageName
      Tags:
        Tag: Value
      AccessLogSettings:
        DestinationArn: !GetAtt AccessLogs.Arn
        Format: $context.requestId
      DefaultRouteSettings:
        ThrottlingBurstLimit: 200
      RouteSettings:
        "GET /path":
          ThrottlingBurstLimit: 500 # overridden in HttpApi Event
      StageVariables:
        StageVar: Value
      FailOnWarnings: true

  AccessLogs:
    Type: AWS::Logs::LogGroup

Outputs:
  HttpApiUrl:
    Description: URL of your API endpoint
    Value:
      Fn::Sub: 'https://${HttpApi}.execute-api.${AWS::Region}.${AWS::URLSuffix}/${StageName}/'
  HttpApiId:
    Description: Api id of HttpApi
    Value:
      Ref: HttpApi
```

# HttpApiAuth
<a name="sam-property-httpapi-httpapiauth"></a>

配置授权，以控制对 Amazon API Gateway HTTP API 的访问。

有关配置 HTTP 访问权限的更多信息 APIs，请参阅《API Gateway *开发者指南》[中的 API Gateway 中控制和管理对 HTTP](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-access-control.html) API* 的访问权限。

## 语法
<a name="sam-property-httpapi-httpapiauth-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-httpapiauth-syntax.yaml"></a>

```
  [Authorizers](#sam-httpapi-httpapiauth-authorizers): OAuth2Authorizer | LambdaAuthorizer
  [DefaultAuthorizer](#sam-httpapi-httpapiauth-defaultauthorizer): String
  [EnableIamAuthorizer](#sam-httpapi-httpapiauth-enableiamauthorizer): Boolean
```

## Properties
<a name="sam-property-httpapi-httpapiauth-properties"></a>

 `Authorizers`   <a name="sam-httpapi-httpapiauth-authorizers"></a>
用于控制对 API Gateway API 的访问的授权方。  
*类型*：[OAuth2授权者 \$1 [LambdaAuthorizer](sam-property-httpapi-lambdaauthorizer.md)](sam-property-httpapi-oauth2authorizer.md)  
*必需*：否  
*默认值*：无  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*其他说明*： AWS SAM 将授权者添加到 OpenAPI 定义中。

 `DefaultAuthorizer`   <a name="sam-httpapi-httpapiauth-defaultauthorizer"></a>
指定默认授权方，以用于授权对 API Gateway API 的 API 调用。如果 `EnableIamAuthorizer` 设置为 `true`，您可以指定 `AWS_IAM` 作为默认授权方。否则，请指定您在 `Authorizers` 中定义的授权方。  
*类型*：字符串  
*必需*：否  
*默认值*：无  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `EnableIamAuthorizer`   <a name="sam-httpapi-httpapiauth-enableiamauthorizer"></a>
指定是否要对 API 路由使用 IAM 授权。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-httpapi-httpapiauth--examples"></a>

### OAuth 2.0 授权者
<a name="sam-property-httpapi-httpapiauth--examples--oauth-2.0-authorizer"></a>

OAuth 2.0 授权方示例

#### YAML
<a name="sam-property-httpapi-httpapiauth--examples--oauth-2.0-authorizer--yaml"></a>

```
Auth:
  Authorizers:
    OAuth2Authorizer:
      AuthorizationScopes:
        - scope1
        - scope2
      JwtConfiguration:
        issuer: "https://www.example.com/v1/connect/oauth2"
        audience:
          - MyApi
      IdentitySource: "$request.querystring.param"
  DefaultAuthorizer: OAuth2Authorizer
```

### IAM 授权方
<a name="sam-property-httpapi-httpapiauth--examples--iam-authorizer"></a>

IAM 授权方示例

#### YAML
<a name="sam-property-httpapi-httpapiauth--examples--iam-authorizer--yaml"></a>

```
Auth:
  EnableIamAuthorizer: true
  DefaultAuthorizer: AWS_IAM
```

# LambdaAuthorizer
<a name="sam-property-httpapi-lambdaauthorizer"></a>

配置 Lambda 授权机构，使用函数控制对您的 Amazon API Gateway HTTP API 的访问。 AWS Lambda 

有关更多信息和示例，请参阅《*API Gateway 开发者指南》 APIs*[中的 “使用 HTTP 的 AWS Lambda 授权方](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html)”。

## 语法
<a name="sam-property-httpapi-lambdaauthorizer-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-lambdaauthorizer-syntax.yaml"></a>

```
  [AuthorizerPayloadFormatVersion](#sam-httpapi-lambdaauthorizer-authorizerpayloadformatversion): String
  EnableFunctionDefaultPermissions: Boolean
  [EnableSimpleResponses](#sam-httpapi-lambdaauthorizer-enablesimpleresponses): Boolean
  [FunctionArn](#sam-httpapi-lambdaauthorizer-functionarn): String
  [FunctionInvokeRole](#sam-httpapi-lambdaauthorizer-functioninvokerole): String
  [Identity](#sam-httpapi-lambdaauthorizer-identity): LambdaAuthorizationIdentity
```

## Properties
<a name="sam-property-httpapi-lambdaauthorizer-properties"></a>

 `AuthorizerPayloadFormatVersion`   <a name="sam-httpapi-lambdaauthorizer-authorizerpayloadformatversion"></a>
指定发送到 HTTP API Lambda 授权方的负载的格式。对于 HTTP API Lambda 授权方必须指定。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `authorizerPayloadFormatVersion` 部分。  
*有效值*：`1.0` 或 `2.0`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `EnableFunctionDefaultPermissions`   <a name="sam-httpapi-lambdaauthorizer-enablefunctiondefaultpermissions"></a>
默认情况下，未授予 HTTP API 资源调用 Lambda 授权方的权限。将此属性指定为 `true` 以自动在您的 HTTP API 资源和 Lambda 授权方之间创建权限。  
*类型*：布尔值  
*必需*：否  
*默认值*：`false`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `EnableSimpleResponses`   <a name="sam-httpapi-lambdaauthorizer-enablesimpleresponses"></a>
指定 Lambda 授权方是否以简单格式返回响应。默认情况下，Lambda 授权机构必须返回 AWS Identity and Access Management (IAM) 策略。如果启用，Lambda 授权方可以返回布尔值，而不是 IAM 策略。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `enableSimpleResponses` 部分。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionArn`   <a name="sam-httpapi-lambdaauthorizer-functionarn"></a>
为 API 提供授权的 Lambda 函数的 Amazon 资源名称（ARN）。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `authorizerUri` 部分。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `FunctionInvokeRole`   <a name="sam-httpapi-lambdaauthorizer-functioninvokerole"></a>
具有 API Gateway 调用授权方函数所需凭证的 IAM 角色的 ARN。如果函数的基于资源的策略未授予 API Gateway `lambda:InvokeFunction` 权限，请指定此参数。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `authorizerCredentials` 部分。  
有关更多信息，请参阅*《API Gateway 开发人员指南》*中的[创建 Lambda 授权方](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html#http-api-lambda-authorizer.example-create)。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Identity`   <a name="sam-httpapi-lambdaauthorizer-identity"></a>
在授权方传入请求中指定 `IdentitySource`。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `identitySource` 部分。  
*类型*：[LambdaAuthorizationIdentity](sam-property-httpapi-lambdaauthorizationidentity.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-httpapi-lambdaauthorizer--examples"></a>

### LambdaAuthorizer
<a name="sam-property-httpapi-lambdaauthorizer--examples--lambdaauthorizer"></a>

LambdaAuthorizer 示例

#### YAML
<a name="sam-property-httpapi-lambdaauthorizer--examples--lambdaauthorizer--yaml"></a>

```
Auth:
  Authorizers:
    MyLambdaAuthorizer:
      AuthorizerPayloadFormatVersion: 2.0
      FunctionArn:
        Fn::GetAtt:
          - MyAuthFunction
          - Arn
      FunctionInvokeRole:
        Fn::GetAtt:
          - LambdaAuthInvokeRole
          - Arn
      Identity:
        Headers:
          - Authorization
```

# LambdaAuthorizationIdentity
<a name="sam-property-httpapi-lambdaauthorizationidentity"></a>

Use 属性可用于在 Lambda 授权方的传入请求 IdentitySource 中指定。有关身份源的更多信息，请参阅*《API Gateway 开发人员指南》*中的[身份源](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html#http-api-lambda-authorizer.identity-sources)。

## 语法
<a name="sam-property-httpapi-lambdaauthorizationidentity-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-lambdaauthorizationidentity-syntax.yaml"></a>

```
  [Context](#sam-httpapi-lambdaauthorizationidentity-context): List
  [Headers](#sam-httpapi-lambdaauthorizationidentity-headers): List
  [QueryStrings](#sam-httpapi-lambdaauthorizationidentity-querystrings): List
  [ReauthorizeEvery](#sam-httpapi-lambdaauthorizationidentity-reauthorizeevery): Integer
  [StageVariables](#sam-httpapi-lambdaauthorizationidentity-stagevariables): List
```

## Properties
<a name="sam-property-httpapi-lambdaauthorizationidentity-properties"></a>

 `Context`   <a name="sam-httpapi-lambdaauthorizationidentity-context"></a>
将给定的上下文字符串转换为映射表达式列表，格式为 `$context.contextString`。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Headers`   <a name="sam-httpapi-lambdaauthorizationidentity-headers"></a>
将标头转换为映射表达式列表，格式为 `$request.header.name`。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `QueryStrings`   <a name="sam-httpapi-lambdaauthorizationidentity-querystrings"></a>
将给定的查询字符串转换为映射表达式列表，格式为 `$request.querystring.queryString`。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ReauthorizeEvery`   <a name="sam-httpapi-lambdaauthorizationidentity-reauthorizeevery"></a>
 time-to-live(TTL) 周期，以秒为单位，用于指定 API Gateway 缓存授权方结果的时长。如果您指定一个大于 0 的值，API Gateway 将缓存授权方响应。最大值为 3600 秒（1 小时）。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `StageVariables`   <a name="sam-httpapi-lambdaauthorizationidentity-stagevariables"></a>
将给定的阶段变量转换为映射表达式列表，格式为 `$stageVariables.stageVariable`。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-httpapi-lambdaauthorizationidentity--examples"></a>

### LambdaRequestIdentity
<a name="sam-property-httpapi-lambdaauthorizationidentity--examples--lambdarequestidentity"></a>

Lambda 请求身份示例

#### YAML
<a name="sam-property-httpapi-lambdaauthorizationidentity--examples--lambdarequestidentity--yaml"></a>

```
Identity:
  QueryStrings:
    - auth
  Headers:
    - Authorization
  StageVariables:
    - VARIABLE
  Context:
    - authcontext
  ReauthorizeEvery: 100
```

# OAuth2Authorizer
<a name="sam-property-httpapi-oauth2authorizer"></a>

 OAuth 2.0 授权方（也称为 JSON 网络令牌 (JWT) 授权方）的定义。

有关更多信息，请参阅《*API Gateway 开发*者指南》中的 “[ APIs 使用 JWT 授权者控制 HTTP 访问权限](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html)”。

## 语法
<a name="sam-property-httpapi-oauth2authorizer-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-oauth2authorizer-syntax.yaml"></a>

```
  [AuthorizationScopes](#sam-httpapi-oauth2authorizer-authorizationscopes): List
  [IdentitySource](#sam-httpapi-oauth2authorizer-identitysource): String
  [JwtConfiguration](#sam-httpapi-oauth2authorizer-jwtconfiguration): Map
```

## Properties
<a name="sam-property-httpapi-oauth2authorizer-properties"></a>

 `AuthorizationScopes`   <a name="sam-httpapi-oauth2authorizer-authorizationscopes"></a>
此授权方的授权范围列表。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IdentitySource`   <a name="sam-httpapi-oauth2authorizer-identitysource"></a>
此授权方的身份源表达式。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `JwtConfiguration`   <a name="sam-httpapi-oauth2authorizer-jwtconfiguration"></a>
此授权方的 JWT 配置。  
这会传递到 OpenAPI 定义的 `securitySchemes` 部分中 `x-amazon-apigateway-authorizer` 的 `jwtConfiguration` 部分。  
属`issuer`性和`audience`不区分大小写，可以使用 OpenAPI 中的小写字母，也可以使用大写字母`Issuer`和。`Audience` [AWS::ApiGatewayV2::Authorizer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-authorizer-jwtconfiguration.html)
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-httpapi-oauth2authorizer--examples"></a>

### OAuth 2.0 授权者
<a name="sam-property-httpapi-oauth2authorizer--examples--oauth-2.0-authorizer"></a>

OAuth 2.0 授权方示例

#### YAML
<a name="sam-property-httpapi-oauth2authorizer--examples--oauth-2.0-authorizer--yaml"></a>

```
Auth:
  Authorizers:
    OAuth2Authorizer:
      AuthorizationScopes:
        - scope1
      JwtConfiguration:
        issuer: "https://www.example.com/v1/connect/oauth2"
        audience:
          - MyApi
      IdentitySource: "$request.querystring.param"
  DefaultAuthorizer: OAuth2Authorizer
```

# HttpApiCorsConfiguration
<a name="sam-property-httpapi-httpapicorsconfiguration"></a>

管理您的 HTTP 的跨源资源共享 (CORS)。 APIs使用字符串指定允许使用的域，或使用其他 Cors 配置指定词典。注意：Cors 要求 SAM 修改你的 OpenAPI 定义，因此它仅适用于属性中`DefinitionBody`定义的 OpenApi 内联定义。

有关 CORS 的更多信息，请参阅*《API Gateway 开发人员指南》*中的[为 HTTP API 配置 CORS](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html)。

注意：如果 HttpApiCorsConfiguration 在 OpenAPI 和属性级别同时设置，则会将它们 AWS SAM 合并，且属性优先。

## 语法
<a name="sam-property-httpapi-httpapicorsconfiguration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-httpapicorsconfiguration-syntax.yaml"></a>

```
  [AllowCredentials](#sam-httpapi-httpapicorsconfiguration-allowcredentials): Boolean
  [AllowHeaders](#sam-httpapi-httpapicorsconfiguration-allowheaders): List
  [AllowMethods](#sam-httpapi-httpapicorsconfiguration-allowmethods): List
  [AllowOrigins](#sam-httpapi-httpapicorsconfiguration-alloworigins): List
  [ExposeHeaders](#sam-httpapi-httpapicorsconfiguration-exposeheaders): List
  [MaxAge](#sam-httpapi-httpapicorsconfiguration-maxage): Integer
```

## Properties
<a name="sam-property-httpapi-httpapicorsconfiguration-properties"></a>

 `AllowCredentials`   <a name="sam-httpapi-httpapicorsconfiguration-allowcredentials"></a>
指定是否在 CORS 请求中包含凭证。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowHeaders`   <a name="sam-httpapi-httpapicorsconfiguration-allowheaders"></a>
表示允许的标头集合。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowMethods`   <a name="sam-httpapi-httpapicorsconfiguration-allowmethods"></a>
表示允许的 HTTP 方法集合。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AllowOrigins`   <a name="sam-httpapi-httpapicorsconfiguration-alloworigins"></a>
表示允许的源集合。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ExposeHeaders`   <a name="sam-httpapi-httpapicorsconfiguration-exposeheaders"></a>
表示公开的标头集合。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `MaxAge`   <a name="sam-httpapi-httpapicorsconfiguration-maxage"></a>
浏览器应缓存预检请求结果的秒数。  
*类型*：整数  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-httpapi-httpapicorsconfiguration--examples"></a>

### HttpApiCorsConfiguration
<a name="sam-property-httpapi-httpapicorsconfiguration--examples--httpapicorsconfiguration"></a>

HTTP API Cors 配置示例。

#### YAML
<a name="sam-property-httpapi-httpapicorsconfiguration--examples--httpapicorsconfiguration--yaml"></a>

```
CorsConfiguration:
  AllowOrigins:
    - "https://example.com"
  AllowHeaders:
    - x-apigateway-header
  AllowMethods:
    - GET
  MaxAge: 600
  AllowCredentials: true
```

# HttpApiDefinition
<a name="sam-property-httpapi-httpapidefinition"></a>

定义 API 的 OpenAPI 文档。

## 语法
<a name="sam-property-httpapi-httpapidefinition-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-httpapidefinition-syntax.yaml"></a>

```
  [Bucket](#sam-httpapi-httpapidefinition-bucket): String
  [Key](#sam-httpapi-httpapidefinition-key): String
  [Version](#sam-httpapi-httpapidefinition-version): String
```

## Properties
<a name="sam-property-httpapi-httpapidefinition-properties"></a>

 `Bucket`   <a name="sam-httpapi-httpapidefinition-bucket"></a>
存储了 OpenAPI 文件的 Amazon S3 桶的名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Api``BodyS3Location`数据类型的`[Bucket](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-api-bodys3location.html#cfn-apigatewayv2-api-bodys3location-bucket)`属性。

 `Key`   <a name="sam-httpapi-httpapidefinition-key"></a>
OpenAPI 文件的 Amazon S3 密钥。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Api``BodyS3Location`数据类型的`[Key](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-api-bodys3location.html#cfn-apigatewayv2-api-bodys3location-key)`属性。

 `Version`   <a name="sam-httpapi-httpapidefinition-version"></a>
对于受版本控制的对象，是 OpenAPI 文件的版本。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::Api``BodyS3Location`数据类型的`[Version](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-api-bodys3location.html#cfn-apigatewayv2-api-bodys3location-version)`属性。

## 示例
<a name="sam-property-httpapi-httpapidefinition--examples"></a>

### 定义 Uri 示例
<a name="sam-property-httpapi-httpapidefinition--examples--definition-uri-example"></a>

API 定义示例

#### YAML
<a name="sam-property-httpapi-httpapidefinition--examples--definition-uri-example--yaml"></a>

```
DefinitionUri:
  Bucket: sam-s3-demo-bucket-name
  Key: mykey-name
  Version: 121212
```

# HttpApiDomainConfiguration
<a name="sam-property-httpapi-httpapidomainconfiguration"></a>

为 API 配置自定义域。

## 语法
<a name="sam-property-httpapi-httpapidomainconfiguration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-httpapidomainconfiguration-syntax.yaml"></a>

```
  [BasePath](#sam-httpapi-httpapidomainconfiguration-basepath): List
  [CertificateArn](#sam-httpapi-httpapidomainconfiguration-certificatearn): String
  [DomainName](#sam-httpapi-httpapidomainconfiguration-domainname): String
  [EndpointConfiguration](#sam-httpapi-httpapidomainconfiguration-endpointconfiguration): String
  [MutualTlsAuthentication](#sam-httpapi-httpapidomainconfiguration-mutualtlsauthentication): [MutualTlsAuthentication](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-domainname.html#cfn-apigatewayv2-domainname-mutualtlsauthentication)
  [OwnershipVerificationCertificateArn](#sam-httpapi-httpapidomainconfiguration-ownershipverificationcertificatearn): String
  [Route53](#sam-httpapi-httpapidomainconfiguration-route53): Route53Configuration
  [SecurityPolicy](#sam-httpapi-httpapidomainconfiguration-securitypolicy): String
```

## Properties
<a name="sam-property-httpapi-httpapidomainconfiguration-properties"></a>

 `BasePath`   <a name="sam-httpapi-httpapidomainconfiguration-basepath"></a>
要使用 Amazon API Gateway 域名配置的基本路径列表。  
*类型*：列表  
*必需*：否  
*默认值*：/  
*CloudFormation 兼容性*：此属性类似于`AWS::ApiGatewayV2::ApiMapping`资源的`[ApiMappingKey](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-apimapping.html#cfn-apigatewayv2-apimapping-apimappingkey)`属性。 AWS SAM 创建多个`AWS::ApiGatewayV2::ApiMapping`资源，每个资源在此属性中指定的值一个。

 `CertificateArn`   <a name="sam-httpapi-httpapidomainconfiguration-certificatearn"></a>
该域名终端节点的 AWS 托管证书的 Amazon 资源名称 (ARN)。 AWS Certificate Manager 是唯一支持的来源。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway2::DomainName DomainNameConfiguration`资源的`[CertificateArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-domainname-domainnameconfiguration.html#cfn-apigatewayv2-domainname-domainnameconfiguration-certificatearn)`属性。

 `DomainName`   <a name="sam-httpapi-httpapidomainconfiguration-domainname"></a>
API Gateway API 的自定义域名。不支持大写字母。  
AWS SAM 设置此属性时会生成`AWS::ApiGatewayV2::DomainName`资源。有关此场景的更多信息，请参阅[DomainName 属性已指定](sam-specification-generated-resources-httpapi.md#sam-specification-generated-resources-httpapi-domain-name)。有关生成的 CloudFormation 资源的信息，请参阅[生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGateway2::DomainName`资源的`[DomainName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-domainname.html#cfn-apigatewayv2-domainname-domainname)`属性。

 `EndpointConfiguration`   <a name="sam-httpapi-httpapidomainconfiguration-endpointconfiguration"></a>
定义要映射到自定义域的 API Gateway 端点的类型。此属性的值决定了该`CertificateArn`属性的映射方式 CloudFormation。  
HTTP 的唯一有效值 APIs 是`REGIONAL`。  
*类型*：字符串  
*必需*：否  
*默认值*：`REGIONAL`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `MutualTlsAuthentication`   <a name="sam-httpapi-httpapidomainconfiguration-mutualtlsauthentication"></a>
自定义域名的相互传输层安全性协议（TLS）身份验证配置。  
*类型*：[MutualTlsAuthentication](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-domainname.html#cfn-apigatewayv2-domainname-mutualtlsauthentication)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::DomainName`资源的`[MutualTlsAuthentication](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-domainname.html#cfn-apigatewayv2-domainname-mutualtlsauthentication)`属性。

 `OwnershipVerificationCertificateArn`   <a name="sam-httpapi-httpapidomainconfiguration-ownershipverificationcertificatearn"></a>
ACM 颁发的用于验证自定义域所有权的公有证书的 ARN。只有在配置双向 TLS 并且为 `CertificateArn` 指定了 ACM 导入的或私有 CA 证书 ARN 时才需要。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::DomainName``DomainNameConfiguration`数据类型的`[OwnershipVerificationCertificateArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-domainname-domainnameconfiguration.html#cfn-apigatewayv2-domainname-domainnameconfiguration-ownershipverificationcertificatearn)`属性。

 `Route53`   <a name="sam-httpapi-httpapidomainconfiguration-route53"></a>
定义 Amazon Route 53 配置。  
*类型*：[Route53Configuration](sam-property-httpapi-route53configuration.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SecurityPolicy`   <a name="sam-httpapi-httpapidomainconfiguration-securitypolicy"></a>
此域名的安全策略的 TLS 版本。  
HTTP 的唯一有效值 APIs 是`TLS_1_2`。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::ApiGatewayV2::DomainName``DomainNameConfiguration`数据类型的`[SecurityPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigatewayv2-domainname-domainnameconfiguration.html#cfn-apigatewayv2-domainname-domainnameconfiguration-securitypolicy)`属性。

## 示例
<a name="sam-property-httpapi-httpapidomainconfiguration--examples"></a>

### DomainName
<a name="sam-property-httpapi-httpapidomainconfiguration--examples--domainname"></a>

DomainName 示例

#### YAML
<a name="sam-property-httpapi-httpapidomainconfiguration--examples--domainname--yaml"></a>

```
Domain:
  DomainName: www.example.com
  CertificateArn: arn-example
  EndpointConfiguration: REGIONAL
  Route53:
    HostedZoneId: Z1PA6795UKMFR9
  BasePath:
    - foo
    - bar
```

# Route53Configuration
<a name="sam-property-httpapi-route53configuration"></a>

为 API 配置 Route53 记录集。

## 语法
<a name="sam-property-httpapi-route53configuration-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-httpapi-route53configuration-syntax.yaml"></a>

```
  [DistributionDomainName](#sam-httpapi-route53configuration-distributiondomainname): String
  [EvaluateTargetHealth](#sam-httpapi-route53configuration-evaluatetargethealth): Boolean
  [HostedZoneId](#sam-httpapi-route53configuration-hostedzoneid): String
  [HostedZoneName](#sam-httpapi-route53configuration-hostedzonename): String
  [IpV6](#sam-httpapi-route53configuration-ipv6): Boolean
  Region: String
  SetIdentifier: String
```

## Properties
<a name="sam-property-httpapi-route53configuration-properties"></a>

 `DistributionDomainName`   <a name="sam-httpapi-route53configuration-distributiondomainname"></a>
配置 API 自定义域名的自定义分配。  
*类型*：字符串  
*必需*：否  
*默认*：使用 API Gateway 分配。  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup AliasTarget`资源的`[DNSName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget-1.html#cfn-route53-aliastarget-dnshostname)`属性。  
*其他说明*：[CloudFront分配](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudfront-distribution.html)的域名。

 `EvaluateTargetHealth`   <a name="sam-httpapi-route53configuration-evaluatetargethealth"></a>
如果 EvaluateTargetHealth 为 true，则别名记录将继承引用 AWS 资源的运行状况，例如 Elastic Load Balancing 负载均衡器或托管区域中的其他记录。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup AliasTarget`资源的`[EvaluateTargetHealth](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html#cfn-route53-aliastarget-evaluatetargethealth)`属性。  
*其他说明*：当别名目标为 CloudFront 分布时，您不能 EvaluateTargetHealth 将其设置为 true。

 `HostedZoneId`   <a name="sam-httpapi-route53configuration-hostedzoneid"></a>
要在其中创建记录的托管区的 ID。  
指定 `HostedZoneName` 或 `HostedZoneId`，但不能同时指定两者。如果您拥有多个使用相同域名的托管区域，则必须使用 `HostedZoneId` 指定托管区。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup RecordSet`资源的`[HostedZoneId](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-1.html#cfn-route53-recordset-hostedzoneid)`属性。

 `HostedZoneName`   <a name="sam-httpapi-route53configuration-hostedzonename"></a>
要在其中创建记录的托管区的名称。您必须包含结尾圆点（例如 `www.example.com.`）作为 `HostedZoneName` 的一部分。  
指定 `HostedZoneName` 或 `HostedZoneId`，但不能同时指定两者。如果您拥有多个使用相同域名的托管区域，则必须使用 `HostedZoneId` 指定托管区。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup RecordSet`资源的`[HostedZoneName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-1.html#cfn-route53-recordset-hostedzonename)`属性。

 `IpV6`   <a name="sam-httpapi-route53configuration-ipv6"></a>
设置此属性后，将 AWS SAM 创建一个`AWS::Route53::RecordSet`资源并将提供的资源的 [Type](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset.html#cfn-route53-recordset-type) 设置`AAAA`为 HostedZone。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`Region`  <a name="sam-httpapi-route53configuration-region"></a>
*仅限基于延迟的资源记录集*：您创建此资源记录集所引用的资源的亚马逊 EC2 区域。资源通常是 AWS 资源，例如 EC2 实例或 ELB 负载均衡器，并由 IP 地址或 DNS 域名引用，具体取决于记录类型。  
当 Amazon Route 53 收到针对您已为其创建延迟资源记录集的域名和类型的 DNS 查询时，Route 53 会选择最终用户与关联亚马逊 EC2 地区之间延迟最低的延迟资源记录集。然后，Route 53 会返回与所选资源记录集相关的值。  
注意以下几点：  
+ 您只能为每个延迟资源记录集指定一个 `ResourceRecord`。
+ 您只能为每个 Amazon EC2 地区创建一个延迟资源记录集。
+ 您无需为所有 Amazon EC2 区域创建延迟资源记录集。Route 53 会从您已创建延迟资源记录集的区域中选择延迟性能最佳的区域。
+ 您不能创建 `Name` 和 `Type` 元素的值与延迟资源记录集相同的非延迟资源记录集。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup``RecordSet`数据类型的`[ Region](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-1.html#cfn-route53-recordset-region)`属性。

`SetIdentifier`  <a name="sam-httpapi-route53configuration-setidentifier"></a>
*具有简单策略以外的路由策略的资源记录集：*用于区分具有相同名称和类型组合的多个资源记录集的标识符，如名为 acme.example.com 且类型为 A 的多个加权资源记录集。在一组具有相同名称和类型的资源记录集中，每个资源记录集的 `SetIdentifier` 值必须唯一。  
有关路由策略的信息，请参阅*《Amazon Route 53 开发人员指南》*中的[选择路由策略](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-policy.html)。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Route53::RecordSetGroup``RecordSet`数据类型的`[ SetIdentifier](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-recordset-1.html#cfn-route53-recordset-setidentifier)`属性。

## 示例
<a name="sam-property-httpapi-route53configuration--examples"></a>

### Route 53 配置示例
<a name="sam-property-httpapi-route53configuration--examples--route-53-configuration-example"></a>

此示例演示了如何配置 Route 53。

#### YAML
<a name="sam-property-httpapi-route53configuration--examples--route-53-configuration-example--yaml"></a>

```
Domain:
  DomainName: www.example.com
  CertificateArn: arn-example
  EndpointConfiguration: EDGE
  Route53:
    HostedZoneId: Z1PA6795UKMFR9
    EvaluateTargetHealth: true
    DistributionDomainName: xyz
```

# AWS::Serverless::LayerVersion
<a name="sam-resource-layerversion"></a>

创建包含 Lambda 函数 LayerVersion 所需的库或运行时代码的 Lambda。

该[AWS::Serverless::LayerVersion](#sam-resource-layerversion)资源还支持 res `Metadata` ource 属性，因此您可以指示 AWS SAM 构建应用程序中包含的层。有关构建层的更多信息，请参阅 [在中构建 Lambda 图层 AWS SAM](building-layers.md)。

**重要说明**：自从中发布[UpdateReplacePolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatereplacepolicy.html)资源属性以来 CloudFormation，[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html)（推荐）提供的好处与相同[AWS::Serverless::LayerVersion](#sam-resource-layerversion)。

转换无服务器 LayerVersion 时，SAM 还会转换资源的逻辑 ID，这样资源更新 CloudFormation 时就不会自动删除旧 LayerVersions 的 ID。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-layerversion-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-resource-layerversion-syntax.yaml"></a>

```
Type: AWS::Serverless::LayerVersion
Properties:
  [CompatibleArchitectures](#sam-layerversion-compatiblearchitectures): List
  [CompatibleRuntimes](#sam-layerversion-compatibleruntimes): List
  [ContentUri](#sam-layerversion-contenturi): String | LayerContent
  [Description](#sam-layerversion-description): String
  [LayerName](#sam-layerversion-layername): String
  [LicenseInfo](#sam-layerversion-licenseinfo): String
  [PublishLambdaVersion](#sam-layerversion-PublishLambdaVersion): Boolean
  [RetentionPolicy](#sam-layerversion-retentionpolicy): String
```

## Properties
<a name="sam-resource-layerversion-properties"></a>

 `CompatibleArchitectures`   <a name="sam-layerversion-compatiblearchitectures"></a>
为层版本指定支持的指令集架构。  
有关此属性更多信息，请参阅*《AWS Lambda 开发人员指南》*中的 [Lambda 指令集架构](https://docs.aws.amazon.com/lambda/latest/dg/foundation-arch.html)。  
*有效值*：`x86_64`、`arm64`  
*类型*：列表  
*必需*：否  
*默认值*：`x86_64`  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::LayerVersion`资源的`[CompatibleArchitectures](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html#cfn-lambda-layerversion-compatiblearchitectures)`属性。

 `CompatibleRuntimes`   <a name="sam-layerversion-compatibleruntimes"></a>
与此兼容的运行时列表。 LayerVersion  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::LayerVersion`资源的`[CompatibleRuntimes](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html#cfn-lambda-layerversion-compatibleruntimes)`属性。

 `ContentUri`   <a name="sam-layerversion-contenturi"></a>
Amazon S3 Uri、本地文件夹的路径或层代码的 LayerContent 对象。  
如果提供了 Amazon S3 URI 或 LayerContent 对象，则引用的亚马逊 S3 对象必须是包含 [Lambda](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html) 层内容的有效 ZIP 档案。  
如果提供了本地文件夹的路径，则为使内容正确转换，模板必须经过包括 [sam build](sam-cli-command-reference-sam-build.md) 以及后续的 [sam deploy](sam-cli-command-reference-sam-deploy.md) 或 [sam package](sam-cli-command-reference-sam-package.md) 的工作流程。默认情况下，相对路径是根据 AWS SAM 模板的位置进行解析的。  
*类型*：字符串 \$1 [LayerContent](sam-property-layerversion-layercontent.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::LayerVersion`资源的`[Content](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html#cfn-lambda-layerversion-content)`属性。嵌套的 Amazon S3 属性的命名有所不同。

 `Description`   <a name="sam-layerversion-description"></a>
该层的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::LayerVersion`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html#cfn-lambda-layerversion-description)`属性。

 `LayerName`   <a name="sam-layerversion-layername"></a>
层的名称或 Amazon 资源名称（ARN）。  
*类型*：字符串  
*必需*：否  
*默认*：资源逻辑 ID  
*CloudFormation 兼容性*：此属性类似于`AWS::Lambda::LayerVersion`资源的`[LayerName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html#cfn-lambda-layerversion-layername)`属性。如果您没有指定名称，则将使用资源的逻辑 ID 作为名称。

 `LicenseInfo`   <a name="sam-layerversion-licenseinfo"></a>
有关此许可证的信息 LayerVersion。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::LayerVersion`资源的`[LicenseInfo](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html#cfn-lambda-layerversion-licenseinfo)`属性。

 `PublishLambdaVersion`   <a name="sam-layerversion-PublishLambdaVersion"></a>
一个选择性属性，当引用的 `LayerVersion` 资源发生变更时，会自动创建新的 Lambda 版本。当在关联的 Lambda 函数中启用 `AutoPublishAlias` 和 `AutoPublishAliasAllProperties` 时，每次对 `LayerVersion` 资源的修改都会触发新的 Lambda 版本创建。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `RetentionPolicy`   <a name="sam-layerversion-retentionpolicy"></a>
此属性指定当您删除资源时，是保留还是删除 `LayerVersion` 的旧版本。如果您在更新或替换资源时需要保留 `LayerVersion` 的旧版本，则必须启用 `UpdateReplacePolicy` 属性。有关执行此操作的信息，请参阅《AWS CloudFormation 用户指南》**中的 [`UpdateReplacePolicy` 属性](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatereplacepolicy.html)。  
*有效值*：`Retain` 或 `Delete`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。  
*其他说明*：指定后`Retain`， AWS SAM 会`DeletionPolicy: Retain`向转换后的`AWS::Lambda::LayerVersion`资源添加一个[支持的资源属性 AWS SAM](sam-specification-resource-attributes.md)。

## 返回值
<a name="sam-resource-layerversion-return-values"></a>

### Ref
<a name="sam-resource-layerversion-return-values-ref"></a>

当向`Ref`内部函数提供此资源的逻辑 ID 时，它将返回底层 Lambda 的资源 ARN。 LayerVersion

有关使用 `Ref` 函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。

## 示例
<a name="sam-resource-layerversion--examples"></a>

### LayerVersionExample
<a name="sam-resource-layerversion--examples--layerversionexample"></a>

的示例 LayerVersion

#### YAML
<a name="sam-resource-layerversion--examples--layerversionexample--yaml"></a>

```
Properties:
  LayerName: MyLayer
  Description: Layer description
  ContentUri: 's3://sam-s3-demo-bucket/my-layer.zip'
  CompatibleRuntimes:
    - nodejs10.x
    - nodejs12.x
  LicenseInfo: 'Available under the MIT-0 license.'
  RetentionPolicy: Retain
```

# LayerContent
<a name="sam-property-layerversion-layercontent"></a>

一个 ZIP 存档，其中包含 [Lambda 层](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html)的内容。

## 语法
<a name="sam-property-layerversion-layercontent-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-layerversion-layercontent-syntax.yaml"></a>

```
  [Bucket](#sam-layerversion-layercontent-bucket): String
  [Key](#sam-layerversion-layercontent-key): String
  [Version](#sam-layerversion-layercontent-version): String
```

## Properties
<a name="sam-property-layerversion-layercontent-properties"></a>

 `Bucket`   <a name="sam-layerversion-layercontent-bucket"></a>
层存档的 Amazon S3 桶。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::LayerVersion``Content`数据类型的`[S3Bucket](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-layerversion-content.html#cfn-lambda-layerversion-content-s3bucket)`属性。

 `Key`   <a name="sam-layerversion-layercontent-key"></a>
层存档的 Amazon S3 密钥。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::LayerVersion``Content`数据类型的`[S3Key](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-layerversion-content.html#cfn-lambda-layerversion-content-s3key)`属性。

 `Version`   <a name="sam-layerversion-layercontent-version"></a>
对于进行版本控制的对象，则为要使用的层存档对象版本。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Lambda::LayerVersion``Content`数据类型的`[S3ObjectVersion](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-layerversion-content.html#cfn-lambda-layerversion-content-s3objectversion)`属性。

## 示例
<a name="sam-property-layerversion-layercontent--examples"></a>

### LayerContent
<a name="sam-property-layerversion-layercontent--examples--layercontent"></a>

层内容示例

#### YAML
<a name="sam-property-layerversion-layercontent--examples--layercontent--yaml"></a>

```
LayerContent:
  Bucket: amzn-s3-demo-bucket-name
  Key: mykey-name
  Version: 121212
```

# AWS::Serverless::SimpleTable
<a name="sam-resource-simpletable"></a>

创建具有单个属性主键的 DynamoDB 表。当只需要通过主键访问数据时，它很有用。

要获得更多高级功能，请使用 CloudFormation中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html) 资源。这些资源可以在 AWS SAM中使用。它们内容全面，并支持进一步定制，包括 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-keyschema.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-keyschema.html) 和 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-resourcepolicy.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-resourcepolicy.html) 定制。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-simpletable-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-resource-simpletable-syntax.yaml"></a>

```
Type: AWS::Serverless::SimpleTable
Properties:
  PointInTimeRecoverySpecification: [PointInTimeRecoverySpecification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-pointintimerecoveryspecification.html)
  [PrimaryKey](#sam-simpletable-primarykey): PrimaryKeyObject
  [ProvisionedThroughput](#sam-simpletable-provisionedthroughput): ProvisionedThroughputObject
  [SSESpecification](#sam-simpletable-ssespecification): [SSESpecification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-ssespecification.html)
  [TableName](#sam-simpletable-tablename): String
  [Tags](#sam-simpletable-tags): Map
```

## Properties
<a name="sam-resource-simpletable-properties"></a>

 `PointInTimeRecoverySpecification`   <a name="sam-simpletable-pointintimerecoveryspecification"></a>
用于启用时间点恢复的设置。  
*类型*:[PointInTimeRecoverySpecification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-pointintimerecoveryspecification.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::DynamoDB::Table`资源的`[PointInTimeRecoverySpecification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-pointintimerecoveryspecification.html)`属性。

 `PrimaryKey`   <a name="sam-simpletable-primarykey"></a>
用作表主键的属性名称和类型。如果未提供，则主键将为 `String`，值为 `id`。  
创建此资源后，无法修改此属性的值。
*类型*：[PrimaryKeyObject](sam-property-simpletable-primarykeyobject.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ProvisionedThroughput`   <a name="sam-simpletable-provisionedthroughput"></a>
读取和写入吞吐量配置信息。  
如果未指定 `ProvisionedThroughput`，则将 `BillingMode` 指定为 `PAY_PER_REQUEST`。  
*类型*：[ProvisionedThroughputObject](sam-property-simpletable-provisionedthroughputobject.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::DynamoDB::Table`资源的`[ProvisionedThroughput](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-provisionedthroughput.html)`属性。

 `SSESpecification`   <a name="sam-simpletable-ssespecification"></a>
指定用于启用服务器端加密的设置。  
*类型*：[SSESpecification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-ssespecification.html)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::DynamoDB::Table`资源的`[SSESpecification](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-ssespecification.html)`属性。

 `TableName`   <a name="sam-simpletable-tablename"></a>
DynamoDB 表的名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::DynamoDB::Table`资源的`[TableName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-tablename)`属性。

 `Tags`   <a name="sam-simpletable-tags"></a>
一个地图（字符串到字符串），用于指定要添加到其中的标签 SimpleTable。有关标签的有效键和值的详细信息，请参阅*《AWS CloudFormation 用户指南》*中的[资源标签](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html)。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::DynamoDB::Table`资源的`[Tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#cfn-dynamodb-table-tags)`属性。SAM 中的 Tags 属性由 Key: Value CloudFormation 对组成；其中包含标签对象的列表。

## 返回值
<a name="sam-resource-simpletable-return-values"></a>

### Ref
<a name="sam-resource-simpletable-return-values-ref"></a>

当该资源的逻辑 ID 提供给 Ref 内置函数时，它将返回底层 DynamoDB 表的资源名称。

有关使用 `Ref` 函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。

## 示例
<a name="sam-resource-simpletable--examples"></a>

### SimpleTableExample
<a name="sam-resource-simpletable--examples--simpletableexample"></a>

的示例 SimpleTable

#### YAML
<a name="sam-resource-simpletable--examples--simpletableexample--yaml"></a>

```
Properties:
  TableName: my-table
  PrimaryKey:
    Name: MyPrimaryKey
    Type: String
  ProvisionedThroughput:
    ReadCapacityUnits: 5
    WriteCapacityUnits: 5
  Tags:
    Department: Engineering
    AppType: Serverless
```

# PrimaryKeyObject
<a name="sam-property-simpletable-primarykeyobject"></a>

描述主键属性的对象。

## 语法
<a name="sam-property-simpletable-primarykeyobject-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-simpletable-primarykeyobject-syntax.yaml"></a>

```
  [Name](#sam-simpletable-primarykeyobject-name): String
  [Type](#sam-simpletable-primarykeyobject-type): String
```

## Properties
<a name="sam-property-simpletable-primarykeyobject-properties"></a>

 `Name`   <a name="sam-simpletable-primarykeyobject-name"></a>
主键的属性名称。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::DynamoDB::Table``AttributeDefinition`数据类型的`[AttributeName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-attributedef.html#cfn-dynamodb-attributedef-attributename)`属性。  
*其他说明*：此属性也传递给`AWS::DynamoDB::Table KeySchema`数据类型的[AttributeName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-keyschema.html#aws-properties-dynamodb-keyschema-attributename)属性。

 `Type`   <a name="sam-simpletable-primarykeyobject-type"></a>
主键的数据类型。  
*有效值*：`String`、`Number`、`Binary`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::DynamoDB::Table``AttributeDefinition`数据类型的`[AttributeType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-attributedef.html#cfn-dynamodb-attributedef-attributename-attributetype)`属性。

## 示例
<a name="sam-property-simpletable-primarykeyobject--examples"></a>

### PrimaryKey
<a name="sam-property-simpletable-primarykeyobject--examples--primarykey"></a>

主键示例。

#### YAML
<a name="sam-property-simpletable-primarykeyobject--examples--primarykey--yaml"></a>

```
Properties:
  PrimaryKey:
    Name: MyPrimaryKey
    Type: String
```

# ProvisionedThroughputObject
<a name="sam-property-simpletable-provisionedthroughputobject"></a>

描述预置吞吐量属性的对象。

## 语法
<a name="sam-property-simpletable-provisionedthroughputobject-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="w2aac13c22c41c19b5b5"></a>

```
  [ReadCapacityUnits](#sam-simpletable-provisionedthroughputobject-readcapacityunits): Integer
  [WriteCapacityUnits](#sam-simpletable-provisionedthroughputobject-writecapacityunits): Integer
```

## Properties
<a name="sam-property-simpletable-provisionedthroughputobject-properties"></a>

 `ReadCapacityUnits`   <a name="sam-simpletable-provisionedthroughputobject-readcapacityunits"></a>
在 DynamoDB 返回 `ThrottlingException` 之前，每秒使用的最大强一致性读取数。  
*类型*：整数  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::DynamoDB::Table``ProvisionedThroughput`数据类型的`[ReadCapacityUnits](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-provisionedthroughput.html#aws-properties-dynamodb-table-provisionedthroughput-properties)`属性。

 `WriteCapacityUnits`   <a name="sam-simpletable-provisionedthroughputobject-writecapacityunits"></a>
在 DynamoDB 返回 `ThrottlingException` 之前，每秒使用的最大写入数。  
*类型*：整数  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::DynamoDB::Table``ProvisionedThroughput`数据类型的`[WriteCapacityUnits](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-dynamodb-table-provisionedthroughput.html#aws-properties-dynamodb-table-provisionedthroughput-properties)`属性。

## 示例
<a name="sam-property-simpletable-provisionedthroughputobject--examples"></a>

### ProvisionedThroughput
<a name="sam-property-simpletable-provisionedthroughputobject--examples--provisionedthroughput"></a>

预置吞吐量示例。

#### YAML
<a name="sam-property-simpletable-provisionedthroughputobject--examples--provisionedthroughput--yaml"></a>

```
Properties:
   ProvisionedThroughput:
     ReadCapacityUnits: 5
     WriteCapacityUnits: 5
```

# AWS::Serverless::StateMachine
<a name="sam-resource-statemachine"></a>

创建 AWS Step Functions 状态机，您可以使用它来编排 AWS Lambda 函数和其他 AWS 资源，以形成复杂而强大的工作流程。

有关 Step Functions 的更多信息，请参阅[《AWS Step Functions 开发人员指南》](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html)。

**注意**  
部署到时 AWS CloudFormation， AWS SAM 会将您的 AWS SAM 资源转换为 CloudFormation 资源。有关更多信息，请参阅 [生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

## 语法
<a name="sam-resource-statemachine-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-resource-statemachine-syntax.yaml"></a>

```
Type: AWS::Serverless::StateMachine
Properties:
  AutoPublishAlias: String
  UseAliasAsEventTarget: Boolean
  [Definition](#sam-statemachine-definition): Map
  [DefinitionSubstitutions](#sam-statemachine-definitionsubstitutions): Map
  [DefinitionUri](#sam-statemachine-definitionuri): String | [S3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-definitions3location)
  DeploymentPreference: [DeploymentPreference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stepfunctions-statemachinealias-deploymentpreference.html)
  [Events](#sam-statemachine-events): EventSource
  [Logging](#sam-statemachine-logging): [LoggingConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-loggingconfiguration)
  [Name](#sam-statemachine-name): String
  [PermissionsBoundary](#sam-statemachine-permissionsboundary): String
  [Policies](#sam-statemachine-policies): String | List | Map
  PropagateTags: Boolean
  [RolePath](#sam-statemachine-rolepath): String
  [Role](#sam-statemachine-role): String
  [Tags](#sam-statemachine-tags): Map
  [Tracing](#sam-statemachine-tracing): [TracingConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-tracingconfiguration)
  [Type](#sam-statemachine-type): String
```

## Properties
<a name="sam-resource-statemachine-properties"></a>

 `AutoPublishAlias`   <a name="sam-statemachine-autopublishalias"></a>
状态机别名的名称。要详细了解如何使用 Step Functions 状态机别名，请参阅*《AWS Step Functions 开发人员指南》*中的[使用版本与别名功能管理持续部署](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-cd-aliasing-versioning.html)。  
使用 `DeploymentPreference` 为别名配置部署首选项。如果您未指定`DeploymentPreference`，则 AWS SAM 会将流量配置为一次性切换到较新的状态机版本。  
AWS SAM 默认情况下，将版本`UpdateReplacePolicy``Retain`的`DeletionPolicy`和设置为。以前的版本不会被自动删除。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::StepFunctions::StateMachineAlias`资源的` [ Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachinealias.html#cfn-stepfunctions-statemachinealias-name)`属性。

 `UseAliasAsEventTarget`   <a name="sam-statemachine-usealiasaseventtarget"></a>
指示是否将使用 `AutoPublishAlias` 属性创建的别名传递给使用[事件](#sam-statemachine-events)定义的事件源目标。  
指定 `True` 使用别名作为事件的目标。  
*类型*：布尔值  
*必需*：否  
*默认值*：`False`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Definition`   <a name="sam-statemachine-definition"></a>
状态机定义是一个对象，其中对象的格式与 AWS SAM 模板文件的格式相匹配，例如 JSON 或 YAML。状态机定义遵循 [Amazon States Language](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html)。  
有关内联状态机定义的示例，请参见 [示例](#sam-resource-statemachine--examples)。  
您必须提供 `Definition` 或 `DefinitionUri`。  
*类型*：映射  
*必需*：条件  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `DefinitionSubstitutions`   <a name="sam-statemachine-definitionsubstitutions"></a>
在状态机定义中指定占位符变量的映射的 string-to-string地图。这使您能够将运行时获得的值（例如，从内置函数）注入到状态机定义中。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::StepFunctions::StateMachine`资源的`[DefinitionSubstitutions](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-definitionsubstitutions)`属性。如果在内联状态机定义中指定了任何内部函数，则向该属性 AWS SAM 添加条目以将其注入状态机定义中。

 `DefinitionUri`   <a name="sam-statemachine-definitionuri"></a>
Amazon Simple Storage Service (Amazon S3) URI 或以 [Amazon States Language](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html) 编写的状态机定义的本地文件路径。  
如果您提供本地文件路径，则模板必须通过包含 `sam deploy` 或 `sam package` 命令的工作流程才能使定义正确转换。为此，必须使用 AWS SAM CLI 版本 0.52.0 或更高版本。  
您必须提供 `Definition` 或 `DefinitionUri`。  
*类型*：字符串 \$1 [S3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-definitions3location)  
*必需*：条件  
*CloudFormation 兼容性*：此属性直接传递给`AWS::StepFunctions::StateMachine`资源的`[DefinitionS3Location](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-definitions3location)`属性。

 `DeploymentPreference`   <a name="sam-statemachine-deploymentpreference"></a>
启用和配置逐步状态机部署的设置。要详细了解 Step Functions 逐步部署，请参阅*《AWS Step Functions 开发人员指南》*中的[使用版本与别名功能管理持续部署](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-cd-aliasing-versioning.html)。  
在配置此属性之前指定 `AutoPublishAlias`。您的 `DeploymentPreference` 设置将应用于通过 `AutoPublishAlias` 指定的别名。  
指定后`DeploymentPreference`， AWS SAM 会自动生成`StateMachineVersionArn`子属性值。  
*类型*：[DeploymentPreference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stepfunctions-statemachinealias-deploymentpreference.html)  
*必需*：否  
*CloudFormation 兼容性*： AWS SAM 生成`StateMachineVersionArn`属性值并将其附加到资源的`[DeploymentPreference](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachinealias.html#cfn-stepfunctions-statemachinealias-deploymentpreference)`属性，`DeploymentPreference`然后传递`DeploymentPreference`给`AWS::StepFunctions::StateMachineAlias`资源的属性。

 `Events`   <a name="sam-statemachine-events"></a>
指定触发此状态机的事件。事件由一个类型和一组依赖于该类型的属性组成。  
*类型*：[EventSource](sam-property-statemachine-statemachineeventsource.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Logging`   <a name="sam-statemachine-logging"></a>
定义记录哪些执行历史事件以及它们的记录位置。  
*类型*：[LoggingConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-loggingconfiguration)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::StepFunctions::StateMachine`资源的`[LoggingConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-loggingconfiguration)`属性。

 `Name`   <a name="sam-statemachine-name"></a>
状态机的名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::StepFunctions::StateMachine`资源的`[StateMachineName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-statemachinename)`属性。

 `PermissionsBoundary`   <a name="sam-statemachine-permissionsboundary"></a>
此状态机执行角色使用的权限边界的 ARN。此属性仅在为您生成角色时有效。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IAM::Role`资源的`[PermissionsBoundary](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-permissionsboundary)`属性。

 `Policies`   <a name="sam-statemachine-policies"></a>
此状态机的权限策略。策略将附加到状态机的默认 AWS Identity and Access Management (IAM) 执行角色中。  
此属性接受单个值或值列表。允许的值包括：  
+ [AWS SAM策略模板](serverless-policy-templates.md).
+ [AWS 托管策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#aws-managed-policies)或[客户管理型策略](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#customer-managed-policies)的 ARN。
+ 以下[列表](https://github.com/aws/serverless-application-model/blob/develop/samtranslator/internal/data/aws_managed_policies.json)中 AWS 托管策略的名称。
+ 在 YAML 中格式化为映射的[内联 IAM policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html#inline-policies)。
如果指定 `Role` 属性，则将忽略该属性。
*类型*：字符串 \$1 列表 \$1 映射  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

`PropagateTags`  <a name="sam-statemachine-propagatetags"></a>
指明是否将 `Tags` 属性中的标签传递给 [AWS::Serverless::StateMachine](sam-specification-generated-resources-statemachine.md) 生成的资源。指定 `True` 以在生成的资源中传播标签。  
*类型*：布尔值  
*必需*：否  
*默认值*：`False`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Role`   <a name="sam-statemachine-role"></a>
用作此状态机执行角色的 IAM 角色的 ARN。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性直接传递给`AWS::StepFunctions::StateMachine`资源的`[ RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-rolearn)`属性。

 `RolePath`   <a name="sam-statemachine-rolepath"></a>
状态机的 IAM 执行角色的路径。  
生成角色时请使用此属性。当使用 `Role` 属性指定角色时，请勿使用。  
*类型*：字符串  
*必需*：条件  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IAM::Role`资源的`[Path](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-path)`属性。

 `Tags`   <a name="sam-statemachine-tags"></a>
指定添加到状态机的标签和相应的执行角色的 string-to-string地图。有关标签的有效键和值的信息，请参阅 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html) 资源的[标签](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-tags)属性。  
*类型*：映射  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::StepFunctions::StateMachine`资源的`[Tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-tags)`属性。 AWS SAM 自动为该资源以及为其生成的默认角色添加`stateMachine:createdBy:SAM`标签。

 `Tracing`   <a name="sam-statemachine-tracing"></a>
选择是否 AWS X-Ray 为状态机启用。有关使用 X-Ray 和 Step Functions 的更多信息，请参阅*《AWS Step Functions 开发人员指南》*中的 [AWS X-Ray 与 Step Functions](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-xray-tracing.html)。  
*类型*：[TracingConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-tracingconfiguration)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::StepFunctions::StateMachine`资源的`[TracingConfiguration](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-tracingconfiguration)`属性。

 `Type`   <a name="sam-statemachine-type"></a>
状态机的类型。  
*有效值*：`STANDARD` 或 `EXPRESS`  
*类型*：字符串  
*必需*：否  
*默认值*：`STANDARD`  
*CloudFormation 兼容性*：此属性直接传递给`AWS::StepFunctions::StateMachine`资源的`[StateMachineType](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html#cfn-stepfunctions-statemachine-statemachinetype)`属性。

## 返回值
<a name="sam-resource-statemachine-return-values"></a>

### Ref
<a name="sam-resource-statemachine-return-values-ref"></a>

在将此资源的逻辑 ID 提供给 Ref 内置函数时，Ref 会返回底层 `AWS::StepFunctions::StateMachine` 资源的 Amazon 资源名称（ARN）。

有关使用 `Ref` 函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。

### Fn:: GetAtt
<a name="sam-resource-statemachine-return-values-fn--getatt"></a>

`Fn::GetAtt` 返回一个此类型指定属性的值。以下为可用属性和示例返回值。

有关使用 `Fn::GetAtt` 的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的 [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html)。

`Name`  <a name="Name-fn::getatt"></a>
返回状态机的名称，例如 `HelloWorld-StateMachine`。

## 示例
<a name="sam-resource-statemachine--examples"></a>

### 状态机定义文件
<a name="sam-resource-statemachine--examples--state-machine-definition-file"></a>

以下是内联状态机定义的示例，该定义允许 Lambda 函数调用状态机。请注意，此示例要求 `Role` 属性配置适当的策略以允许调用。`my_state_machine.asl.json` 文件必须以 [Amazon States Language](https://docs.aws.amazon.com/step-functions/latest/dg/concepts-amazon-states-language.html) 编写。

在此示例中，这些`DefinitionSubstitution`条目允许状态机包含在 AWS SAM 模板文件中声明的资源。

#### YAML
<a name="sam-resource-statemachine--examples--state-machine-definition-file--yaml"></a>

```
MySampleStateMachine:
  Type: AWS::Serverless::StateMachine
  Properties:
    DefinitionUri: statemachine/my_state_machine.asl.json
    Role: arn:aws:iam::123456123456:role/service-role/my-sample-role
    Tracing:
      Enabled: true
    DefinitionSubstitutions:
      MyFunctionArn: !GetAtt MyFunction.Arn
      MyDDBTable: !Ref TransactionTable
```

### 内联状态机定义
<a name="sam-resource-statemachine--examples--inline-state-machine-definition"></a>

以下是内联状态机定义的示例。

在此示例中， AWS SAM 模板文件是用 YAML 编写的，因此状态机定义也在 YAML 中。要在 JSON 中声明内联状态机定义，请使用 JSON 编写 AWS SAM 模板文件。

#### YAML
<a name="sam-resource-statemachine--examples--inline-state-machine-definition--yaml"></a>

```
MySampleStateMachine:
  Type: AWS::Serverless::StateMachine
  Properties:
    Definition:
      StartAt: MyLambdaState
      States:
        MyLambdaState:
          Type: Task
          Resource: arn:aws:lambda:us-east-1:123456123456:function:my-sample-lambda-app
          End: true
    Role: arn:aws:iam::123456123456:role/service-role/my-sample-role
    Tracing:
      Enabled: true
```

# EventSource
<a name="sam-property-statemachine-statemachineeventsource"></a>

描述触发状态机的事件源的对象。每个事件都由一个类型和一组依赖于该类型的属性组成。有关每个事件源的属性的更多信息，请参阅与具体类型对应的子主题。

## 语法
<a name="sam-property-statemachine-statemachineeventsource-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachineeventsource-syntax.yaml"></a>

```
  [Properties](#sam-statemachine-statemachineeventsource-properties): Schedule | ScheduleV2 | CloudWatchEvent | EventBridgeRule | Api
  [Type](#sam-statemachine-statemachineeventsource-type): String
```

## Properties
<a name="sam-property-statemachine-statemachineeventsource-properties"></a>

 `Properties`   <a name="sam-statemachine-statemachineeventsource-properties"></a>
描述此事件映射的属性的对象。这组属性必须符合定义的 `Type`。  
*类型*[：[日程安排](sam-property-statemachine-statemachineschedule.md) \$1 [ScheduleV2](sam-property-statemachine-statemachineschedulev2.md) \$1 \$1 \$1 A [CloudWatchEvent](sam-property-statemachine-statemachinecloudwatchevent.md)pi [EventBridgeRule](sam-property-statemachine-statemachineeventbridgerule.md)](sam-property-statemachine-statemachineapi.md)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Type`   <a name="sam-statemachine-statemachineeventsource-type"></a>
事件类型。  
*有效值*：`Api`、`Schedule`、`ScheduleV2`、`CloudWatchEvent`、`EventBridgeRule`  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-statemachine-statemachineeventsource--examples"></a>

### API
<a name="sam-property-statemachine-statemachineeventsource--examples--api"></a>

以下是 `API` 类型事件的示例。

#### YAML
<a name="sam-property-statemachine-statemachineeventsource--examples--api--yaml"></a>

```
ApiEvent:
  Type: Api
  Properties:
    Method: get
    Path: /group/{user}
    RestApiId: 
      Ref: MyApi
```

# Api
<a name="sam-property-statemachine-statemachineapi"></a>

描述 `Api` 事件源类型的对象。如果定义了 [AWS::Serverless::Api](sam-resource-api.md) 资源，则路径和方法值必须与 API 的 OpenAPI 定义中的操作相对应。

## 语法
<a name="sam-property-statemachine-statemachineapi-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachineapi-syntax.yaml"></a>

```
  [Auth](#sam-statemachine-statemachineapi-auth): ApiStateMachineAuth
  [Method](#sam-statemachine-statemachineapi-method): String
  [Path](#sam-statemachine-statemachineapi-path): String
  [RestApiId](#sam-statemachine-statemachineapi-restapiid): String
  UnescapeMappingTemplate: Boolean
```

## Properties
<a name="sam-property-statemachine-statemachineapi-properties"></a>

 `Auth`   <a name="sam-statemachine-statemachineapi-auth"></a>
此 API、路径和方法的授权配置。  
如果未指定 `DefaultAuthorizer`，则使用此属性覆盖单个路径的 API `DefaultAuthorizer` 设置，或者覆盖默认 `ApiKeyRequired` 设置。  
*类型*：[ApiStateMachineAuth](sam-property-statemachine-apistatemachineauth.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Method`   <a name="sam-statemachine-statemachineapi-method"></a>
调用此函数的 HTTP 方法。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Path`   <a name="sam-statemachine-statemachineapi-path"></a>
调用此函数的 URI 路径。值必须以 `/` 开头。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `RestApiId`   <a name="sam-statemachine-statemachineapi-restapiid"></a>
`RestApi` 资源的标识符，必须包含具有给定路径和方法的操作。通常，将其设置为引用此模板中定义的 [AWS::Serverless::Api](sam-resource-api.md) 资源。  
如果未定义此属性，则使用生成的`OpenApi`文档 AWS SAM 创建默认[AWS::Serverless::Api](sam-resource-api.md)资源。该资源包含所有路径和方法的并集，这些路径和方法由同一模板中的 `Api` 事件定义，但未指定 `RestApiId`。  
此属性无法引用在其他模板中定义的 [AWS::Serverless::Api](sam-resource-api.md) 资源。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `UnescapeMappingTemplate`   <a name="sam-statemachine-statemachineapi-unescapemappingtemplate"></a>
在传递给状态机的输入上，通过将 `\'` 替换为 `'` 来取消转义单引号。当输入包含单引号时使用。  
如果设置为 `False` 并且输入包含单引号，则会发生错误。
*类型*：布尔值  
*必需*：否  
*默认值*：False  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-statemachine-statemachineapi--examples"></a>

### ApiEvent
<a name="sam-property-statemachine-statemachineapi--examples--apievent"></a>

以下是 `Api` 类型事件的示例。

#### YAML
<a name="sam-property-statemachine-statemachineapi--examples--apievent--yaml"></a>

```
Events:
  ApiEvent:
    Type: Api
    Properties:
      Path: /path
      Method: get
```

# ApiStateMachineAuth
<a name="sam-property-statemachine-apistatemachineauth"></a>

在事件级别为特定 API、路径和方法配置授权。

## 语法
<a name="sam-property-statemachine-apistatemachineauth-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-apistatemachineauth-syntax.yaml"></a>

```
  [ApiKeyRequired](#sam-statemachine-apistatemachineauth-apikeyrequired): Boolean
  [AuthorizationScopes](#sam-statemachine-apistatemachineauth-authorizationscopes): List
  [Authorizer](#sam-statemachine-apistatemachineauth-authorizer): String
  [ResourcePolicy](#sam-statemachine-apistatemachineauth-resourcepolicy): ResourcePolicyStatement
```

## Properties
<a name="sam-property-statemachine-apistatemachineauth-properties"></a>

 `ApiKeyRequired`   <a name="sam-statemachine-apistatemachineauth-apikeyrequired"></a>
此 API、路径和方法需要 API 密钥。  
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AuthorizationScopes`   <a name="sam-statemachine-apistatemachineauth-authorizationscopes"></a>
适用于此 API、路径和方法的授权范围。  
如果您已指定 `DefaultAuthorizer` 属性，则您指定的范围将覆盖该属性应用的所有范围。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Authorizer`   <a name="sam-statemachine-apistatemachineauth-authorizer"></a>
适用于特定状态机的 `Authorizer`。  
如果您已为 API 指定了全局授权方并希望公开此状态机，请通过将 `Authorizer` 设置为 `NONE` 来覆盖全局授权方。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `ResourcePolicy`   <a name="sam-statemachine-apistatemachineauth-resourcepolicy"></a>
为此 API 和路径配置资源策略。  
*类型*：[ResourcePolicyStatement](sam-property-statemachine-resourcepolicystatement.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-statemachine-apistatemachineauth--examples"></a>

### StateMachine-身份验证
<a name="sam-property-statemachine-apistatemachineauth--examples--statemachine-auth"></a>

以下示例指定了状态机级别的授权。

#### YAML
<a name="sam-property-statemachine-apistatemachineauth--examples--statemachine-auth--yaml"></a>

```
Auth:
  ApiKeyRequired: true
  Authorizer: NONE
```

# ResourcePolicyStatement
<a name="sam-property-statemachine-resourcepolicystatement"></a>

为 API 的所有方法和路径配置资源策略。有关资源策略的更多信息，请参阅*《API Gateway 开发人员指南》*中的[使用 API Gateway 资源策略控制 API 的访问权限](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-resource-policies.html)。

## 语法
<a name="sam-property-statemachine-resourcepolicystatement-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-resourcepolicystatement-syntax.yaml"></a>

```
  [AwsAccountBlacklist](#sam-statemachine-resourcepolicystatement-awsaccountblacklist): List
  [AwsAccountWhitelist](#sam-statemachine-resourcepolicystatement-awsaccountwhitelist): List
  [CustomStatements](#sam-statemachine-resourcepolicystatement-customstatements): List
  [IntrinsicVpcBlacklist](#sam-statemachine-resourcepolicystatement-intrinsicvpcblacklist): List
  [IntrinsicVpcWhitelist](#sam-statemachine-resourcepolicystatement-intrinsicvpcwhitelist): List
  [IntrinsicVpceBlacklist](#sam-statemachine-resourcepolicystatement-intrinsicvpceblacklist): List
  [IntrinsicVpceWhitelist](#sam-statemachine-resourcepolicystatement-intrinsicvpcewhitelist): List
  [IpRangeBlacklist](#sam-statemachine-resourcepolicystatement-iprangeblacklist): List
  [IpRangeWhitelist](#sam-statemachine-resourcepolicystatement-iprangewhitelist): List
  [SourceVpcBlacklist](#sam-statemachine-resourcepolicystatement-sourcevpcblacklist): List
  [SourceVpcWhitelist](#sam-statemachine-resourcepolicystatement-sourcevpcwhitelist): List
```

## Properties
<a name="sam-property-statemachine-resourcepolicystatement-properties"></a>

 `AwsAccountBlacklist`   <a name="sam-statemachine-resourcepolicystatement-awsaccountblacklist"></a>
要封锁的 AWS 账户。  
*类型*：字符串列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `AwsAccountWhitelist`   <a name="sam-statemachine-resourcepolicystatement-awsaccountwhitelist"></a>
要允许的 AWS 账户。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：字符串列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `CustomStatements`   <a name="sam-statemachine-resourcepolicystatement-customstatements"></a>
适用于此 API 的自定义资源策略语句列表。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpcBlacklist`   <a name="sam-statemachine-resourcepolicystatement-intrinsicvpcblacklist"></a>
要屏蔽的虚拟私有云列表 (VPCs)，其中每个 VPC 都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内部函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpcWhitelist`   <a name="sam-statemachine-resourcepolicystatement-intrinsicvpcwhitelist"></a>
 VPCs 要允许的列表，其中每个 VPC 都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内部函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpceBlacklist`   <a name="sam-statemachine-resourcepolicystatement-intrinsicvpceblacklist"></a>
要阻止的 VPC 端点列表，其中每个 VPC 端点都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内置函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IntrinsicVpceWhitelist`   <a name="sam-statemachine-resourcepolicystatement-intrinsicvpcewhitelist"></a>
要允许的 VPC 端点列表，其中每个 VPC 端点都指定为引用，例如[动态引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/dynamic-references.html)或`Ref`[内置函数](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html)。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IpRangeBlacklist`   <a name="sam-statemachine-resourcepolicystatement-iprangeblacklist"></a>
要阻止的 IP 地址或地址范围。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `IpRangeWhitelist`   <a name="sam-statemachine-resourcepolicystatement-iprangewhitelist"></a>
要允许的 IP 地址或地址范围。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceVpcBlacklist`   <a name="sam-statemachine-resourcepolicystatement-sourcevpcblacklist"></a>
要阻止的源 VPC 或 VPC 端点。源 VPC 名称必须以 `"vpc-"` 开头，源 VPC 端点名称必须以 `"vpce-"` 开头。有关此属性的使用示例，请参阅本页底部的“示例”部分。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `SourceVpcWhitelist`   <a name="sam-statemachine-resourcepolicystatement-sourcevpcwhitelist"></a>
要允许的源 VPC 或 VPC 端点。源 VPC 名称必须以 `"vpc-"` 开头，源 VPC 端点名称必须以 `"vpce-"` 开头。  
*类型*：列表  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-statemachine-resourcepolicystatement--examples"></a>

### 资源策略示例
<a name="sam-property-statemachine-resourcepolicystatement--examples--resource-policy-example"></a>

以下示例屏蔽两个 IP 地址和一个源 VPC，并允许一个 AWS 账户。

#### YAML
<a name="sam-property-statemachine-resourcepolicystatement--examples--resource-policy-example--yaml"></a>

```
Auth:
  ResourcePolicy:
    CustomStatements: [{
                         "Effect": "Allow",
                         "Principal": "*",
                         "Action": "execute-api:Invoke",
                         "Resource": "execute-api:/Prod/GET/pets",
                         "Condition": {
                           "IpAddress": {
                             "aws:SourceIp": "1.2.3.4"
                           }
                         }
                       }]
    IpRangeBlacklist:
      - "10.20.30.40"
      - "1.2.3.4"
    SourceVpcBlacklist:
      - "vpce-1a2b3c4d"
    AwsAccountWhitelist:
      - "111122223333"
    IntrinsicVpcBlacklist:
      - "{{resolve:ssm:SomeVPCReference:1}}" 
      - !Ref MyVPC
    IntrinsicVpceWhitelist:
      - "{{resolve:ssm:SomeVPCEReference:1}}" 
      - !Ref MyVPCE
```

# CloudWatchEvent
<a name="sam-property-statemachine-statemachinecloudwatchevent"></a>

描述 `CloudWatchEvent` 事件源类型的对象。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html)资源。

**重要说明**：[EventBridgeRule](sam-property-statemachine-statemachineeventbridgerule.md)是首选使用的事件源类型，而不是`CloudWatchEvent`。 `EventBridgeRule`并`CloudWatchEvent`使用相同的底层服务、API 和 CloudFormation 资源。但是， AWS SAM 将仅向添加对新功能的支持`EventBridgeRule`。

## 语法
<a name="sam-property-statemachine-statemachinecloudwatchevent-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachinecloudwatchevent-syntax.yaml"></a>

```
  [EventBusName](#sam-statemachine-statemachinecloudwatchevent-eventbusname): String
  [Input](#sam-statemachine-statemachinecloudwatchevent-input): String
  [InputPath](#sam-statemachine-statemachinecloudwatchevent-inputpath): String
  [Pattern](#sam-statemachine-statemachinecloudwatchevent-pattern): [EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)
```

## Properties
<a name="sam-property-statemachine-statemachinecloudwatchevent-properties"></a>

 `EventBusName`   <a name="sam-statemachine-statemachinecloudwatchevent-eventbusname"></a>
要与该规则关联的事件总线。如果省略此属性，则 AWS SAM 使用默认的事件总线。  
*类型*：字符串  
*必需*：否  
*默认*：默认事件总线  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventBusName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventbusname)`属性。

 `Input`   <a name="sam-statemachine-statemachinecloudwatchevent-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-input)`属性。

 `InputPath`   <a name="sam-statemachine-statemachinecloudwatchevent-inputpath"></a>
当您不希望将整个匹配事件传递给目标时，请使用 `InputPath` 属性描述要传递事件的哪一部分。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[InputPath](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath)`属性。

 `Pattern`   <a name="sam-statemachine-statemachinecloudwatchevent-pattern"></a>
描述哪些事件路由到指定目标。有关更多信息，请参阅 *Amazon EventBridge 用户指南 EventBridge*[中的事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html)。  
*类型*：[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)`属性。

## 示例
<a name="sam-property-statemachine-statemachinecloudwatchevent--examples"></a>

### CloudWatchEvent
<a name="sam-property-statemachine-statemachinecloudwatchevent--examples--cloudwatchevent"></a>

以下是 `CloudWatchEvent` 事件源类型的示例。

#### YAML
<a name="sam-property-statemachine-statemachinecloudwatchevent--examples--cloudwatchevent--yaml"></a>

```
CWEvent:
  Type: CloudWatchEvent
  Properties:
    Input: '{"Key": "Value"}'
    Pattern:
      detail:
        state:
          - running
```

# EventBridgeRule
<a name="sam-property-statemachine-statemachineeventbridgerule"></a>

描述`EventBridgeRule`事件源类型的对象，它将您的状态机设置为 Amazon EventBridge 规则的目标。有关更多信息，请参阅[什么是亚马逊 EventBridge？](https://docs.aws.amazon.com/eventbridge/latest/userguide/what-is-amazon-eventbridge.html) 在《*亚马逊 EventBridge 用户指南》*中。

AWS SAM 设置此事件类型时会生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html)资源。

## 语法
<a name="sam-property-statemachine-statemachineeventbridgerule-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachineeventbridgerule-syntax.yaml"></a>

```
  DeadLetterConfig: DeadLetterConfig
  EventBusName: String
  Input: String
  InputPath: String
  InputTransformer: [InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-inputtransformer.html)
  Pattern: [EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)
  RetryPolicy: [RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)
  RuleName: String
  State: String
  Target: Target
```

## Properties
<a name="sam-property-statemachine-statemachineeventbridgerule-properties"></a>

 `DeadLetterConfig`   <a name="sam-statemachine-statemachineeventbridgerule-deadletterconfig"></a>
配置亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的 Lambda 函数发送事件时，或者没有足够的权限调用 Lambda 函数 EventBridge 时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
*类型*：[DeadLetterConfig](sam-property-statemachine-statemachinedeadletterconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule``Target`数据类型的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-deadletterconfig)`属性。此属性的 AWS SAM 版本包括其他子属性， AWS SAM 以备您想要创建死信队列时使用。

 `EventBusName`   <a name="sam-statemachine-statemachineeventbridgerule-eventbusname"></a>
要与该规则关联的事件总线。如果省略此属性，则 AWS SAM 使用默认的事件总线。  
*类型*：字符串  
*必需*：否  
*默认*：默认事件总线  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventBusName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventbusname)`属性。

 `Input`   <a name="sam-statemachine-statemachineeventbridgerule-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-input)`属性。

 `InputPath`   <a name="sam-statemachine-statemachineeventbridgerule-inputpath"></a>
当您不希望将整个匹配事件传递给目标时，请使用 `InputPath` 属性描述要传递事件的哪一部分。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[InputPath](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath)`属性。

`InputTransformer`  <a name="sam-statemachine-statemachineeventbridgerule-inputtransformer"></a>
使您可以根据特定事件数据向目标提供自定义输入的设置。您可以从事件中提取一个或多个键值对，然后使用该数据将自定义输入发送到目标。有关更多信息，请参阅《[亚马逊* EventBridge 用户指南》中的亚马逊 EventBridge *输入转换](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-transform-target-input.html)。  
*类型*：[InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputtransformer)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[InputTransformer](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-inputtransformer.html) `属性。

 `Pattern`   <a name="sam-statemachine-statemachineeventbridgerule-pattern"></a>
描述哪些事件路由到指定目标。有关更多信息，请参阅 *Amazon EventBridge 用户指南 EventBridge*[中的事件和事件模式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eventbridge-and-event-patterns.html)。  
*类型*：[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[EventPattern](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-eventpattern)`属性。

 `RetryPolicy`   <a name="sam-statemachine-statemachineeventbridgerule-retrypolicy"></a>
包含有关重试策略设置的信息的 `RetryPolicy` 对象。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
*类型*：[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)`属性。

 `RuleName`   <a name="sam-statemachine-statemachineeventbridgerule-rulename"></a>
 规则的名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-name)`属性。

`State`  <a name="sam-statemachine-statemachineeventbridgerule-state"></a>
规则的状态。  
*有效值*：`[ DISABLED | ENABLED ]`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state)`属性。

 `Target`   <a name="sam-statemachine-statemachineeventbridgerule-target"></a>
触发规则时 EventBridge 调用的 AWS 资源。您可以使用此属性来指定目标的逻辑 ID。如果未指定此属性，则 AWS SAM 生成目标的逻辑 ID。  
*类型*：[目标](sam-property-statemachine-statemachinetarget.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule`资源的`[Targets](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-targets)`属性。此属性的 AWS SAM 版本仅允许您指定单个目标的逻辑 ID。

## 示例
<a name="sam-property-statemachine-statemachineeventbridgerule--examples"></a>

### EventBridgeRule
<a name="sam-property-statemachine-statemachineeventbridgerule--examples--eventbridgerule"></a>

以下是 `EventBridgeRule` 事件源类型的示例。

#### YAML
<a name="sam-property-statemachine-statemachineeventbridgerule--examples--eventbridgerule--yaml"></a>

```
EBRule:
  Type: EventBridgeRule
  Properties:
    Input: '{"Key": "Value"}'
    Pattern:
      detail:
        state:
          - terminated
```

# DeadLetterConfig
<a name="sam-property-statemachine-statemachinedeadletterconfig"></a>

该对象用于指定亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的状态机发送事件或调用状态机的权限不足时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。

## 语法
<a name="sam-property-statemachine-statemachinedeadletterconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachinedeadletterconfig-syntax.yaml"></a>

```
  [Arn](#sam-statemachine-statemachinedeadletterconfig-arn): String
  [QueueLogicalId](#sam-statemachine-statemachinedeadletterconfig-queuelogicalid): String
  [Type](#sam-statemachine-statemachinedeadletterconfig-type): String
```

## Properties
<a name="sam-property-statemachine-statemachinedeadletterconfig-properties"></a>

 `Arn`   <a name="sam-statemachine-statemachinedeadletterconfig-arn"></a>
指定作为死信队列目标的 Amazon SQS 队列的 Amazon 资源名称（ARN）。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``DeadLetterConfig`数据类型的`[Arn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-deadletterconfig.html#cfn-events-rule-deadletterconfig-arn)`属性。

 `QueueLogicalId`   <a name="sam-statemachine-statemachinedeadletterconfig-queuelogicalid"></a>
指定了 AWS SAM 创建的死信队列的自定义名称。`Type`  
如果未设置 `Type` 属性，则将忽略该属性。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Type`   <a name="sam-statemachine-statemachinedeadletterconfig-type"></a>
队列的类型。设置此属性后， AWS SAM 会自动创建死信队列并附加必要的[基于资源的策略](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html#dlq-perms)，以授予规则资源向队列发送事件的权限。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*有效值*：`SQS`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-statemachine-statemachinedeadletterconfig--examples"></a>

### DeadLetterConfig
<a name="sam-property-statemachine-statemachinedeadletterconfig--examples--deadletterconfig"></a>

DeadLetterConfig

#### YAML
<a name="sam-property-statemachine-statemachinedeadletterconfig--examples--deadletterconfig--yaml"></a>

```
DeadLetterConfig:
  Type: SQS
  QueueLogicalId: MyDLQ
```

# Target
<a name="sam-property-statemachine-statemachinetarget"></a>

配置触发规则时 EventBridge 调用的 AWS 资源。

## 语法
<a name="sam-property-statemachine-statemachinetarget-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachinetarget-syntax.yaml"></a>

```
  [Id](#sam-statemachine-statemachinetarget-id): String
```

## Properties
<a name="sam-property-statemachine-statemachinetarget-properties"></a>

 `Id`   <a name="sam-statemachine-statemachinetarget-id"></a>
目标的逻辑 ID。  
`Id` 的值可以包含字母数字字符、句点 (`.`)、连字符 (`-`) 和下划线 (`_`)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[Id](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-id)`属性。

## 示例
<a name="sam-property-statemachine-statemachinetarget--examples"></a>

### Target
<a name="sam-property-statemachine-statemachinetarget--examples--target"></a>

#### YAML
<a name="sam-property-statemachine-statemachinetarget--examples--target--yaml"></a>

```
EBRule:
  Type: EventBridgeRule
  Properties:
    Target:
      Id: MyTarget
```

# Schedule
<a name="sam-property-statemachine-statemachineschedule"></a>

描述`Schedule`事件源类型的对象，它将您的状态机设置为按计划触发的 EventBridge 规则的目标。有关更多信息，请参阅[什么是亚马逊 EventBridge？](https://docs.aws.amazon.com/eventbridge/latest/userguide/what-is-amazon-eventbridge.html) 在《*亚马逊 EventBridge 用户指南》*中。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html)资源。

## 语法
<a name="sam-property-statemachine-statemachineschedule-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachineschedule-syntax.yaml"></a>

```
  [DeadLetterConfig](#sam-statemachine-statemachineschedule-deadletterconfig): DeadLetterConfig
  [Description](#sam-statemachine-statemachineschedule-description): String
  [Enabled](#sam-statemachine-statemachineschedule-enabled): Boolean
  [Input](#sam-statemachine-statemachineschedule-input): String
  [Name](#sam-statemachine-statemachineschedule-name): String
  [RetryPolicy](#sam-statemachine-statemachineschedule-retrypolicy): [RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)
  [RoleArn](#sam-statemachine-statemachineschedulev-rolearn): String
  [Schedule](#sam-statemachine-statemachineschedule-schedule): String
  [State](#sam-statemachine-statemachineschedule-state): String
  Target: Target
```

## Properties
<a name="sam-property-statemachine-statemachineschedule-properties"></a>

 `DeadLetterConfig`   <a name="sam-statemachine-statemachineschedule-deadletterconfig"></a>
配置亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的 Lambda 函数发送事件时，或者没有足够的权限调用 Lambda 函数 EventBridge 时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
*类型*：[DeadLetterConfig](sam-property-statemachine-statemachinescheduledeadletterconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule``Target`数据类型的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-deadletterconfig)`属性。此属性的 AWS SAM 版本包括其他子属性， AWS SAM 以备您想要创建死信队列时使用。

 `Description`   <a name="sam-statemachine-statemachineschedule-description"></a>
规则的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-description)`属性。

 `Enabled`   <a name="sam-statemachine-statemachineschedule-enabled"></a>
指示是否启用规则。  
要禁用该规则，请将此属性设置为 `false`。  
指定 `Enabled` 或 `State` 属性，但不能同时指定两者。
*类型*：布尔值  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state)`属性。如果此属性设置为，`true`则 AWS SAM 通过`ENABLED`，否则通过`DISABLED`。

 `Input`   <a name="sam-statemachine-statemachineschedule-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-input)`属性。

 `Name`   <a name="sam-statemachine-statemachineschedule-name"></a>
 规则的名称。如果您不指定名称，则 CloudFormation 会生成一个唯一的物理 ID 并将该 ID 用作规则名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-name)`属性。

 `RetryPolicy`   <a name="sam-statemachine-statemachineschedule-retrypolicy"></a>
包含有关重试策略设置的信息的 `RetryPolicy` 对象。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。  
*类型*：[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-retrypolicy)`属性。

 `RoleArn`   <a name="sam-statemachine-statemachineschedulev-rolearn"></a>
调用计划时， EventBridge 计划程序将用于目标的 IAM 角色的 ARN。  
*类型*：[RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)  
*必需*：否。如果未提供，则将创建并使用新角色。  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule``Target`数据类型的`[RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)`属性。

 `Schedule`   <a name="sam-statemachine-statemachineschedule-schedule"></a>
决定运行规则的时间和频率的计划表达式。有关更多信息，请参阅[规则的计划表达式](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-create-rule-schedule.html)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[ScheduleExpression](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-scheduleexpression)`属性。

 `State`   <a name="sam-statemachine-statemachineschedule-state"></a>
规则的状态。  
*接受的值：*`DISABLED | ENABLED`  
指定 `Enabled` 或 `State` 属性，但不能同时指定两者。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-state)`属性。

 `Target`   <a name="sam-statemachine-statemachineschedule-target"></a>
触发规则时 EventBridge 调用的 AWS 资源。您可以使用此属性来指定目标的逻辑 ID。如果未指定此属性，则 AWS SAM 生成目标的逻辑 ID。  
*类型*：[目标](sam-property-statemachine-statemachinetarget.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Events::Rule`资源的`[Targets](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html#cfn-events-rule-targets)`属性。此属性的 AWS SAM 版本仅允许您指定单个目标的逻辑 ID。

## 示例
<a name="sam-property-statemachine-statemachineschedule--examples"></a>

### CloudWatch 安排活动
<a name="sam-property-statemachine-statemachineschedule--examples--cloudwatch-schedule-event"></a>

CloudWatch 安排活动示例

#### YAML
<a name="sam-property-statemachine-statemachineschedule--examples--cloudwatch-schedule-event--yaml"></a>

```
CWSchedule:
  Type: Schedule
  Properties:
    Schedule: 'rate(1 minute)'
    Name: TestSchedule
    Description: test schedule
    Enabled: false
```

# DeadLetterConfig
<a name="sam-property-statemachine-statemachinescheduledeadletterconfig"></a>

该对象用于指定亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的状态机发送事件或调用状态机的权限不足时，调用可能会失败。有关更多信息，请参阅 A *ma EventBridge * zon 用户指南中的[事件重试策略和使用死信队列](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html)。

## 语法
<a name="sam-property-statemachine-statemachinescheduledeadletterconfig-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachinescheduledeadletterconfig-syntax.yaml"></a>

```
  [Arn](#sam-statemachine-statemachinescheduledeadletterconfig-arn): String
  [QueueLogicalId](#sam-statemachine-statemachinescheduledeadletterconfig-queuelogicalid): String
  [Type](#sam-statemachine-statemachinescheduledeadletterconfig-type): String
```

## Properties
<a name="sam-property-statemachine-statemachinescheduledeadletterconfig-properties"></a>

 `Arn`   <a name="sam-statemachine-statemachinescheduledeadletterconfig-arn"></a>
指定作为死信队列目标的 Amazon SQS 队列的 Amazon 资源名称（ARN）。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``DeadLetterConfig`数据类型的`[Arn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-deadletterconfig.html#cfn-events-rule-deadletterconfig-arn)`属性。

 `QueueLogicalId`   <a name="sam-statemachine-statemachinescheduledeadletterconfig-queuelogicalid"></a>
指定了 AWS SAM 创建的死信队列的自定义名称。`Type`  
如果未设置 `Type` 属性，则将忽略该属性。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `Type`   <a name="sam-statemachine-statemachinescheduledeadletterconfig-type"></a>
队列的类型。设置此属性后， AWS SAM 会自动创建死信队列并附加必要的[基于资源的策略](https://docs.aws.amazon.com/eventbridge/latest/userguide/rule-dlq.html#dlq-perms)，以授予规则资源向队列发送事件的权限。  
指定 `Type` 属性或 `Arn` 属性，但不能同时指定两者。
*有效值*：`SQS`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

## 示例
<a name="sam-property-statemachine-statemachinescheduledeadletterconfig--examples"></a>

### DeadLetterConfig
<a name="sam-property-statemachine-statemachinescheduledeadletterconfig--examples--deadletterconfig"></a>

DeadLetterConfig

#### YAML
<a name="sam-property-statemachine-statemachinescheduledeadletterconfig--examples--deadletterconfig--yaml"></a>

```
DeadLetterConfig:
  Type: SQS
  QueueLogicalId: MyDLQ
```

# Target
<a name="sam-property-statemachine-statemachinescheduletarget"></a>

配置触发规则时 EventBridge 调用的 AWS 资源。

## 语法
<a name="sam-property-statemachine-statemachinescheduletarget-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachinescheduletarget-syntax.yaml"></a>

```
  [Id](#sam-statemachine-statemachinescheduletarget-id): String
```

## Properties
<a name="sam-property-statemachine-statemachinescheduletarget-properties"></a>

 `Id`   <a name="sam-statemachine-statemachinescheduletarget-id"></a>
目标的逻辑 ID。  
`Id` 的值可以包含字母数字字符、句点 (`.`)、连字符 (`-`) 和下划线 (`_`)。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Events::Rule``Target`数据类型的`[Id](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-id)`属性。

## 示例
<a name="sam-property-statemachine-statemachinescheduletarget--examples"></a>

### Target
<a name="sam-property-statemachine-statemachinescheduletarget--examples--target"></a>

#### YAML
<a name="sam-property-statemachine-statemachinescheduletarget--examples--target--yaml"></a>

```
EBRule:
  Type: Schedule
  Properties:
    Target:
      Id: MyTarget
```

# ScheduleV2
<a name="sam-property-statemachine-statemachineschedulev2"></a>

描述`ScheduleV2`事件源类型的对象，它将您的状态机设置为按计划触发的 Amazon S EventBridge cheduler 事件的目标。有关更多信息，请参阅[什么是 Amazon EventBridge 日程安排](https://docs.aws.amazon.com/scheduler/latest/UserGuide/what-is-scheduler.html)？ 在《*EventBridge 日程安排器用户指南》*中。

AWS Serverless Application Model (AWS SAM) 在设置此事件类型时生成[https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html)资源。

## 语法
<a name="sam-property-statemachine-statemachineschedulev2-syntax"></a>

要在 AWS Serverless Application Model (AWS SAM) 模板中声明此实体，请使用以下语法。

### YAML
<a name="sam-property-statemachine-statemachineschedulev2-syntax.yaml"></a>

```
DeadLetterConfig: DeadLetterConfig
[Description](#sam-statemachine-statemachineschedulev2-description): String
[EndDate](#sam-statemachine-statemachineschedulev2-enddate): String
[FlexibleTimeWindow](#sam-statemachine-statemachineschedulev2-flexibletimewindow): FlexibleTimeWindow
[GroupName](#sam-statemachine-statemachineschedulev2-groupname): String
[Input](#sam-statemachine-statemachineschedulev2-input): String
[KmsKeyArn](#sam-statemachine-statemachineschedulev2-kmskeyarn): String
[Name](#sam-statemachine-statemachineschedulev2-name): String
OmitName: Boolean
[PermissionsBoundary](#sam-statemachine-statemachineschedulev2-permissionsboundary): String
[RetryPolicy](#sam-statemachine-statemachineschedulev2-retrypolicy): RetryPolicy
[RoleArn](#sam-statemachine-statemachineschedulev2-rolearn): String
[ScheduleExpression](#sam-statemachine-statemachineschedulev2-scheduleexpression): String
[ScheduleExpressionTimezone](#sam-statemachine-statemachineschedulev2-scheduleexpressiontimezone): String
[StartDate](#sam-statemachine-statemachineschedulev2-startdate): String
[State](#sam-statemachine-statemachineschedulev2-state): String
```

## Properties
<a name="sam-property-statemachine-statemachineschedulev2-properties"></a>

 `DeadLetterConfig`   <a name="sam-statemachine-statemachineschedulev2-deadletterconfig"></a>
配置亚马逊简单队列服务 (Amazon SQS) Simple Queue Service 队列，目标调用失败后 EventBridge 在该队列中发送事件。例如，当向不存在的 Lambda 函数发送事件时，或者没有足够的权限调用 Lambda 函数 EventBridge 时，调用可能会失败。*有关更多信息，请参阅《日[ EventBridge 程安排器用户指南》中的为调度程序配置死信队列](https://docs.aws.amazon.com/scheduler/latest/UserGuide/configuring-schedule-dlq.html)。EventBridge *  
*类型*：[DeadLetterConfig](sam-property-statemachine-statemachinescheduledeadletterconfig.md)  
*必需*：否  
*CloudFormation 兼容性*：此属性类似于`AWS::Scheduler::Schedule``Target`数据类型的`[DeadLetterConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-deadletterconfig)`属性。此属性的 AWS SAM 版本包括其他子属性， AWS SAM 以备您想要创建死信队列时使用。

 `Description`   <a name="sam-statemachine-statemachineschedulev2-description"></a>
计划的描述。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[Description](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-description)`属性。

 `EndDate`   <a name="sam-statemachine-statemachineschedulev2-enddate"></a>
以 UTC 为单位的日期，在此日期之前计划可以调用其目标。根据计划的重复表达式，调用可能会在您指定的 **EndDate** 或之前停止。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[EndDate](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-enddate)`属性。

 `FlexibleTimeWindow`   <a name="sam-statemachine-statemachineschedulev2-flexibletimewindow"></a>
允许配置可以调用计划的窗口。  
*类型*：[FlexibleTimeWindow](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-flexibletimewindow)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[FlexibleTimeWindow](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler.html#cfn-scheduler-schedule-flexibletimewindow)`属性。

 `GroupName`   <a name="sam-statemachine-statemachineschedulev2-groupname"></a>
将与此计划关联的计划组名称。如果未定义，则使用默认组。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[GroupName](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-groupname)`属性。

 `Input`   <a name="sam-statemachine-statemachineschedulev2-input"></a>
传递到目标的有效 JSON 文本。如果使用此属性，则不会将事件文本本身的任何内容传递到目标。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule Target`资源的`[Input](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-input)`属性。

 `KmsKeyArn`   <a name="sam-statemachine-statemachineschedulev2-kmskeyarn"></a>
将用于加密客户数据的 KMS 密钥的 ARN。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[KmsKeyArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-kmskeyarn)`属性。

 `Name`   <a name="sam-statemachine-statemachineschedulev2-name"></a>
计划的名称。如果您未指定名称，则 AWS SAM 会生成格式为的名称，`StateMachine-Logical-IDEvent-Source-Name`并使用该 ID 作为计划名称。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[Name](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-name)`属性。

`OmitName`  <a name="sam-statemachine-statemachineschedulev2-omitname"></a>
默认情况下， AWS SAM 生成并使用格式为的计划名称*<State-machine-logical-ID><event-source-name>*。将此属性设置`true`为 CloudFormation 生成唯一的物理 ID，然后改用该物理 ID 作为计划名称。  
*类型*：布尔值  
*必需*：否  
*默认值*：`false`  
*CloudFormation 兼容性*：此属性是独有的 AWS SAM ，没有 CloudFormation 等效属性。

 `PermissionsBoundary`   <a name="sam-statemachine-statemachineschedulev2-permissionsboundary"></a>
用于为角色设置权限边界的策略的 ARN。  
如果已定义，`PermissionsBoundary`则 AWS SAM 将对计划程序计划的目标 IAM 角色应用相同的边界。
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::IAM::Role`资源的`[PermissionsBoundary](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html#cfn-iam-role-permissionsboundary)`属性。

 `RetryPolicy`   <a name="sam-statemachine-statemachineschedulev2-retrypolicy"></a>
包含有关重试策略设置的信息的 `RetryPolicy` 对象。  
*类型*：[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-retrypolicy)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule``Target`数据类型的`[RetryPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-retrypolicy)`属性。

 `RoleArn`   <a name="sam-statemachine-statemachineschedulev2-rolearn"></a>
调用计划时， EventBridge 计划程序将用于目标的 IAM 角色的 ARN。  
*类型*：[RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule``Target`数据类型的`[RoleArn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-scheduler-schedule-target.html#cfn-scheduler-schedule-target-rolearn)`属性。

 `ScheduleExpression`   <a name="sam-statemachine-statemachineschedulev2-scheduleexpression"></a>
决定运行计划的时间和频率的计划表达式。  
*类型*：字符串  
*是否必需*：是  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[ScheduleExpression](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-scheduleexpression)`属性。

 `ScheduleExpressionTimezone`   <a name="sam-statemachine-statemachineschedulev2-scheduleexpressiontimezone"></a>
评估计划表达式的时区。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[ScheduleExpressionTimezone](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-scheduleexpressiontimezone)`属性。

 `StartDate`   <a name="sam-statemachine-statemachineschedulev2-startdate"></a>
以 UTC 为单位的日期，在此日期之后计划可以调用目标。根据计划的重复表达式，调用可能会在您指定的 **StartDate** 或之后发生。  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[StartDate](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-startdate)`属性。

 `State`   <a name="sam-statemachine-statemachineschedulev2-state"></a>
计划的状态。  
*接受的值：*`DISABLED | ENABLED`  
*类型*：字符串  
*必需*：否  
*CloudFormation 兼容性*：此属性直接传递给`AWS::Scheduler::Schedule`资源的`[State](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-state)`属性。

## 示例
<a name="sam-property-statemachine-statemachineschedulev2--examples"></a>

### 定义 ScheduleV2 资源的基本示例
<a name="sam-property-statemachine-statemachineschedulev2--examples--example1"></a>

```
StateMachine:
  Type: AWS::Serverless::StateMachine
  Properties:
    Name: MyStateMachine
    Events:
      ScheduleEvent:
        Type: ScheduleV2
        Properties:
          ScheduleExpression: "rate(1 minute)"
      ComplexScheduleEvent:
        Type: ScheduleV2
        Properties:
          ScheduleExpression: rate(1 minute)
          FlexibleTimeWindow:
            Mode: FLEXIBLE
            MaximumWindowInMinutes: 5
          StartDate: '2022-12-28T12:00:00.000Z'
          EndDate: '2023-01-28T12:00:00.000Z'
          ScheduleExpressionTimezone: UTC
          RetryPolicy:
            MaximumRetryAttempts: 5
            MaximumEventAgeInSeconds: 300
          DeadLetterConfig:
            Type: SQS
    DefinitionUri:
      Bucket: sam-sam-s3-demo-bucket
      Key: my-state-machine.asl.json
      Version: 3
    Policies:
      - LambdaInvokePolicy:
          FunctionName: !Ref MyFunction
```

# 生成的 CloudFormation 资源用于 AWS SAM
<a name="sam-specification-generated-resources"></a>

本节详细介绍了在 AWS SAM 处理 AWS 模板时创建的 CloudFormation 资源。根据您指定的方案， AWS SAM 生成的 CloudFormation 资源集会有所不同。*场景*是在模板文件中指定的 AWS SAM 资源和属性的组合。您可以在模板文件中的其他位置引用生成的 CloudFormation 资源，类似于引用在模板文件中明确声明的资源。

例如，如果您在 AWS SAM 模板文件中指定了 `AWS::Serverless::Function` 资源，则 AWS SAM 总是会生成 `AWS::Lambda::Function` 基本资源。如果您还指定了可选`AutoPublishAlias`属性，则 AWS SAM 还会生成`AWS::Lambda::Alias`和`AWS::Lambda::Version`资源。

本节列出了场景及其生成的 CloudFormation 资源，并说明如何在 AWS SAM 模板文件中引用生成的 CloudFormation 资源。

## 引用生成的资源 CloudFormation
<a name="sam-specification-generated-resources-referencing"></a>

您可以通过`LogicalId`或按可引用属性在 AWS SAM 模板文件中引用生成的 CloudFormation 资源。

### 通过以下方式引用生成的 CloudFormation 资源 LogicalId
<a name="sam-specification-generated-resources-referencing-logicalid"></a>

 AWS SAM 生成每个 CloudFormation 资源的资源都有一个字母数字（A-Z `[LogicalId](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html#resources-section-structure-logicalid)`、a-z、0-9）标识符，在模板文件中是唯一的。 AWS SAM 使用模板文件`LogicalIds`中的 AWS SAM 资源来构造它生成的 CloudFormation 资源。`LogicalIds`您可以使用生成的 CloudFormation 资源在`LogicalId`模板文件中访问该资源的属性，就像访问已明确声明的 CloudFormation 资源一样。有关 CloudFormation 和 AWS SAM 模板`LogicalIds`的更多信息，请参阅《*AWS CloudFormation 用户指南*》中的[资源](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html)。

**注意**  
某些生成的资源的 `LogicalIds` 包含唯一哈希值，以避免命名空间冲突。这些资源的 `LogicalIds` 是在创建堆栈时派生的。只有在创建堆栈之后，您才能使用 AWS 管理控制台 AWS CLI、或其中一个来检索它们 AWS SDKs。我们不建议通过 `LogicalId` 引用这些资源，因为哈希值可能会发生变化。

### 通过可引用属性引用生成的 CloudFormation 资源
<a name="sam-specification-generated-resources-referencing-referenceable-property"></a>

对于某些生成的资源， AWS SAM 提供该资源的可引用属性。 AWS SAM 您可以使用此属性在 AWS SAM 模板文件中引用生成的 CloudFormation 资源及其属性。

**注意**  
并非所有生成的 CloudFormation 资源都具有可引用的属性。对于这些资源，必须使用 `LogicalId`。

## 生成的 CloudFormation 资源场景
<a name="sam-specification-generated-resources-scenarios"></a>

下表汇总了构成生成 AWS SAM 资源的场景的 CloudFormation 资源和属性。**场景**列中的主题提供了有关为该场景 AWS SAM 生成的其他 CloudFormation 资源的详细信息。


| AWS SAM 资源 | 基础 CloudFormation 资源 | 场景 | 
| --- | --- | --- | 
| AWS::Serverless::Api  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html) |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::Application  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-stack.html) |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::CapacityProvider  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-capacityprovider.html) |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::Function | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html) |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::HttpApi | [AWS::ApiGatewayV2::Api](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.html) |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::LayerVersion  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html) |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::SimpleTable  | [AWS::DynamoDB::Table](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html) |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 
| AWS::Serverless::StateMachine  | [https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-stepfunctions-statemachine.html) |  [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_cn/serverless-application-model/latest/developerguide/sam-specification-generated-resources.html)  | 

**Topics**
+ [引用生成的资源 CloudFormation](#sam-specification-generated-resources-referencing)
+ [生成的 CloudFormation 资源场景](#sam-specification-generated-resources-scenarios)
+ [CloudFormation 指定时AWS::Serverless::Api生成的资源](sam-specification-generated-resources-api.md)
+ [CloudFormation 指定时AWS::Serverless::Application生成的资源](sam-specification-generated-resources-application.md)
+ [CloudFormation 指定时AWS::Serverless::CapacityProvider生成的资源](sam-specification-generated-resources-capacityprovider.md)
+ [CloudFormation 指定时生成的资源 AWS::Serverless::Connector](sam-specification-generated-resources-connector.md)
+ [CloudFormation 指定时AWS::Serverless::Function生成的资源](sam-specification-generated-resources-function.md)
+ [CloudFormation 指定时AWS::Serverless::GraphQLApi生成的资源](sam-specification-generated-resources-graphqlapi.md)
+ [CloudFormation 指定时 AWS::Serverless::HttpApi 生成的资源](sam-specification-generated-resources-httpapi.md)
+ [CloudFormation 指定时AWS::Serverless::LayerVersion生成的资源](sam-specification-generated-resources-layerversion.md)
+ [CloudFormation 指定时AWS::Serverless::SimpleTable生成的资源](sam-specification-generated-resources-simpletable.md)
+ [CloudFormation 指定时AWS::Serverless::StateMachine生成的资源](sam-specification-generated-resources-statemachine.md)

# CloudFormation 指定时AWS::Serverless::Api生成的资源
<a name="sam-specification-generated-resources-api"></a>

指定`AWS::Serverless::Api`时， AWS Serverless Application Model (AWS SAM) 始终生成`AWS::ApiGateway::RestApi`基础 CloudFormation 资源。此外，它还总是生成 `AWS::ApiGateway::Stage` 和 `AWS::ApiGateway::Deployment` 资源。

**`AWS::ApiGateway::RestApi`**  
*`LogicalId`: *`<api‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::ApiGateway::Stage`**  
*`LogicalId`: *`<api‑LogicalId><stage‑name>Stage`  
`<stage‑name>` 是 `StageName` 属性将被设置为的字符串。例如，您将 `StageName` 设置为 `Gamma`，`LogicalId` 是 `MyRestApiGammaStage`。  
*可引用属性：*`<api‑LogicalId>.Stage`

**`AWS::ApiGateway::Deployment`**  
*`LogicalId`: *`<api‑LogicalId>Deployment<sha>`  
`<sha>` 是在创建堆栈时生成的唯一哈希值。例如 `MyRestApiDeployment926eeb5ff1`。  
*可引用属性：*`<api‑LogicalId>.Deployment`

除了这些 CloudFormation 资源之外，如果`AWS::Serverless::Api`指定了这些资源，还会为以下场景 AWS SAM 生成其他 CloudFormation 资源。

**Topics**
+ [DomainName 属性已指定](#sam-specification-generated-resources-api-domain-name)
+ [UsagePlan 属性已指定](#sam-specification-generated-resources-api-usage-plan)

## DomainName 属性已指定
<a name="sam-specification-generated-resources-api-domain-name"></a>

当指定了`Domain`属性的属性`AWS::Serverless::Api`时， AWS SAM 会生成`AWS::ApiGateway::DomainName` CloudFormation 资源。`DomainName`

**`AWS::ApiGateway::DomainName`**  
*`LogicalId`: *`ApiGatewayDomainName<sha>`  
`<sha>` 是在创建堆栈时生成的唯一哈希值。例如：`ApiGatewayDomainName926eeb5ff1`。  
*可引用属性：*`<api‑LogicalId>.DomainName`

## UsagePlan 属性已指定
<a name="sam-specification-generated-resources-api-usage-plan"></a>

指定`UsagePlan`属性的`Auth`属性后， AWS SAM 会生成以下 CloudFormation 资源：`AWS::ApiGateway::UsagePlan``AWS::ApiGateway::UsagePlanKey`、和`AWS::ApiGateway::ApiKey`。`AWS::Serverless::Api`

**`AWS::ApiGateway::UsagePlan`**  
*`LogicalId`: *`<api‑LogicalId>UsagePlan`  
*可引用属性：*`<api‑LogicalId>.UsagePlan`

**`AWS::ApiGateway::UsagePlanKey`**  
*`LogicalId`: *`<api‑LogicalId>UsagePlanKey`  
*可引用属性：*`<api‑LogicalId>.UsagePlanKey`

**`AWS::ApiGateway::ApiKey`**  
*`LogicalId`: *`<api‑LogicalId>ApiKey`  
*可引用属性：*`<api‑LogicalId>.ApiKey`

# CloudFormation 指定时AWS::Serverless::Application生成的资源
<a name="sam-specification-generated-resources-application"></a>

当指定`AWS::Serverless::Application`时， AWS Serverless Application Model (AWS SAM) 会生成`AWS::CloudFormation::Stack`基础 CloudFormation 资源。

**`AWS::CloudFormation::Stack`**  
*`LogicalId`: *`<application‑LogicalId>`   
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

# CloudFormation 指定时AWS::Serverless::CapacityProvider生成的资源
<a name="sam-specification-generated-resources-capacityprovider"></a>

如果指定了 `AWS::Serverless::CapacityProvider`， AWS Serverless Application Model (AWS SAM) 会生成 `AWS::Lambda::CapacityProvider` 基本 CloudFormation 资源。

**`AWS::Lambda::CapacityProvider`**  
*`LogicalId`: *`<capacityprovider‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

除此 CloudFormation 资源外，如果指定了`AWS::Serverless::CapacityProvider`此资源， AWS SAM 还会生成用于以下场景的 CloudFormation 资源：

**Topics**
+ [OperatorRole 未指定属性](#sam-specification-generated-resources-capacityprovider-iam-role)

## OperatorRole 未指定属性
<a name="sam-specification-generated-resources-capacityprovider-iam-role"></a>

*未*指定`OperatorRole`属性时， AWS SAM 会生成附加`AWSLambdaManagedEC2ResourceOperator`托管策略的`AWS::IAM::Role` CloudFormation 资源。`AWS::Serverless::CapacityProvider`

**`AWS::IAM::Role`**  
*`LogicalId`: *`<capacityprovider‑LogicalId>OperatorRole`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

# CloudFormation 指定时生成的资源 AWS::Serverless::Connector
<a name="sam-specification-generated-resources-connector"></a>

**注意**  
如果通过嵌入式 `Connectors` 属性定义连接器，在生成这些资源之前，会先转换为 `AWS::Serverless::Connector` 资源。

在 AWS SAM 模板中指定`AWS::Serverless::Connector`资源时， AWS SAM 会根据需要生成以下 AWS CloudFormation 资源。

**`AWS::IAM::ManagedPolicy`**  
 *`LogicalId`:*`<connector‑LogicalId>Policy`   
 *可引用属性：* N/A （要引用此 CloudFormation 资源，必须使用。）`LogicalId` 

**`AWS::SNS::TopicPolicy`**  
 *`LogicalId`:*`<connector‑LogicalId>TopicPolicy`   
 *可引用属性：* N/A （要引用此 CloudFormation 资源，必须使用。）`LogicalId` 

**`AWS::SQS::QueuePolicy`**  
 *`LogicalId`:*`<connector‑LogicalId>QueuePolicy`   
 *可引用属性：* N/A （要引用此 CloudFormation 资源，必须使用。）`LogicalId` 

**`AWS::Lambda::Permission`**  
 *`LogicalId`:*`<connector‑LogicalId><permission>LambdaPermission`   
 `<permission>` 是 `Permissions` 属性指定的权限。例如 `Write`。  
*可引用属性：* N/A （要引用此 CloudFormation 资源，必须使用。）`LogicalId` 

# CloudFormation 指定时AWS::Serverless::Function生成的资源
<a name="sam-specification-generated-resources-function"></a>

指定`AWS::Serverless::Function`时， AWS Serverless Application Model (AWS SAM) 始终会创建`AWS::Lambda::Function`基础 CloudFormation 资源。

**`AWS::Lambda::Function`**  
*`LogicalId`: *`<function‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

除此 CloudFormation 资源外，如果指定了`AWS::Serverless::Function`此资源， AWS SAM 还会生成用于以下场景的 CloudFormation 资源。

**Topics**
+ [核心函数属性](#sam-specification-generated-resources-function-core-properties)
+ [事件源](#sam-specification-generated-resources-function-event-sources)
+ [事件配置](#sam-specification-generated-resources-function-event-configuration)

## 核心函数属性
<a name="sam-specification-generated-resources-function-core-properties"></a>

以下场景基于核心功能属性生成 CloudFormation 资源：

### 未指定 Role 属性
<a name="sam-specification-generated-resources-function-not-role"></a>

如果*未*指定 a `AWS::Serverless::Function` 的`Role`属性，则 AWS SAM 会生成`AWS::IAM::Role` CloudFormation 资源。

**`AWS::IAM::Role`**  
*`LogicalId`: *`<function‑LogicalId>Role`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

### AutoPublishAlias 属性已指定
<a name="sam-specification-generated-resources-function-autopublishalias"></a>

当指定了的`AutoPublishAlias`属性`AWS::Serverless::Function`时， AWS SAM 会生成以下 CloudFormation 资源：`AWS::Lambda::Alias`和`AWS::Lambda::Version`。

**`AWS::Lambda::Alias`**  
*`LogicalId`: *`<function‑LogicalId>Alias<alias‑name>`  
`<alias‑name>` 是 `AutoPublishAlias` 将被设置为的字符串。例如，如果设置为 `AutoPublishAlias``live`，则`LogicalId`为：*MyFunction*别名*live*。  
*可引用属性：*`<function‑LogicalId>.Alias`

**`AWS::Lambda::Version`**  
*`LogicalId`: *`<function‑LogicalId>Version<sha>`  
`<sha>` 是在创建堆栈时生成的唯一哈希值。例如，*MyFunction*版本*926eeb5ff1*。  
*可引用属性：*`<function‑LogicalId>.Version`

有关该`AutoPublishAlias`属性的更多信息，请参阅的 “[属性” 部分 AWS::Serverless::Function](sam-resource-function.md#sam-resource-function-properties)。

### DeploymentPreference 属性已指定
<a name="sam-specification-generated-resources-function-deploymentpreference"></a>

当指定了的`DeploymentPreference`属性`AWS::Serverless::Function`时， AWS SAM 会生成以下资源 CloudFormation 资源：`AWS::CodeDeploy::Application`和`AWS::CodeDeploy::DeploymentGroup`。此外，如果*未*指定`DeploymentPreference`对象的`Role`属性， AWS SAM 还会生成`AWS::IAM::Role` CloudFormation 资源。

**`AWS::CodeDeploy::Application`**  
*`LogicalId`: *`ServerlessDeploymentApplication`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::CodeDeploy::DeploymentGroup`**  
*`LogicalId`: *`<function‑LogicalId>DeploymentGroup`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::IAM::Role`**  
*`LogicalId`: *`CodeDeployServiceRole`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

### FunctionUrlConfig 属性已指定
<a name="sam-specification-generated-resources-function-functionurlconfig"></a>

指定`FunctionUrlConfig`属性后， AWS SAM 会根据生成不同的 CloudFormation 资源`AuthType`。

指定`AuthType: NONE`后，将 AWS SAM 生成以下 CloudFormation 资源：

**`AWS::Lambda::Permission`（调用访问权限）**  
*`LogicalId`: *`<function‑LogicalId>URLInvokeAllowPublicAccess`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::Lambda::Permission`（公有访问权限）**  
*`LogicalId`: *`<function‑LogicalId>UrlPublicPermissions`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::Lambda::Url`**  
*`LogicalId`: *`<function‑LogicalId>Url`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

指定`AuthType: AWS_IAM`时，仅 AWS SAM 生成：

**`AWS::Lambda::Url`**  
*`LogicalId`: *`<function‑LogicalId>Url`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

有关该`FunctionUrlConfig`属性的更多信息，请参阅[FunctionUrlConfig](sam-property-function-functionurlconfig.md)。

## 事件源
<a name="sam-specification-generated-resources-function-event-sources"></a>

以下场景基于事件源生成 CloudFormation 资源：

### 指定了 Api 事件源
<a name="sam-specification-generated-resources-function-api"></a>

如果的`Event`属性设置`AWS::Serverless::Function`为`Api`，但*未*指定该`RestApiId`属性，则 AWS SAM 生成`AWS::ApiGateway::RestApi` CloudFormation 资源。

**`AWS::ApiGateway::RestApi`**  
*`LogicalId`: *`ServerlessRestApi`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

### 已指定 HttpApi 事件源
<a name="sam-specification-generated-resources-function-httpapi"></a>

如果的`Event`属性设置`AWS::Serverless::Function`为`HttpApi`，但*未*指定该`ApiId`属性，则 AWS SAM 生成`AWS::ApiGatewayV2::Api` CloudFormation 资源。

**`AWS::ApiGatewayV2::Api`**  
*`LogicalId`: *`ServerlessHttpApi`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

### 指定了流式事件源
<a name="sam-specification-generated-resources-function-streaming"></a>

将的`Event`属性设置`AWS::Serverless::Function`为其中一种流媒体类型时， AWS SAM 会生成`AWS::Lambda::EventSourceMapping` CloudFormation 资源。这适用于以下类型：`DynamoDB`、`Kinesis`、`MQ`、`MSK` 和 `SQS`。

**`AWS::Lambda::EventSourceMapping`**  
*`LogicalId`: *`<function‑LogicalId><event‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

### 指定了事件桥（或事件总线）事件源
<a name="sam-specification-generated-resources-function-eventbridge"></a>

将的`Event`属性设置`AWS::Serverless::Function`为事件桥（或事件总线）类型之一时， AWS SAM 会生成`AWS::Events::Rule` CloudFormation 资源。这适用于以下类型：`EventBridgeRule`、`Schedule` 和 `CloudWatchEvents`。

**`AWS::Events::Rule`**  
*`LogicalId`: *`<function‑LogicalId><event‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

### 已指定 IotRule 事件源
<a name="sam-specification-generated-resources-function-iotrule"></a>

当的`Event`属性设置`AWS::Serverless::Function`为 Io 时TRule， AWS SAM 会生成`AWS::IoT::TopicRule` CloudFormation 资源。

**`AWS::IoT::TopicRule`**  
*`LogicalId`: *`<function‑LogicalId><event‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

## 事件配置
<a name="sam-specification-generated-resources-function-event-configuration"></a>

以下方案根据事件配置生成 CloudFormation 资源：

### OnSuccess （或 OnFailure）属性是为亚马逊 SNS 事件指定的
<a name="sam-specification-generated-resources-function-sns-onsuccess"></a>

如果指定了属性的属性`AWS::Serverless::Function`的`OnSuccess`（或`OnFailure`）`EventInvokeConfig`属性，且目标类型为，`SNS`但*未*指定目标 ARN，则 AWS SAM 生成以下 CloudFormation 资源：`AWS::Lambda::EventInvokeConfig`和。`DestinationConfig` `AWS::SNS::Topic`

**`AWS::Lambda::EventInvokeConfig`**  
*`LogicalId`: *`<function‑LogicalId>EventInvokeConfig`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::SNS::Topic`**  
*`LogicalId`: *`<function‑LogicalId>OnSuccessTopic`（或 `<function‑LogicalId>OnFailureTopic`）  
*可引用属性：*`<function‑LogicalId>.DestinationTopic`  
如果为 Amazon SNS 事件指定了 `OnSuccess` 和 `OnFailure`，为了区分生成的资源，必须使用 `LogicalId`。

### OnSuccess （或 OnFailure）属性是为亚马逊 SQS 事件指定的
<a name="sam-specification-generated-resources-function-sqs-onsuccess"></a>

如果指定了属性的属性`AWS::Serverless::Function`的`OnSuccess`（或`OnFailure`）`EventInvokeConfig`属性，且目标类型为，`SQS`但*未*指定目标 ARN，则 AWS SAM 生成以下 CloudFormation 资源：`AWS::Lambda::EventInvokeConfig`和。`DestinationConfig` `AWS::SQS::Queue`

**`AWS::Lambda::EventInvokeConfig`**  
*`LogicalId`: *`<function‑LogicalId>EventInvokeConfig`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::SQS::Queue`**  
*`LogicalId`: *`<function‑LogicalId>OnSuccessQueue`（或 `<function‑LogicalId>OnFailureQueue`）  
*可引用属性：*`<function‑LogicalId>.DestinationQueue`  
如果为 Amazon SQS 事件指定了 `OnSuccess` 和 `OnFailure`，为了区分生成的资源，必须使用 `LogicalId`。

# CloudFormation 指定时AWS::Serverless::GraphQLApi生成的资源
<a name="sam-specification-generated-resources-graphqlapi"></a>

在 AWS Serverless Application Model (AWS SAM) 模板中指定`AWS::Serverless::GraphQLApi`资源时， AWS SAM 始终会创建以下基础 AWS CloudFormation 资源。

**`AWS::AppSync::DataSource`**  
*`LogicalId`: *`<graphqlapi-LogicalId><datasource-RelativeId><datasource-Type>DataSource`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::AppSync::FunctionConfiguration`**  
*`LogicalId`: *`<graphqlapi-LogicalId><function-RelativeId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::AppSync::GraphQLApi`**  
*`LogicalId`: *`<graphqlapi-LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::AppSync::GraphQLSchema`**  
*`LogicalId`: *`<graphqlapi-LogicalId>Schema`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

**`AWS::AppSync::Resolver`**  
*`LogicalId`: *`<graphqlapi-LogicalId><OperationType><resolver-RelativeId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

除了这些 CloudFormation 资源之外，`AWS::Serverless::GraphQLApi`如果指定了这些资源，还 AWS SAM 可能生成以下 CloudFormation 资源。

`AWS::AppSync::ApiCache`  
*`LogicalId`: *`<graphqlapi-LogicalId>ApiCache`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

`AWS::AppSync::ApiKey`  
*`LogicalId`: *`<graphqlapi-LogicalId><apikey-RelativeId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

`AWS::AppSync::DomainName`  
*`LogicalId`: *`<graphqlapi-LogicalId>DomainName`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

`AWS::AppSync::DomainNameApiAssociation`  
*`LogicalId`: *`<graphqlapi-LogicalId>DomainNameApiAssociation`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

AWS SAM 也可以使用该`AWS::Serverless::Connector`资源来配置权限。有关更多信息，请参阅 [CloudFormation 指定时生成的资源 AWS::Serverless::Connector](sam-specification-generated-resources-connector.md)。

# CloudFormation 指定时 AWS::Serverless::HttpApi 生成的资源
<a name="sam-specification-generated-resources-httpapi"></a>

当指定`AWS::Serverless::HttpApi`时， AWS Serverless Application Model (AWS SAM) 会生成`AWS::ApiGatewayV2::Api`基础 CloudFormation 资源。

**`AWS::ApiGatewayV2::Api`**  
*`LogicalId`: *`<httpapi‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

除此 CloudFormation 资源外，如果指定了`AWS::Serverless::HttpApi`此资源， AWS SAM 还会生成用于以下场景的 CloudFormation 资源：

**Topics**
+ [StageName 属性已指定](#sam-specification-generated-resources-httpapi-stage-name)
+ [StageName *未*指定属性](#sam-specification-generated-resources-httpapi-not-stage-name)
+ [DomainName 属性已指定](#sam-specification-generated-resources-httpapi-domain-name)

## StageName 属性已指定
<a name="sam-specification-generated-resources-httpapi-stage-name"></a>

当指定了的`StageName`属性`AWS::Serverless::HttpApi`时， AWS SAM 会生成`AWS::ApiGatewayV2::Stage` CloudFormation 资源。

**`AWS::ApiGatewayV2::Stage`**  
*`LogicalId`: *`<httpapi‑LogicalId><stage‑name>Stage`  
`<stage‑name>` 是 `StageName` 属性将被设置为的字符串。例如，如果设置为 `StageName``Gamma`，则`LogicalId`为：*MyHttpApiGamma*舞台。  
*可引用属性：*`<httpapi‑LogicalId>.Stage`

## StageName *未*指定属性
<a name="sam-specification-generated-resources-httpapi-not-stage-name"></a>

如果*未*指定 a `AWS::Serverless::HttpApi` 的`StageName`属性，则 AWS SAM 生成`AWS::ApiGatewayV2::Stage` CloudFormation 资源。

**`AWS::ApiGatewayV2::Stage`**  
*`LogicalId`: *`<httpapi‑LogicalId>ApiGatewayDefaultStage`  
*可引用属性：*`<httpapi‑LogicalId>.Stage`

## DomainName 属性已指定
<a name="sam-specification-generated-resources-httpapi-domain-name"></a>

当指定了`Domain`属性的属性`AWS::Serverless::HttpApi`时， AWS SAM 会生成`AWS::ApiGatewayV2::DomainName` CloudFormation 资源。`DomainName`

**`AWS::ApiGatewayV2::DomainName`**  
*`LogicalId`: *`ApiGatewayDomainNameV2<sha>`  
`<sha>` 是在创建堆栈时生成的唯一哈希值。例如 `ApiGatewayDomainNameV2`*926eeb5ff1*。  
*可引用属性：*`<httpapi‑LogicalId>.DomainName`

# CloudFormation 指定时AWS::Serverless::LayerVersion生成的资源
<a name="sam-specification-generated-resources-layerversion"></a>

当指定`AWS::Serverless::LayerVersion`时， AWS Serverless Application Model (AWS SAM) 会生成`AWS::Lambda::LayerVersion`基础 CloudFormation 资源。

**`AWS::Lambda::LayerVersion`**  
*`LogicalId`: *`<layerversion‑LogicalId>`   
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

# CloudFormation 指定时AWS::Serverless::SimpleTable生成的资源
<a name="sam-specification-generated-resources-simpletable"></a>

当指定`AWS::Serverless::SimpleTable`时， AWS Serverless Application Model (AWS SAM) 会生成`AWS::DynamoDB::Table`基础 CloudFormation 资源。

**`AWS::DynamoDB::Table`**  
*`LogicalId`: *`<simpletable‑LogicalId>`   
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

# CloudFormation 指定时AWS::Serverless::StateMachine生成的资源
<a name="sam-specification-generated-resources-statemachine"></a>

如果指定了 `AWS::Serverless::StateMachine`， AWS Serverless Application Model (AWS SAM) 会生成 `AWS::StepFunctions::StateMachine` 基本 CloudFormation 资源。

**`AWS::StepFunctions::StateMachine`**  
*`LogicalId`: *`<statemachine‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

除此 CloudFormation 资源外，如果指定了`AWS::Serverless::StateMachine`此资源， AWS SAM 还会生成用于以下场景的 CloudFormation 资源：

**Topics**
+ [未指定 Role 属性](#sam-specification-generated-resources-statemachine-not-role)
+ [指定了 API 事件源](#sam-specification-generated-resources-statemachine-api)
+ [指定了事件桥（或事件总线）事件源](#sam-specification-generated-resources-statemachine-eventbridge)

## 未指定 Role 属性
<a name="sam-specification-generated-resources-statemachine-not-role"></a>

如果*未*指定 a `AWS::Serverless::StateMachine` 的`Role`属性，则 AWS SAM 会生成`AWS::IAM::Role` CloudFormation 资源。

**`AWS::IAM::Role`**  
*`LogicalId`: *`<statemachine‑LogicalId>Role`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

## 指定了 API 事件源
<a name="sam-specification-generated-resources-statemachine-api"></a>

如果的`Event`属性设置`AWS::Serverless::StateMachine`为`Api`，但*未*指定该`RestApiId`属性，则 AWS SAM 生成`AWS::ApiGateway::RestApi` CloudFormation 资源。

**`AWS::ApiGateway::RestApi`**  
*`LogicalId`: *`ServerlessRestApi`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

## 指定了事件桥（或事件总线）事件源
<a name="sam-specification-generated-resources-statemachine-eventbridge"></a>

将的`Event`属性设置`AWS::Serverless::StateMachine`为事件桥（或事件总线）类型之一时， AWS SAM 会生成`AWS::Events::Rule` CloudFormation 资源。这适用于以下类型：`EventBridgeRule`、`Schedule` 和 `CloudWatchEvents`。

**`AWS::Events::Rule`**  
*`LogicalId`: *`<statemachine‑LogicalId><event‑LogicalId>`  
*可引用的属性：*N/A（必须使用`LogicalId`来引用此 CloudFormation 资源）

# 支持的资源属性 AWS SAM
<a name="sam-specification-resource-attributes"></a>

资源属性是您可以添加的属 AWS SAM 性和用于控制其他行为和关系的 CloudFormation 资源。有关资源属性的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的[资源属性引用](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-product-attribute-reference.html)。

AWS SAM 支持由定义的资源属性的子集 CloudFormation。在支持的资源属性中，有些属性仅复制到相应 CloudFormation 资源的基础生成的 AWS SAM 资源中，有些则复制到由相应 CloudFormation 资源生成的所有生成的 AWS SAM 资源中。有关从相应 CloudFormation 资源生成的 AWS SAM 资源的更多信息，请参阅[生成的 CloudFormation 资源用于 AWS SAM](sam-specification-generated-resources.md)。

下表汇总了按 AWS SAM以下所[异常](#sam-specification-resource-attributes-exceptions)列内容提供的资源属性支持。


| 资源属性 | 目标生成的资源 | 
| --- | --- | 
|  ** [DependsOn](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html) ** **[元数据](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-metadata.html) **1, 2  |  仅限基础 CloudFormation 生成的资源。有关 AWS SAM 资源和基础 CloudFormation 资源之间映射的信息，请参阅[生成的 CloudFormation 资源场景](sam-specification-generated-resources.md#sam-specification-generated-resources-scenarios)。  | 
| ** [Condition](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-section-structure.html) ** ** [DeletionPolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-deletionpolicy.html) ** ** [UpdateReplacePolicy](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-updatereplacepolicy.html) **  |  所有从相应 CloudFormation 资源生成的 AWS SAM 资源。有关生成 CloudFormation 资源的场景的信息，请参阅[生成的 CloudFormation 资源场景](sam-specification-generated-resources.md#sam-specification-generated-resources-scenarios)。  | 

**备注**：

1. 有关使用 `Metadata` 资源属性和 `AWS::Serverless::Function` 资源类型的更多信息，请参阅 [在中使用自定义运行时构建 Lambda 函数 AWS SAM](building-custom-runtimes.md)。

1. 有关使用 `Metadata` 资源属性和 `AWS::Serverless::LayerVersion` 资源类型的更多信息，请参阅 [在中构建 Lambda 图层 AWS SAM](building-layers.md)。

## 异常
<a name="sam-specification-resource-attributes-exceptions"></a>

前面描述的资源属性规则有许多例外情况：
+ 对于`AWS::Lambda::LayerVersion`， AWS SAM仅限自定义字段`DeletionPolicy`为生成的 CloudFormation 资源`RetentionPolicy`设置。它的优先级高于 `DeletionPolicy` 其本身。如果两者均未设置，则默认将 `DeletionPolicy` 设置为 `Retain`。
+ 对于 `AWS::Lambda::Version`，如果未指定 `DeletionPolicy`，则默认为 `Retain`。
+ 对于为无服务器函数指定的场`DeploymentPreferences`景，资源属性不会复制到以下生成的 CloudFormation 资源中：
  + `AWS::CodeDeploy::Application`
  + `AWS::CodeDeploy::DeploymentGroup`
  + 为此场景创建的名为 `CodeDeployServiceRole` 的 `AWS::IAM::Role`
+ 如果您的 AWS SAM 模板包含多个带有隐式创建的 API 事件源的函数，则这些函数将共享生成的`AWS::ApiGateway::RestApi`资源。在这种情况下，如果函数具有不同的资源属性，则对于生成的`AWS::ApiGateway::RestApi`资源，根据以下优先级列表 AWS SAM 复制资源属性：
  + `UpdateReplacePolicy`:

    1. `Retain`

    1. `Snapshot`

    1. `Delete`
  + `DeletionPolicy`:

    1. `Retain`

    1. `Delete`

# 适用于 API Gateway 的扩展 AWS SAM
<a name="sam-specification-api-gateway-extensions"></a>

专为设计的 API Gateway 扩展提供了用于设计和管理 APIs的额外自定义和功能。 AWS API Gateway 扩展是 OpenAPI 规范的扩展，它支持 AWS特定授权和特定于 API 网关的 API 集成。有关 API Gateway 扩展的更多信息，请参阅[基于 OpenAPI 的 API Gateway 扩展](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html)。

AWS SAM 支持 API Gateway 扩展的子集。要查看支持哪些 API Gateway 扩展 AWS SAM，请参阅下表。


|  |  | 
| --- |--- |
|  API Gateway 扩展  |  由... 支持 AWS SAM  | 
| [x-amazon-apigateway-any-method对象](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-any-method.html) | 是 | 
| [x-amazon-apigateway-api-key-source 属性](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-api-key-source.html) | 否 | 
| [x-amazon-apigateway-auth Object](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-auth.html) | 是 | 
| [x-amazon-apigateway-authorizer Object](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authorizer.html) | 是 | 
| [x-amazon-apigateway-authtype 属性](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-authtype.html) | 是 | 
| [x-amazon-apigateway-binary-媒体类型属性](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-binary-media-types.html) | 是 | 
| [x-amazon-apigateway-documentation Object](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-documentation.html) | 否 | 
| [x-amazon-apigateway-endpoint-配置对象](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-endpoint-configuration.html) | 否 | 
| [x-amazon-apigateway-gateway-响应对象](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.html) | 是 | 
| [x-amazon-apigateway-gateway-responses.gatewayRespon](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.gatewayResponse.html) | 是 | 
| [x-amazon-apigateway-gateway-responses.responseparameter](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.responseParameters.html) | 是 | 
| [x-amazon-apigateway-gateway-responses.responseTemp](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-gateway-responses.responseTemplates.html) | 是 | 
| [x-amazon-apigateway-integration Object](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration.html) | 是 | 
| [x-amazon-apigateway-integration.requestTemp](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration-requestTemplates.html) | 是 | 
| [x-amazon-apigateway-integration. 请求参数对象](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration-requestParameters.html) | 否 | 
| [x-amazon-apigateway-integration. 响应对象](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration-responses.html) | 是 | 
| [x-amazon-apigateway-integration.response](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration-response.html) | 是 | 
| [x-amazon-apigateway-integration.responseTempl](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration-responseTemplates.html) | 是 | 
| [x-amazon-apigateway-integration.responseparameters](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-integration-responseParameters.html) | 是 | 
| [x-amazon-apigateway-request-验证器属性](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-request-validator.html) | 否 | 
| [x-amazon-apigateway-request-验证器对象](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-request-validators.html) | 否 | 
| [x-amazon-apigateway-request-validators.requestValidator 对象](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions-request-validators.requestValidator.html) | 否 | 

# 的内在函数 AWS SAM
<a name="sam-specification-intrinsic-functions"></a>

内部函数是内置函数，允许您为仅在运行时可用的属性赋值。 AWS SAM 对某些内部函数属性的支持有限，因此它无法解析某些内部函数。因此，建议添加 `AWS::LanguageExtensions` 转换来解决此问题。是由托管的宏 CloudFormation ，允许您使用默认情况下不包含的内部函数和其他功能。`AWS::LanguageExtensions` CloudFormation

```
Transform:
  - AWS::LanguageExtensions
  - AWS::Serverless-2016-10-31
```

**注意**  
如果你在 CodeUri 属性中使用内部函数， AWS SAM 将无法正确解析这些值。考虑改用 `AWS::LanguageExtensions` 转换。  
有关更多信息，请参阅的 [“属性” 部分 AWS::Serverless::Function](sam-resource-function.md#sam-resource-function-properties)。

有关内置函数的更多信息，请参阅*《AWS CloudFormation 用户指南》*中的[内置函数参考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html)。