

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

# 逐步解說：建立自訂 AWS AppConfig 擴充功能
<a name="working-with-appconfig-extensions-creating-custom"></a>

若要建立自訂 AWS AppConfig 擴充功能，請完成下列任務。在稍後的主題中，會更詳細地描述每個任務。

**注意**  
您可以在 GitHub 上檢視自訂 AWS AppConfig 擴充功能的範例：  
[使用 Systems Manager `blocked day` 變更行事曆透過暫時行事曆防止部署的範例延伸模組](https://github.com/aws-samples/aws-appconfig-change-calendar-extn)
[避免秘密使用 git-secrets 洩漏至組態資料的範例延伸](https://github.com/aws-samples/aws-appconfig-git-secrets-extn)
[避免個人身分識別資訊 (PII) 使用 Amazon Comprehend 洩漏至組態資料的範例延伸](https://github.com/aws-samples/aws-appconfig-pii-extn)

**1. [建立 AWS Lambda 函數](https://docs.aws.amazon.com/appconfig/latest/userguide/working-with-appconfig-extensions-creating-custom-lambda.html)**  
對於大多數使用案例，若要建立自訂擴充功能，您必須建立 AWS Lambda 函數來執行擴充功能中定義的任何運算和處理。此規則的例外是，如果您建立[AWS 撰寫通知延伸](https://docs.aws.amazon.com/appconfig/latest/userguide/working-with-appconfig-extensions-about-predefined.html)項目的*自訂*版本，以新增或移除動作點。如需此例外狀況的詳細資訊，請參閱 [步驟 3：建立自訂 AWS AppConfig 延伸模組](working-with-appconfig-extensions-creating-custom-extensions.md)。

**2. [設定自訂擴充功能的許可](https://docs.aws.amazon.com/appconfig/latest/userguide/working-with-appconfig-extensions-creating-custom-permissions.html)**  
若要設定自訂擴充功能的許可，您可以執行下列其中一項操作：  
+ 建立包含`InvokeFunction`許可的 AWS Identity and Access Management (IAM) 服務角色。
+ 使用 Lambda [AddPermission](https://docs.aws.amazon.com/lambda/latest/dg/API_AddPermission.html) API 動作建立資源政策。
本演練說明如何建立 IAM 服務角色。

**3. [建立延伸模組](https://docs.aws.amazon.com/appconfig/latest/userguide/working-with-appconfig-extensions-creating-custom-extensions.html)**  
您可以使用 AWS AppConfig 主控台，或從 或 SDK 呼叫 [CreateExtension](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_CreateExtension.html) API 動作 AWS CLI AWS Tools for PowerShell來建立擴充功能。演練使用 主控台。

**4. [建立延伸模組關聯](https://docs.aws.amazon.com/appconfig/latest/userguide/working-with-appconfig-extensions-creating-custom-association.html)**  
您可以使用 AWS AppConfig 主控台，或從 或 SDK 呼叫 [CreateExtensionAssociation](https://docs.aws.amazon.com/appconfig/2019-10-09/APIReference/API_CreateExtensionAssociation.html) API 動作 AWS CLI AWS Tools for PowerShell，來建立延伸關聯。演練使用 主控台。

**5. 執行叫用延伸模組的動作**  
建立關聯之後，當該資源發生延伸定義的動作點時， 會 AWS AppConfig 叫用延伸。例如，如果您關聯包含`PRE_CREATE_HOSTED_CONFIGURATION_VERSION`動作的延伸模組，則每次建立新的託管組態版本時都會叫用該延伸模組。

本節中的主題說明建立自訂 AWS AppConfig 擴充功能時涉及的每個任務。每個任務都會在客戶想要建立擴充功能，以自動將組態備份到 Amazon Simple Storage Service (Amazon S3) 儲存貯體的使用案例中描述。延伸項目會在建立託管組態 (`PRE_CREATE_HOSTED_CONFIGURATION_VERSION`) 或部署 () 時執行`PRE_START_DEPLOYMENT`。

**Topics**
+ [步驟 1：為自訂 AWS AppConfig 延伸模組建立 Lambda 函數](working-with-appconfig-extensions-creating-custom-lambda.md)
+ [步驟 2：設定自訂 AWS AppConfig 擴充功能的許可](working-with-appconfig-extensions-creating-custom-permissions.md)
+ [步驟 3：建立自訂 AWS AppConfig 延伸模組](working-with-appconfig-extensions-creating-custom-extensions.md)
+ [步驟 4：建立自訂擴充功能的 AWS AppConfig 擴充功能關聯](working-with-appconfig-extensions-creating-custom-association.md)