

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

# 故障診斷 AWS CloudFormation Guard
<a name="troubleshooting"></a>

如果您在使用 時遇到問題 AWS CloudFormation Guard，請參閱本節中的主題。

**Topics**
+ [當沒有所選類型的資源時，子句失敗](#troubleshooting-when-conditions-filters)
+ [Guard 不會評估具有短格式 Fn::GetAtt 參考的 CloudFormation 範本](#troubleshooting-cfn-intrinsic-functions)
+ [一般疑難排解主題](#troubleshooting-general)

## 當沒有所選類型的資源時，子句失敗
<a name="troubleshooting-when-conditions-filters"></a>

當查詢使用類似 的篩選條件時`Resources.*[ Type == 'AWS::ApiGateway::RestApi' ]`，如果輸入中沒有`AWS::ApiGateway::RestApi`資源，子句會評估為 `FAIL`。

```
%api_gws.Properties.EndpointConfiguration.Types[*] == "PRIVATE"
```

若要避免此結果，請將篩選條件指派給變數，並使用`when`條件檢查。

```
let api_gws = Resources.*[ Type == 'AWS::ApiGateway::RestApi' ]
    when %api_gws !empty { ...}
```

## Guard 不會評估具有短格式 Fn::GetAtt 參考的 CloudFormation 範本
<a name="troubleshooting-cfn-intrinsic-functions"></a>

Guard 不支援短形式的內部函數。例如，不支援在 YAML 格式 CloudFormation 範本`!Join``!Sub`中使用 。反之，請使用擴充形式的 CloudFormation 內部函數。例如，在 YAML 格式的 CloudFormation 範本`Fn::Sub`中使用 `Fn::Join`，根據 Guard 規則進行評估。

如需內部函數的詳細資訊，請參閱*AWS CloudFormation 《 使用者指南*》中的[內部函數參考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html)。

## 一般疑難排解主題
<a name="troubleshooting-general"></a>
+ 確認`string`常值不包含內嵌的逸出字串。Guard 不支援`string`常值的內嵌逸出字串。如果您的意圖是剖析內嵌 JSON 字串，請使用 Guard 3.0.0 和更新版本中提供的 `json_parse()`函數。如需詳細資訊，請參閱[使用內建函數](writing-rules.md#built-in-functions)。
+ 確認您的`!=`比較比較比較相容的資料類型。例如， `string`和 `int`是不相容的比較資料類型。執行`!=`比較時，如果值不相容，則會在內部發生錯誤。目前，錯誤會被隱藏並轉換為 `false`以滿足 Rust 中的 [PartialEq](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html) 特性。