

這是新的 *CloudFormation 範本參考指南*。請更新您的書籤和連結。如需 CloudFormation 入門的說明，請參閱 [AWS CloudFormation 使用者指南](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html)。

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

# 轉換參照
<a name="transform-reference"></a>

轉換是由 CloudFormation 託管的巨集。有別於自訂巨集，轉換是由 CloudFormation 託管，所以使用時並不需要任何特殊許可。轉換可用於 CloudFormation 中任何帳戶的範本。此外，使用轉換時不會產生任何費用。在評估順序和範圍方面，CloudFormation 會將轉換與任何其他巨集視為相同。

如需有關巨集如何運作的詳細資訊，請參閱《AWS CloudFormation 使用者指南》**中的[使用 CloudFormation 巨集對範本執行自訂處理](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html)。

可以在 CloudFormation 範本中使用下列轉換。

**Topics**
+ [`AWS::CodeDeployBlueGreen` 轉換程序](transform-aws-codedeploybluegreen.md)
+ [`AWS::Include` 轉換程序](transform-aws-include.md)
+ [`AWS::LanguageExtensions` 轉換程序](transform-aws-languageextensions.md)
+ [`AWS::SecretsManager` 轉換程序](transform-aws-secretsmanager.md)
+ [`AWS::Serverless` 轉換程序](transform-aws-serverless.md)
+ [`AWS::ServiceCatalog` 轉換程序](transform-aws-servicecatalog.md)

# `AWS::CodeDeployBlueGreen` 轉換程序
<a name="transform-aws-codedeploybluegreen"></a>

本主題說明如何使用 `AWS::CodeDeployBlueGreen` 轉換，以透過堆疊上的 CodeDeploy 啟用 ECS 藍綠部署。

如需詳細資訊，請參閱**《AWS CloudFormation 使用者指南》中的[使用 CloudFormation 透過 CodeDeploy 執行 ECS 藍/綠部署](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green.html)。

## Usage
<a name="aws-codedeploybluegreen-usage"></a>

若要使用 `AWS::CodeDeployBlueGreen` 轉換，必須在 CloudFormation 範本的頂層宣告轉換。您無法將 `AWS::CodeDeployBlueGreen` 作為內嵌於任何其他範本區段的轉換使用。

轉換宣告的值必須是常值字串。您不能使用參數或函數來指定轉換值。

### 語法
<a name="aws-codedeploybluegreen-syntax"></a>

若要在您的 CloudFormation 範本中宣告此轉換，請使用下列語法：

#### JSON
<a name="aws-codedeploybluegreen-syntax.json"></a>

```
{
  "Transform":[
    "AWS::CodeDeployBlueGreen"
  ],
  "Resources":{
    ...
  }
}
```

#### YAML
<a name="aws-codedeploybluegreen-syntax.yaml"></a>

```
Transform:
  - 'AWS::CodeDeployBlueGreen'
Resources:
  ...
```

`AWS::CodeDeployBlueGreen` 轉換是沒有其他參數的獨立宣告。

## 相關資源
<a name="aws-codedeploybluegreen-related-resources"></a>

如需可在堆疊上啟用 ECS 藍/綠部署的完整 CloudFormation 範本範例，請參閱**《AWS CloudFormation 使用者指南》中的[藍/綠部署範本範例](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/blue-green-template-example.html)。

如需有關使用巨集的一般資訊，請參閱《AWS CloudFormation 使用者指南》**中的[使用範本巨集在 CloudFormation 範本上執行自訂處理](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html)。

# `AWS::Include` 轉換程序
<a name="transform-aws-include"></a>

本主題說明如何使用 `AWS::Include` 轉換，將樣板式內容插入 CloudFormation 範本中。

`AWS::Include` 是 CloudFormation 巨集，當在堆疊範本中參考它時，如果您使用變更集來建立或更新堆疊，會在範本中的轉換位置插入指定檔案的內容。`AWS::Include` 函數的行為與程式設計語言中的 `include`、`copy` 或 `import` 指令類似。

## Usage
<a name="aws-include-usage"></a>

您可以在 CloudFormation 範本內的任意處使用 `AWS::Include` 轉換，但範本參數區段或範本版本除外。舉例來說，您可以在映射區段中使用 `AWS::Include`。

### 範本最上層的語法
<a name="aws-include-syntax-top-level"></a>

若要在 CloudFormation 範本的頂層將此轉換宣告為 `Transform` 區段，請使用下列語法：

#### JSON
<a name="aws-include-syntax-top-level.json"></a>

