

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

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

指定要啟用逐步 Lambda 部署的組態。如需設定逐步 Lambda 部署的詳細資訊，請參閱 [使用 逐步部署無伺服器應用程式 AWS SAM](automating-updates-to-serverless-apps.md)。

**注意**  
您必須在 `AutoPublishAlias`中指定 [AWS::Serverless::Function](sam-resource-function.md)以使用`DeploymentPreference`物件，否則會產生錯誤。

## 語法
<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，且啟用此部署偏好設定，則函數的條件會傳遞至產生的 CodeDeploy 資源。一般而言，您應該將此設定為 True。否則，即使函數的條件解析為 False，也會建立 CodeDeploy 資源。  
*類型*：布林值  
*必要*：否  
*CloudFormation 相容性*：此屬性對 是唯一的 AWS SAM ，並且沒有 CloudFormation 同等屬性。

 `Role`   <a name="sam-function-deploymentpreference-role"></a>
CodeDeploy 將用於流量轉移的 IAM 角色 ARN。如果提供此功能，則不會建立 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>
目前有兩種部署類型：線性和 Canary。如需可用部署類型的詳細資訊，請參閱 [使用 逐步部署無伺服器應用程式 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
```

### 具有 Fn：：If 內部函數的 DeploymentPreference
<a name="sam-property-function-deploymentpreference--examples--deploymentpreference-with-fn::if-intrinsic-function"></a>

`Fn::If` 用於設定警示的範例部署偏好設定。在此範例中，如果 `MyCondition`是 ，`Alarm1`則會設定 `true`，如果 `MyCondition`是 ，`Alarm2``Alarm5`則會設定 `false`。

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