

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

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