```
{
  "Transform":{
    "Name":"AWS::Include",
    "Parameters":{
      "Location":"s3://amzn-s3-demo-bucket/MyFileName.json"
    }
  },
  "Resources":{
    ...
  }
}
```

#### YAML
<a name="aws-include-syntax-top-level.yaml"></a>

```
Transform:
  Name: AWS::Include
  Parameters:
    Location: 's3://amzn-s3-demo-bucket/MyFileName.yaml'
Resources:
  ...
```

### 轉換程序內嵌於範本區段時的語法
<a name="aws-include-syntax-within-section"></a>

若要在 CloudFormation 範本的某個區段中宣告此轉換，請使用 `Fn::Transform` 內建函數和下列語法：

#### JSON
<a name="aws-include-syntax-within-section.json"></a>

```
{
  "Fn::Transform":{
    "Name":"AWS::Include",
    "Parameters":{
      "Location":"s3://amzn-s3-demo-bucket/MyFileName.json"
    }
  }
}
```

#### YAML
<a name="aws-include-syntax-within-section.yaml"></a>

```
Fn::Transform:
  Name: AWS::Include
  Parameters:
    Location: s3://amzn-s3-demo-bucket/MyFileName.yaml
```

如需詳細資訊，請參閱[`Fn::Transform`](intrinsic-function-reference-transform.md)。

### Parameters
<a name="aws-include-parameters"></a>

`Location`

該位置會以 Amazon S3 URI 呈現，其將包含 S3 儲存貯體中的特定檔案名稱；例如 `s3://amzn-s3-demo-bucket/MyFile.yaml`。

## 考量事項
<a name="aws-include-considerations"></a>

