

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

# 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
```