本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
AWS::SecretsManager
轉換程序
本主題說明如何使用 AWS::SecretsManager
轉換和 AWS::SecretsManager::RotationSchedule 資源類型來指定 Lambda 函數來執行秘密輪換。
此AWS::SecretsManager
轉換是一種 CloudFormation 巨集,當您使用變更集建立或更新堆疊時,會在堆疊範本中參考時,自動產生秘密輪換的 Lambda 函數。Lambda 函數放置在已處理範本的巢狀堆疊中。它使用來自 AWS Secrets Manager Rotation Lambda Functions
用量
若要使用AWS::SecretsManager
轉換,您必須在 CloudFormation 範本的最上層宣告。您無法將 AWS::SecretsManager
作為內嵌於任何其他範本區段的轉換使用。
宣告必須使用常值字串 AWS::SecretsManager-2020-07-23
或 AWS::SecretsManager-2024-09-16
作為其值。您不能使用參數或函數來指定轉換值。
語法
若要在 CloudFormation 範本中宣告此轉換,請使用下列語法:
JSON
{ "Transform":"AWS::SecretsManager-
2020-07-23
", "Resources":{...
} }
YAML
Transform: AWS::SecretsManager-
2020-07-23
Resources:...
AWS::SecretsManager
轉換是沒有其他參數的獨立宣告。反之,您可以在堆疊範本中設定 AWS::SecretsManager::RotationSchedule 資源的 HostedRotationLambda 屬性。HostedRotationLambda 屬性會指定 Lambda 函數來執行秘密輪換。
中的新功能 AWS::SecretsManager-2024-09-16
最新版本的AWS::SecretsManager
轉換 (AWS::SecretsManager-2024-09-16
) 引入了下列增強功能:
-
自動 Lambda 升級 – 當您更新 CloudFormation 堆疊時,Lambda 函數現在會自動更新其執行時間組態和內部相依性。這可確保您使用最安全可靠的程式碼版本,以管理 Secrets Manager 中的秘密輪換。
-
支援其他屬性 – 新轉換支援資源類型的其他
AWS::SecretsManager::RotationSchedule
資源屬性,當 與HostedRotationLambda
屬性搭配使用時,包括DependsOn
屬性。注意
這兩個版本都支援
DeletionPolicy
和UpdateReplacePolicy
屬性。
若要進一步了解此新版本的AWS::SecretsManager
轉換,請參閱 AWS 安全部落格上的 介紹增強版本的 AWS Secrets Manager 轉換:AWS::SecretsManager-2024-09-16
範例
下列部分範本範例示範如何在範本中使用AWS::SecretsManager
轉換 (AWS::SecretsManager-2024-09-16
) 和 AWS::SecretsManager::RotationSchedule 資源。在此範例中,CloudFormation 會自動為 MySQL 單一使用者秘密輪換產生 Lambda 函數。
秘密會設定為每天在午夜 (UTC) 自動輪換。輪換程序最多可能需要 2 小時才能完成。更新輪換排程不會立即開始輪換。
JSON
{ "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
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: !Reflogical name of AWS::SecretsManager::Secret resource
HostedRotationLambda: RotationType: MySQLSingleUser RotationLambdaName:name of Lambda function to be created
VpcSecurityGroupIds: !GetAttlogical 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
相關資源
如需可用來設定秘密輪換的完整 CloudFormation 範本範例,請參閱 AWS::SecretsManager::RotationSchedule
資源的範例一節。
如需使用巨集的一般考量,請參閱 考量事項。