使用 `AWS::Include` 時，請謹記下列考量。如需有關使用巨集的更多考量，請參閱《AWS CloudFormation 使用者指南**》中的[巨集考量](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros-overview.html#template-macros-considerations)。
+ 我們目前支援 Amazon S3 URI，不支援其他 Amazon S3 格式 (例如 Amazon S3 ARN)。您必須使用 Amazon S3 儲存貯體，而非 GitHub 儲存庫等項目。
+ 具備 Amazon S3 URL 存取權的所有人皆能在範本中加入該程式碼片段。
+ 您的範本程式碼片段均必須是有效的 JSON。
+ 您的範本程式碼片段必須是有效的索引鍵–值物件，例如 `"KeyName": "keyValue"`。
+ 您無法用 `AWS::Include` 來參考也使用 `AWS::Include` 的範本程式碼片段。
+ 若您變更程式碼片段，堆疊並不會自動取得這些變更。如需取得這些變更，請使用更新後的程式碼片段來更新堆疊。更新堆疊時，務必確認加入的程式碼片段不會在您不知悉的情況下有所變更。請查看變更集，即可在更新堆疊前進行驗證。
+ 建立範本與程式碼片段時，可以將 YAML 和 JSON 範本語言混合使用。
+ YAML 程式碼片段目前不支援使用速記表示法。
+ 您可以使用 `AWS::Include` 來提供跨區域複寫 Amazon S3 URI。存取跨區域複寫物件時，請務必檢查 Amazon S3 儲存貯體的名稱。如需詳細資訊，請參閱《Amazon S3 使用者指南**》中的[在區域中和跨區域複寫物件](https://docs.aws.amazon.com/AmazonS3/latest/userguide/replication.html)。

## 範例
<a name="aws-include-examples"></a>

以下範例會說明如何使用 `AWS::Include` 轉換程序來執行等待條件控點。將 *amzn-s3-demo-bucket* 取代為實際的儲存貯體名稱。

首先，將名為 `single_wait_condition.yaml` 的 YAML 檔案儲存在 S3 儲存貯體中，其中包含以下內容：

```
MyWaitCondition:
  Type: AWS::CloudFormation::WaitCondition
  Properties:
    Handle: !Ref MyWaitHandle
    Timeout: '4500'
```

然後，使用 JSON 或 YAML 格式來參考此檔案。

### JSON
<a name="aws-include-example.json"></a>

```
{
   "Resources": {
      "MyWaitHandle": {
         "Type": "AWS::CloudFormation::WaitConditionHandle"
      },
      "Fn::Transform": {
         "Name": "AWS::Include",
         "Parameters": {
            "Location": "s3://amzn-s3-demo-bucket/single_wait_condition.yaml"
         }
      }
   }
}
```

### YAML
<a name="aws-include-example.yaml"></a>

```
Resources:
  MyWaitHandle:
    Type: AWS::CloudFormation::WaitConditionHandle
  Fn::Transform:
    Name: AWS::Include
    Parameters:
      Location: "s3://amzn-s3-demo-bucket/single_wait_condition.yaml"
```

如需詳細資訊，請參閱《AWS CloudFormation 使用者指南》**中的[在 CloudFormation 範本中建立等待條件](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-waitcondition.html)。

# `AWS::LanguageExtensions` 轉換程序
<a name="transform-aws-languageextensions"></a>

本主題說明如何使用 `AWS::LanguageExtensions` 轉換來啟用預設無法使用的其他函數和功能。

`AWS::LanguageExtensions` 是一個 CloudFormation 巨集，當在堆疊範本中參考它時，如果您使用變更集來建立或更新堆疊，則它會將轉換所定義的任何內建函數更新為其在範本中解析的值。

透過將此轉換包含在 CloudFormation 範本中，您可以存取 `Fn::ForEach` 等其他功能，以允許更進階的操作，例如迭代。也可以在通常不允許的地方使用內建函數，例如在 `Ref` 和 `Fn::GetAtt` 函數中。

## Usage
<a name="aws-languageextensions-usage"></a>

若要使用 `AWS::LanguageExtensions` 轉換，必須在 CloudFormation 範本的頂層宣告轉換。您無法將 `AWS::LanguageExtensions` 作為內嵌於任何其他範本區段的轉換使用。

宣告必須使用常值字串 `AWS::LanguageExtensions` 作為其值。您不能使用參數或函數來指定轉換值。

### 語法
<a name="aws-languageextensions-syntax"></a>

若要在您的 CloudFormation 範本中宣告此轉換，請使用下列語法：

### JSON
<a name="aws-languageextensions-syntax.json"></a>

```
{
  "Transform":"AWS::LanguageExtensions",
  "Resources":{
    ...
  }
}
```

### YAML
<a name="aws-languageextensions-syntax.yaml"></a>

```
Transform: AWS::LanguageExtensions
Resources:
  ...
```

`AWS::LanguageExtensions` 轉換是沒有其他參數的獨立宣告。

## 支援其他函數
<a name="aws-languageextensions-supported-functions"></a>

`AWS::LanguageExtensions` 轉換支援下列其他函數：
+ [`Fn::ForEach`](intrinsic-function-reference-foreach.md)
+ [`Fn::Length`](intrinsic-function-reference-length.md)
+ [`Fn::ToJsonString`](intrinsic-function-reference-ToJsonString.md)

## 考量事項
<a name="aws-languageextensions-considerations"></a>

使用 `AWS::LanguageExtensions` 轉換時，請謹記以下幾點考量：
+ 當您更新使用 `AWS::LanguageExtensions` 轉換的堆疊時，建議您不要使用 CloudFormation 主控台中的**使用現有範本**選項，或同等的命令列選項 `--use-previous-template`。`AWS::LanguageExtensions` 轉換在處理期間會將參數解析為常值。當您使用 `--use-previous-template` 時，CloudFormation 會將此處理過的範本與舊常值搭配使用，以防止套用新的參數值和 Systems Manager 參數更新。反之，請提供原始範本，以確保使用目前的值重新解析參數。
+ 僅由 `AWS::LanguageExtensions` 轉換提供的內部函數在範本中不支援簡短格式 YAML 語法。使用這些函數的明確參考。例如，使用 `Fn::Length` 代替 `!Length`。
+ CLI AWS SAM 目前不支援`AWS::LanguageExtensions`轉換的內部`Fn::ForEach`函數。
+ 如果您使用多個轉換，請使用清單格式。如果您使用的是自訂巨集，則 位置 AWS提供的轉換會在您的自訂巨集之後進行。如果您同時使用 `AWS::LanguageExtensions` 和 `AWS::Serverless` 轉換，則在清單中，`AWS::LanguageExtensions` 轉換必須排在 `AWS::Serverless` 轉換之前。
+ 僅在範本的 `Resources`、`Conditions` 和 `Outputs` 區段中，支援 `AWS::LanguageExtensions` 轉換提供的功能和屬性。

## 範例
<a name="aws-languageextensions-examples"></a>

下列範例顯示如何借助 `AWS::LanguageExtensions` 轉換使用由該轉換定義的 `Fn::Length` 內建函數。

### JSON
<a name="aws-languageextensions-example.json"></a>

```
{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Transform": "AWS::LanguageExtensions",
    "Parameters": {
        "QueueList": {
            "Type": "CommaDelimitedList"
        },
        "QueueNameParam": {
            "Description": "Name for your SQS queue",
            "Type": "String"
        }
    },
    "Resources": {
        "Queue": {
            "Type": "AWS::SQS::Queue",
            "Properties": {
                "QueueName": {
                    "Ref": "QueueNameParam"
                },
                "DelaySeconds": {
                    "Fn::Length": {
                        "Ref": "QueueList"
                    }
                }
            }
        }
    }
}
```

### YAML
<a name="aws-languageextensions-example.yaml"></a>

```
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::LanguageExtensions
Parameters:
  QueueList:
    Type: CommaDelimitedList
  QueueNameParam:
    Description: Name for your SQS queue
    Type: String
Resources:
  Queue:
    Type: AWS::SQS::Queue
    Properties:
      QueueName: !Ref QueueNameParam
      DelaySeconds:
        'Fn::Length': !Ref QueueList
```

## 相關資源
<a name="aws-languageextensions-related-resources"></a>

如需更多範例，請參閱下列主題。
+ [`Fn::ForEach`](intrinsic-function-reference-foreach.md)
+ [`Fn::Length`](intrinsic-function-reference-length.md)
+ [`Fn::ToJsonString`](intrinsic-function-reference-ToJsonString.md)
+ [`Ref`](intrinsic-function-reference-ref.md)
+ [`Fn::GetAtt`](intrinsic-function-reference-getatt.md)
+ [`Fn::FindInMap enhancements`](intrinsic-function-reference-findinmap-enhancements.md)

如需有關使用巨集的一般資訊，請參閱《AWS CloudFormation 使用者指南》**中的[使用範本巨集在 CloudFormation 範本上執行自訂處理](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html)。

# `Fn::FindInMap enhancements`
<a name="intrinsic-function-reference-findinmap-enhancements"></a>

`AWS::LanguageExtensions` 轉換可增強 CloudFormation 範本中 `Fn::FindInMap` 內建函數的功能。

`Fn::FindInMap` 函數用於從 CloudFormation 範本的 `Mappings` 區段所定義的映射中擷取值。不過，標準 `Fn::FindInMap` 函數具有限制，例如無法處理遺失的映射，或無法使用內嵌某些內建函數的 `Fn::FindInMap` 函數。

`AWS::LanguageExtensions` 轉換透過引入下列增強功能來解決這些限制：
+ **預設值支援** – 如果找不到映射，可以指定要傳回的預設值。
+ **內建函數支援** – 也可以使用更廣泛的內建函數來定義 `Fn::FindInMap` 的欄位，而不是使用標準 `Fn::FindInMap` 函數。

## 宣告
<a name="intrinsic-function-reference-findinmap-enhancements-declaration"></a>

### JSON
<a name="intrinsic-function-reference-findinmap-enhancements-syntax.json"></a>

```
{ "Fn::FindInMap" : [
    "MapName",
    "TopLevelKey",
    "SecondLevelKey",
    {"DefaultValue": "DefaultValue"}
  ]
}
```

### YAML
<a name="intrinsic-function-reference-findinmap-enhancements-syntax.yaml"></a>

完整函式名稱的語法：

```
Fn::FindInMap:
  - MapName
  - TopLevelKey
  - SecondLevelKey
  - DefaultValue: DefaultValue
```

短格式的語法：

```
!FindInMap
  - MapName
  - TopLevelKey
  - SecondLevelKey
  - DefaultValue: DefaultValue
```

## Parameters
<a name="intrinsic-function-reference-findinmap-enhancements-parameters"></a>

DefaultValue  <a name="DefaultValue"></a>
無法從 `MapName` 映射中找到 `TopLevelKey` 和/或 `SecondLevelKey` 時，`Fn::FindInMap` 的解析值。此欄位為選用欄位。

只要能夠在轉換期間解析為有效值，`MapName`、`TopLevelKey`、`SecondLevelKey`、和 `DefaultValue` 所有參數都可以是內部函數。

## 範例
<a name="w2aac28c16c20c15"></a>

下列範例示範如何在新增 `AWS::LanguageExtensions` 轉換時定義 `Fn::FindInMap` 的欄位。

### 使用預設值
<a name="intrinsic-function-reference-findinmap-enhancements-example"></a>

以下是在 `Fn::FindInMap` 函數中使用預設值的範例：

#### JSON
<a name="intrinsic-function-reference-findinmap-default-value-example.json"></a>

```
{
  //...
    "Transform": "AWS::LanguageExtensions",
    //...
    "Fn::FindInMap": [
      "RegionMap",
      { "Ref": "AWS::Region" },
      "InstanceType",
      { "DefaultValue": "t3.micro" }
    ]
  //...
}
```

#### YAML
<a name="intrinsic-function-reference-findinmap-default-value-example.yaml"></a>

```
Transform: 'AWS::LanguageExtensions'
#...
    !FindInMap 
        - 'RegionMap'
        - !Ref 'AWS::Region'
        - 'InstanceType'
        - DefaultValue: t3.micro
#...
```

#### 使用內建函數來定義頂層金鑰
<a name="intrinsic-function-reference-findinmap-enhancements-example"></a>

以下是使用內嵌有 `Fn::Select` 和 `Fn::Split` 內建函數的 `Fn::FindInMap` 函數來定義頂層金鑰的範例。

##### JSON
<a name="intrinsic-function-reference-findinmap-enhancement-example.json"></a>

```
{
  //...
  "Transform": "AWS::LanguageExtensions",
  //...
      "Fn::FindInMap": [
        "MyMap",
        {
          "Fn::Select": [
            0,
            {
              "Fn::Split": [
                "|",
                { "Ref": "InputKeys" }
              ]
            }
          ]
        },
        "SecondKey"
      ]
//...
}
```

##### YAML
<a name="intrinsic-function-reference-findinmap-enhance-example.yaml"></a>

```
Transform: 'AWS::LanguageExtensions'
#...
    !FindInMap: [MyMap, !Select [0, !Split [|, !Ref InputKeys]], SecondKey]
#...
```

## 支援的函數
<a name="intrinsic-function-reference-findinmap-enhancements-supported-functions"></a>

您可以在 `Fn::FindInMap:` 增強的參數中使用以下函數：
+ ``Fn::FindInMap``
+ ``Fn::Join``
+ ``Fn::Sub``
+ ``Fn::If``
+ ``Fn::Select``
+ ``Fn::Length``
+ ``Fn::ToJsonString``
+ ``Fn::Split`` - 除非用於預設值，否則 `Fn::Split` 必須與產生字串的內部函數搭配使用，例如 ``Fn::Join`` 或 ``Fn::Select``。
+ ``Ref``

## 相關資源
<a name="w2aac28c16c20c19"></a>

如需有關展示如何使用 `Fn::FindInMap` 內建函數的詳細資訊和範例，請參閱 [`Fn::FindInMap`](intrinsic-function-reference-findinmap.md)。

如需 `AWS::LanguageExtensions` 轉換的詳細資訊，請參閱 [`AWS::LanguageExtensions` 轉換程序](transform-aws-languageextensions.md)。

# `AWS::SecretsManager` 轉換程序
<a name="transform-aws-secretsmanager"></a>

本主題說明如何使用 `AWS::SecretsManager` 轉換和 [AWS::SecretsManager::RotationSchedule](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-secretsmanager-rotationschedule.html) 資源類型來指定 Lambda 函式，以執行秘密輪換。

`AWS::SecretsManager` 轉換是一種 CloudFormation 巨集，當在堆疊範本中參考它時，如果使用變更集來建立或更新堆疊，會為秘密輪換自動產生 Lambda 函式。Lambda 函式放置在已處理範本的巢狀堆疊中。它使用來自 [AWS Secrets Manager Rotation Lambda Functions](https://github.com/aws-samples/aws-secrets-manager-rotation-lambdas) 儲存庫的函數範本，以 [AWS::SecretsManager::RotationSchedule](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-secretsmanager-rotationschedule.html) 資源的 [RotationType](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-secretsmanager-rotationschedule-hostedrotationlambda.html#cfn-secretsmanager-rotationschedule-hostedrotationlambda-rotationtype) 屬性值為基礎。

## Usage
<a name="aws-secretsmanager-usage"></a>

若要使用 `AWS::SecretsManager` 轉換，必須在 CloudFormation 範本的頂層宣告轉換。您無法將 `AWS::SecretsManager` 作為內嵌於任何其他範本區段的轉換使用。

宣告必須使用常值字串 `AWS::SecretsManager-2020-07-23` 或 `AWS::SecretsManager-2024-09-16` 作為其值。您不能使用參數或函數來指定轉換值。

### 語法
<a name="aws-secretsmanager-syntax"></a>

若要在您的 CloudFormation 範本中宣告此轉換，請使用下列語法：

#### JSON
<a name="aws-secretsmanager-syntax.json"></a>

```
{
  "Transform":"AWS::SecretsManager-2020-07-23",
  "Resources":{
    ...
  }
}
```

#### YAML
<a name="aws-secretsmanager-syntax.yaml"></a>

```
Transform: AWS::SecretsManager-2020-07-23
Resources:
  ...
```

`AWS::SecretsManager` 轉換是沒有其他參數的獨立宣告。反之，可以在堆疊範本中設定 [AWS::SecretsManager::RotationSchedule](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-secretsmanager-rotationschedule.html) 資源的 [HostedRotationLambda](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-secretsmanager-rotationschedule-hostedrotationlambda.html) 屬性。[HostedRotationLambda](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-properties-secretsmanager-rotationschedule-hostedrotationlambda.html) 屬性會指定 Lambda 函式，以執行秘密輪換。

## `AWS::SecretsManager-2024-09-16` 中的新功能
<a name="aws-secretsmanager-new-version"></a>

最新版本的 `AWS::SecretsManager` 轉換 (`AWS::SecretsManager-2024-09-16`) 引入了下列增強功能：
+ **自動 Lambda 升級** – 當您更新 CloudFormation 堆疊時，Lambda 函式現在會自動更新其執行時期組態和內部相依性。這可確保您使用最安全且可靠的程式碼版本，以管理 Secrets Manager 中的秘密輪換。
+ **支援其他屬性** – 新轉換在與 `HostedRotationLambda` 屬性搭配使用時，支援 `AWS::SecretsManager::RotationSchedule` 資源類型的其他資源屬性，包括 `DependsOn` 屬性。
**注意**  
這兩個版本都支援 `DeletionPolicy` 和 `UpdateReplacePolicy` 屬性。

若要進一步了解此新版本的`AWS::SecretsManager`轉換，請參閱 AWS 安全部落格上的[介紹增強版本的 AWS Secrets Manager 轉換：AWS::SecretsManager-2024-09-16](https://aws.amazon.com/blogs/security/introducing-an-enhanced-version-of-the-aws-secrets-manager-transform-awssecretsmanager-2024-09-16/)。

## 範例
<a name="aws-secretsmanager-examples"></a>

下列範例示範如何在範本中使用 `AWS::SecretsManager` 轉換 (`AWS::SecretsManager-2024-09-16`) 和 [AWS::SecretsManager::RotationSchedule](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-secretsmanager-rotationschedule.html) 資源。在此範例中，CloudFormation 將自動為 MySQL 單一使用者秘密輪換產生 Lambda 函式。

秘密設定為每天午夜自動輪換 (UTC)。輪換程序可能最多需要 2 小時才能完成。更新輪換排程不會立即開始輪換。

### JSON
<a name="aws-secretsmanager-example.json"></a>

```
{
  "AWSTemplateFormatVersion":"2010-09-09",
  "Transform":"AWS::SecretsManager-2024-09-16",
  "Resources":{

  ...

    "MySecretRotationSchedule":{
      "Type":"AWS::SecretsManager::RotationSchedule",
      "DependsOn":"logical name of AWS::SecretsManager::SecretTargetAttachment resource",
      "Properties":{
        "SecretId":{
          "Ref":"logical name of AWS::SecretsManager::Secret resource"
        },
        "HostedRotationLambda":{
          "RotationType":"MySQLSingleUser",
          "RotationLambdaName":"name of Lambda function to be created",
          "VpcSecurityGroupIds":{
            "Fn::GetAtt":[
              "logical name of AWS::EC2::SecurityGroup resource",
              "GroupId"
            ]
          },
          "VpcSubnetIds":{
            "Fn::Join":[
              ",",
              [
                {
                  "Ref":"logical name of primary subnet"
                },
                {
                  "Ref":"logical name of secondary subnet"
                }
              ]
            ]
          }
        },
        "RotationRules":{
          "ScheduleExpression":"cron(0 0 * * ? *)",
          "Duration":"2h"
        },
        "RotateImmediatelyOnUpdate":false
      }
    }
  }
}
```

### YAML
<a name="aws-secretsmanager-example.yaml"></a>

```
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::SecretsManager-2024-09-16
Resources:

  ...

  MySecretRotationSchedule:
    Type: AWS::SecretsManager::RotationSchedule
    DependsOn: logical name of AWS::SecretsManager::SecretTargetAttachment resource
    Properties:
      SecretId: !Ref logical name of AWS::SecretsManager::Secret resource
      HostedRotationLambda:
        RotationType: MySQLSingleUser
        RotationLambdaName: name of Lambda function to be created
        VpcSecurityGroupIds: !GetAtt logical name of AWS::EC2::SecurityGroup resource.GroupId
        VpcSubnetIds:
          Fn::Join:
          - ","
          - - Ref: logical name of primary subnet
            - Ref: logical name of secondary subnet
      RotationRules:
        ScheduleExpression: cron(0 0 * * ? *)
        Duration: 2h
      RotateImmediatelyOnUpdate: false
```

## 相關資源
<a name="aws-secretsmanager-related-resources"></a>

如需可用來設定秘密輪換的完整 CloudFormation 範本範例，請參閱 `AWS::SecretsManager::RotationSchedule` 資源的[範例](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-secretsmanager-rotationschedule.html#aws-resource-secretsmanager-rotationschedule--examples)一節。

如需有關使用巨集的一般資訊，請參閱《AWS CloudFormation 使用者指南》**中的[使用範本巨集在 CloudFormation 範本上執行自訂處理](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html)。

# `AWS::Serverless` 轉換程序
<a name="transform-aws-serverless"></a>

本主題說明如何使用`AWS::Serverless`轉換來處理以無 AWS 伺服器應用程式模型 (AWS SAM) 語法撰寫的範本，並將其轉換為合規的 CloudFormation 範本。

如需有關使用 `AWS::Serverless` 轉換的詳細資訊，請參閱 GitHub 上的 [AWS SAM 轉換](https://github.com/aws/serverless-application-model)。

## Usage
<a name="aws-serverless-usage"></a>

若要使用 `AWS::Serverless` 轉換，必須在 CloudFormation 範本的頂層宣告轉換。您無法將 `AWS::Serverless` 作為內嵌於任何其他範本區段的轉換使用。

宣告必須使用常值字串 `AWS::Serverless-2016-10-31` 作為其值。您不能使用參數或函數來指定轉換值。

### 語法
<a name="aws-serverless-syntax"></a>

若要在您的 CloudFormation 範本中宣告此轉換，請使用下列語法：

#### JSON
<a name="aws-serverless-syntax.json"></a>

```
{
  "Transform":"AWS::Serverless-2016-10-31",
  "Resources":{
    ...
  }
}
```

#### YAML
<a name="aws-serverless-syntax.yaml"></a>

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

`AWS::Serverless` 轉換是沒有其他參數的獨立宣告。

## 範例
<a name="aws-serverless-examples"></a>

下列範例顯示如何使用 `AWS::Serverless` 轉換和 AWS SAM 語法來簡化 Lambda 函式及其執行角色的宣告。

### JSON
<a name="aws-serverless-example.json"></a>

```
{
  "Transform":"AWS::Serverless-2016-10-31",
  "Resources":{
    "MyFunction":{
      "Type":"AWS::Serverless::Function",
      "Properties":{
        "Handler":"index.handler",
        "Runtime":"nodejs20.x",
        "CodeUri":"s3://amzn-s3-demo-bucket/MySourceCode.zip"
      }
    }
  }
}
```

### YAML
<a name="aws-serverless-example.yaml"></a>

```
Transform: AWS::Serverless-2016-10-31
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs20.x
      CodeUri: 's3://amzn-s3-demo-bucket/MySourceCode.zip'
```

從範本建立變更集時，CloudFormation AWS SAM 會展開轉換所定義的語法。處理過的範本會擴充 `AWS::Serverless::Function` 資源，並宣告 Lambda 函式和執行角色。

```
{
  "Resources": {
    "MyFunction": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Handler": "index.handler",
        "Code": {
          "S3Bucket": "amzn-s3-demo-bucket",
          "S3Key": "MySourceCode.zip"
        },
        "Role": {
          "Fn::GetAtt": ["MyFunctionRole", "Arn"]
        },
        "Runtime": "nodejs20.x"
      }
    },
    "MyFunctionRole": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "ManagedPolicyArns": ["arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"],
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",		 	 	 
          "Statement": [{
            "Action": ["sts:AssumeRole"],
            "Effect": "Allow",
            "Principal": {
              "Service": ["lambda.amazonaws.com"]
            }
          }]
        }
      }
    }
  }
}
```

## 搭配使用 `AWS::Serverless` 與 `AWS::LanguageExtensions`
<a name="aws-serverless-language-extensions"></a>

同時使用 `AWS::Serverless` 和 `AWS::LanguageExtensions` 轉換時，當階段名稱以非 `NoEcho` 參數值進行傳遞時，參考 `AWS::ApiGateway::Stage` 等資源需要特殊語法。

使用 AWS SAM `Fn::Sub`產生邏輯 ID 參考，而不是使用 語法做為參考 (`MyApi.Stage`)。例如 `"Ref": {"Fn::Sub": "${MyApi}${StageName}Stage"}`。這會在執行時期建置正確的邏輯 ID。

這種特殊格式的原因是因為這兩個轉換處理值的方式不同：
+ `AWS::LanguageExtensions` 會將內建函數解析為其實際值。
+ `AWS::Serverless` 會根據其收到靜態值還是內建函數，來建立不同的邏輯 ID。

## 相關資源
<a name="aws-serverless-related-resources"></a>

如需無伺服器應用程式和無 AWS 伺服器應用程式模型 (AWS SAM) 的詳細資訊，請參閱 [AWS Serverless Application Model 開發人員指南](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html)。

如需特定的資源和屬性類型 AWS SAM，請參閱《 *AWS Serverless Application Model 開發人員指南*》中的[AWS SAM 資源和屬性](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-resources-and-properties.html)。

如需有關使用巨集的一般資訊，請參閱《AWS CloudFormation 使用者指南》**中的[使用範本巨集在 CloudFormation 範本上執行自訂處理](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-macros.html)。

# `AWS::ServiceCatalog` 轉換程序
<a name="transform-aws-servicecatalog"></a>

本主題說明如何使用 `AWS::ServiceCatalog`轉換來參考 CloudFormation 範本中現有 AWS Service Catalog 佈建產品的輸出。

## Usage
<a name="aws-servicecatalog-usage"></a>

若要使用 `AWS::ServiceCatalog` 轉換，必須在 CloudFormation 範本的頂層宣告轉換。您無法將 `AWS::ServiceCatalog` 作為內嵌於任何其他範本區段的轉換使用。

如果需要輸出值，請提供已佈建產品的名稱和輸出索引鍵名稱。

您可以在範本中參考多個佈建的產品和索引鍵名稱，每個範本最多可參考 20 個。在佈建期間，轉換會從每個參考的佈建產品和索引鍵擷取值，以取代 CloudFormation 範本中的輸出值。

宣告必須使用常值字串 `AWS::ServiceCatalog` 作為其值。您不能使用參數或函數來指定轉換值。

### 語法
<a name="aws-servicecatalog-syntax"></a>

若要在您的 CloudFormation 範本中宣告此轉換，請使用下列語法：

#### JSON
<a name="aws-servicecatalog-syntax.json"></a>

```
{
  "Transform":"AWS::ServiceCatalog",
  "Resources":{
    ...
  }
}
```

#### YAML
<a name="aws-servicecatalog-syntax.yaml"></a>

```
Transform: AWS::ServiceCatalog
Resources:
  ...
```

`AWS::ServiceCatalog` 轉換是沒有其他參數的獨立宣告。

## 範例
<a name="aws-servicecatalog-examples"></a>

下列範例顯示如何在 CloudFormation 範本中參考現有 Service Catalog 佈建產品的輸出。

在這些範例中，`SampleProvisionedProduct` 是先前建立的佈建產品。`SampleOutputKey`是此佈建產品的輸出索引鍵。

### JSON
<a name="aws-servicecatalog-example.json.json"></a>

此範例是工作版本。

未將該值包裝為字串文字的範例版本將會失敗。

```
{
  "AWSTemplateFormatVersion":"2010-09-09",
  "Transform":"AWS::ServiceCatalog",
  "Resources":{
    "ExampleParameter":{
      "Type":"AWS::SSM::Parameter",
      "Properties":{
        "Type":"String",
        "Value":"[[servicecatalog:provisionedproduct:SampleProvisionedProduct:SampleOutputKey]]"
      }
    }
  }
}
```

### YAML
<a name="aws-servicecatalog-example.yaml"></a>

範例 1–4 是有效的範本。在範例 1 和 2 中，轉換和值是字串文字。

範例 5 不是有效的範本。值必須包裝在字串 `'` 或 `"` 或 `>-` 內。如果沒有，使用者將會收到錯誤。

```
// Example 1 
AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::ServiceCatalog'
Resources:
  ExampleParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Type: String
      Value: '[[servicecatalog:provisionedproduct:SampleProvisionedProduct:SampleOutputKey]]'
     
// Example 2
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::ServiceCatalog
Resources:
  ExampleParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Type: String
      Value: '[[servicecatalog:provisionedproduct:SampleProvisionedProduct:SampleOutputKey]]'
     
     
// Example 3 
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::ServiceCatalog
Resources:
  ExampleParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Type: String
      Value: "[[servicecatalog:provisionedproduct:SampleProvisionedProduct:SampleOutputKey]]"
     
     
// Example 4 
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::ServiceCatalog
Resources:
  ExampleParameter:
    Type: AWS::SSM::Parameter
    Properties:
      Type: String
      Value: >-
        [[servicecatalog:provisionedproduct:SampleProvisionedProduct:SampleOutputKey]]
     
     
// Example 5 
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::ServiceCatalog
Resources:
  ExampleParameter2:
    Type: AWS::SSM::Parameter
    Properties:
      Type: String
      Value: [[servicecatalog:provisionedproduct:SSMProductProvisionedProduct:SampleOutputKey]]
```