変更セット(置換 Replacement )| AWS CoudFormation
| おもに Action が Modify の Replacement ( True | False | Conditional )について記載しています。 |
ドキュメント
変更セットフィールド サンプル
"Changes": [
{
"ResourceChange": {
"ResourceType": "AWS::EC2::Instance",
"PhysicalResourceId": "i-1abc23d4",
"Details": [
{
"ChangeSource": "DirectModification",
"Evaluation": "Static",
"Target": {
"Attribute": "Tags",
"RequiresRecreation": "Never"
}
}
],
"Action": "Modify",
"Scope": [
"Tags"
],
"LogicalResourceId": "MyEC2Instance",
"Replacement": "False"
},
"Type": "Resource"
}
],
変更セットの各フィールドの説明については、「AWS CloudFormation API リファレンス」の「変更データ型」を参照してください。
ref. 変更セットのサンプル
Change
- Changes.HookInvocationCount
- Changes.ResourceChange
A ResourceChange structure that describes the resource and action that CloudFormation will perform.
- Changes.Type
The type of entity that CloudFormation changes.
ResourceChange
Changes.ResourceChange.Action
Action The action that CloudFormation takes on the resource, such as Add (adds a new resource), Modify (changes a resource), Remove (deletes a resource), Import (imports a resource), or Dynamic (exact action for the resource can’t be determined).
Type: String
Valid Values: Add Modify Remove Import Dynamic Required: No
ref. ResourceChange
Changes.ResourceChange.Replacement
For the Modify action, indicates whether CloudFormation will replace the resource by creating a new one and deleting the old one. This value depends on the value of the RequiresRecreation property in the ResourceTargetDefinition structure. For example, if the RequiresRecreation field is Always and the Evaluation field is Static, Replacement is True. If the RequiresRecreation field is Always and the Evaluation field is Dynamic, Replacement is Conditional.
If you have multiple changes with different RequiresRecreation values, the Replacement value depends on the change with the most impact. A RequiresRecreation value of Always has the most impact, followed by Conditional, and then Never.
Type: String
Valid Values: True False Conditional Required: No
DeepL 訳
Modify アクションの場合、CloudFormation が新しいリソースを作成して古いリソースを削除することによってリソースを置き換えるかどうかを示します。この値は、ResourceTargetDefinition構造体のRequiresRecreationプロパティの値に依存します。たとえば、RequiresRecreation フィールドが Always で、Evaluation フィールドが Static の場合、Replacement は True になります。RequiresRecreation フィールドが Always で、Evaluation フィールドが Dynamic の場合、Replacement は Conditional です。
RequiresRecreation 値が異なる複数の変更がある場合、Replacement 値は最も影響の大きい変更に依存します。RequiresRecreationの値がAlwaysの場合、最も影響が大きく、次にConditional、そしてNeverの順となります。
「This value depends on the value of the RequiresRecreation property in the ResourceTargetDefinition structure. 」 に記載してあるとおり ResourceTargetDefinition.RequiresRecreation に依存します。
- RequiresRecreation が Never なら Replacement は False
- RequiresRecreation が Always で Evaluation が Static なら Replacement は True
- RequiresRecreation が Always で Evaluation が Dynamic なら Replacement は Conditional
- RequiresRecreation が Conditionally なら Replacement は Conditional(下記 RequiresRecreation の例 を参照)
Replacement が True / Conditional のときの注意
Name プロパティなどでリソース名を固定している場合、置換(新しいリソースを先に作成してから古いリソースを削除)で同名のリソースが衝突して更新に失敗することがあります。
同名リソースの衝突については CloudFormation Stack も参照してください。
Changes.Details.member.N
Action が Modify のときにのみ表示され、 CloudFormation によるリソース変更の詳細リスト( a list of ResourceChangeDetail structures )です。
Details.member.N For the Modify action, a list of ResourceChangeDetail structures that describes the changes that CloudFormation will make to the resource.
Type: Array of ResourceChangeDetail objects
Required: No
ref.
ResourceChangeDetail
Changes.Details.Target
Target A ResourceTargetDefinition structure that describes the field that CloudFormation will change and whether the resource will be recreated.
Type: ResourceTargetDefinition object
Required: No
ref. ResourceChangeDetail
ResourceTargetDefinition
Changes.Details.Target.RequiresRecreation
RequiresRecreation If the Attribute value is Properties, indicates whether a change to this property causes the resource to be recreated. The value can be Never, Always, or Conditionally. To determine the conditions for a Conditionally recreation, see the update behavior for that property in the AWS resource and property types reference in the AWS CloudFormation User Guide.
Type: String
Valid Values: Never Conditionally Always Required: No
DeepL で翻訳
RequiresRecreation Attribute 値が Properties の場合、このプロパティへの変更がリソースの再作成を引き起こすかどうかを示します。値には、Never、Always、または Conditionally を指定できます。Conditionally の再作成の条件を決定するには、AWS CloudFormation User Guide の AWS resource and property types reference のそのプロパティの更新動作を参照してください。
ref. AWS リソースおよびプロパティタイプのリファレンス
RequiresRecreation の例
{
"Type": "Resource",
"ResourceChange": {
"Action": "Modify",
"LogicalResourceId": "WriteInstance",
"PhysicalResourceId": "xxxxxxxxxx",
"ResourceType": "AWS::RDS::DBInstance",
"Replacement": "Conditional",
"Scope": [
"Properties"
],
"Details": [
{
"Target": {
"Attribute": "Properties",
"Name": "DBParameterGroupName",
"RequiresRecreation": "Conditionally"
},
"Evaluation": "Static",
"ChangeSource": "DirectModification"
}
]
}
}
AWS::RDS::DBInstance > DBParameterGroupName
この例では、プロパティのリファレンスが Update requires: Some interruptions になっています。
Some interruptions は Understand update behaviors of stack resources に以下のように記載されています。
Updates with Some Interruption
AWS CloudFormation updates the resource with some interruption. For example, if you update certain properties on an AWS::EC2::Instance resource, the instance might have some interruption while AWS CloudFormation and Amazon EC2 reconfigure the instance.
ただし、リファレンスの Update requires の表記と変更セットの RequiresRecreation が常に一対一で対応するわけではありません。
置換されるかどうかは、変更セットの Replacement と RequiresRecreation を根拠に判断してください。
ref. スタックリソースの更新動作を理解する
変更セット取得
AWS CLI で変更セットを取得できます。
$ aws cloudformation describe-change-set --change-set-name --stack-name --profile
変更セットの例
{
"StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/SampleStack/1a2345b6-0000-00a0-a123-00abc0abc000",
"Status": "CREATE_COMPLETE",
"ChangeSetName": "SampleChangeSet-direct",
"Parameters": [
{
"ParameterValue": "testing",
"ParameterKey": "Purpose"
},
{
"ParameterValue": "MyKeyName",
"ParameterKey": "KeyPairName"
},
{
"ParameterValue": "t2.micro",
"ParameterKey": "InstanceType"
}
],
"Changes": [
{
"ResourceChange": {
"ResourceType": "AWS::EC2::Instance",
"PhysicalResourceId": "i-1abc23d4",
"Details": [
{
"ChangeSource": "DirectModification",
"Evaluation": "Static",
"Target": {
"Attribute": "Tags",
"RequiresRecreation": "Never"
}
}
],
"Action": "Modify",
"Scope": [
"Tags"
],
"LogicalResourceId": "MyEC2Instance",
"Replacement": "False"
},
"Type": "Resource"
}
],
"CreationTime": "2020-11-18T23:35:25.813Z",
"Capabilities": [],
"StackName": "SampleStack",
"NotificationARNs": [],
"ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/SampleChangeSet-direct/1a2345b6-0000-00a0-a123-00abc0abc000"
}
ref. 変更セットのサンプル