AWS CloudFormation 使用示例 AWS CLI - AWS Command Line Interface

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

AWS CloudFormation 使用示例 AWS CLI

以下代码示例向您展示了如何使用with来执行操作和实现常见场景 AWS CloudFormation。 AWS Command Line Interface

操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。

每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。

主题

操作

以下代码示例显示了如何使用activate-type

AWS CLI

激活类型

以下activate-type示例激活了公共第三方扩展,使其可用于堆栈模板。

aws cloudformation activate-type \ --region us-west-2 \ --type RESOURCE \ --type-name Example::Test::1234567890abcdef0 \ --type-name-alias Example::Test::Alias

输出:

{ "Arn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/Example-Test-Alias" }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用batch-describe-type-configurations

AWS CLI

批量描述类型配置

以下batch-describe-type-configurations示例为该类型配置数据。

aws cloudformation batch-describe-type-configurations \ --region us-west-2 \ --type-configuration-identifiers TypeArn="arn:aws:cloudformation:us-west-2:123456789012:type/resource/Example-Test-Type,TypeConfigurationAlias=MyConfiguration"

输出:

{ "Errors": [], "UnprocessedTypeConfigurations": [], "TypeConfigurations": [ { "Arn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/Example-Test-Type", "Alias": "MyConfiguration", "Configuration": "{\n \"Example\": {\n \"ApiKey\": \"examplekey\",\n \"ApplicationKey\": \"examplekey1\",\n \"ApiURL\": \"exampleurl\"\n }\n}", "LastUpdated": "2021-10-01T15:25:46.210000+00:00", "TypeArn": "arn:aws:cloudformation:us-east-1:123456789012:type/resource/Example-Test-Type" } ] }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用cancel-update-stack

AWS CLI

取消正在进行的堆栈更新

以下 cancel-update-stack 命令会取消 myteststack 堆栈上的堆栈更新:

aws cloudformation cancel-update-stack --stack-name myteststack

以下代码示例显示了如何使用continue-update-rollback

AWS CLI

重试更新回滚

以下 continue-update-rollback 示例从之前失败的堆栈更新中恢复回滚操作。

aws cloudformation continue-update-rollback \ --stack-name my-stack

此命令不生成任何输出。

以下代码示例显示了如何使用create-change-set

AWS CLI

创建更改集

以下create-change-set示例创建了一个具有该CAPABILITY_IAM功能的更改集。该文件template.yaml是当前文件夹中的一个 AWS CloudFormation 模板,用于定义包含IAM资源的堆栈。

aws cloudformation create-change-set \ --stack-name my-application \ --change-set-name my-change-set \ --template-body file://template.yaml \ --capabilities CAPABILITY_IAM

输出:

{ "Id": "arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/bc9555ba-a949-xmpl-bfb8-f41d04ec5784", "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-application/d0a825a0-e4cd-xmpl-b9fb-061c69e99204" }

以下代码示例显示了如何使用create-stack-instances

AWS CLI

创建堆栈实例

以下create-stack-instances示例在两个账户和四个区域中创建堆栈集的实例。容错设置可确保在所有账户和地区尝试更新,即使某些堆栈无法创建。

aws cloudformation create-stack-instances \ --stack-set-name my-stack-set \ --accounts 123456789012 223456789012 \ --regions us-east-1 us-east-2 us-west-1 us-west-2 \ --operation-preferences FailureToleranceCount=7

输出:

{ "OperationId": "d7995c31-83c2-xmpl-a3d4-e9ca2811563f" }

要创建堆栈集,请使用create-stack-set命令。

以下代码示例显示了如何使用create-stack-set

AWS CLI

创建堆栈集

以下create-stack-set示例使用指定的YAML文件模板创建堆栈集。 template.yaml是当前文件夹中用于定义堆栈的 AWS CloudFormation 模板。

aws cloudformation create-stack-set \ --stack-set-name my-stack-set \ --template-body file://template.yaml \ --description "SNS topic"

输出:

{ "StackSetId": "my-stack-set:8d0f160b-d157-xmpl-a8e6-c0ce8e5d8cc1" }

要将堆栈实例添加到堆栈集中,请使用create-stack-instances命令。

以下代码示例显示了如何使用create-stack

AWS CLI

创建 AWS CloudFormation 堆栈

以下 create-stacks 命令使用 sampletemplate.json 模板创建了名为 myteststack 的堆栈:

aws cloudformation create-stack --stack-name myteststack --template-body file://sampletemplate.json --parameters ParameterKey=KeyPairName,ParameterValue=TestKey ParameterKey=SubnetIDs,ParameterValue=SubnetID1\\,SubnetID2

输出:

{ "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896" }

有关更多信息,请参阅AWS CloudFormation 用户指南中的堆栈。

以下代码示例显示了如何使用deactivate-type

AWS CLI

停用文字

以下deactivate-type示例停用了先前在此账户和区域中激活的公共扩展程序。

aws cloudformation deactivate-type \ --region us-west-2 \ --type MODULE \ --type-name Example::Test::Type::MODULE

此命令不生成任何输出。

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用delete-change-set

AWS CLI

删除更改集

以下delete-change-set示例通过指定更改集名称和堆栈名称来删除更改集。

aws cloudformation delete-change-set \ --stack-name my-stack \ --change-set-name my-change-set

此命令不生成任何输出。

以下delete-change-set示例通过指定更改集ARN的完整内容来删除更改集。

aws cloudformation delete-change-set \ --change-set-name arn:aws:cloudformation:us-east-2:123456789012:changeSet/my-change-set/4eca1a01-e285-xmpl-8026-9a1967bfb4b0

此命令不生成任何输出。

以下代码示例显示了如何使用delete-stack-instances

AWS CLI

删除堆栈实例

以下delete-stack-instances示例删除两个区域中两个账户中的堆栈集实例并终止堆栈。

aws cloudformation delete-stack-instances \ --stack-set-name my-stack-set \ --accounts 123456789012 567890123456 \ --regions us-east-1 us-west-1 \ --no-retain-stacks

输出:

{ "OperationId": "ad49f10c-fd1d-413f-a20a-8de6e2fa8f27" }

要删除空堆栈集,请使用delete-stack-set命令。

以下代码示例显示了如何使用delete-stack-set

AWS CLI

删除堆栈集

以下命令删除指定的空堆栈集。堆栈集必须为空。

aws cloudformation delete-stack-set \ --stack-set-name my-stack-set

此命令不生成任何输出。

要从堆栈集中删除实例,请使用delete-stack-instances命令。

以下代码示例显示了如何使用delete-stack

AWS CLI

删除堆栈

以下 delete-stack 示例将删除指定的堆栈。

aws cloudformation delete-stack \ --stack-name my-stack

此命令不生成任何输出。

以下代码示例显示了如何使用deploy

AWS CLI

以下命令将名为的模板部署template.json到名为的堆栈中:my-new-stack

aws cloudformation deploy --template-file /path_to_template/template.json --stack-name my-new-stack --parameter-overrides Key1=Value1 Key2=Value2 --tags Key1=Value1 Key2=Value2
  • 有关API详细信息,请参阅《AWS CLI 命令参考》中的 “部署”。

以下代码示例显示了如何使用deregister-type

AWS CLI

取消注册类型版本

以下deregister-type示例将指定类型的版本从 CloudFormation 注册表中移除,使其无法再用于 CloudFormation 操作。

aws cloudformation deregister-type \ --type RESOURCE \ --type-name My::Logs::LogGroup \ --version-id 00000002

此命令不生成任何输出。

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 CloudFormation 注册表

以下代码示例显示了如何使用describe-account-limits

AWS CLI

获取有关您的账户限额的信息

以下命令检索当前账户的区域限制列表。

aws cloudformation describe-account-limits

输出:

{ "AccountLimits": [ { "Name": "StackLimit", "Value": 200 }, { "Name": "StackOutputsLimit", "Value": 60 }, { "Name": "ConcurrentResourcesLimit", "Value": 2500 } ] }

以下代码示例显示了如何使用describe-change-set

AWS CLI

获取有关变更集的信息

以下describe-change-set示例显示了由更改集名称和堆栈名称指定的更改集的详细信息。

aws cloudformation describe-change-set \ --change-set-name my-change-set \ --stack-name my-stack

以下describe-change-set示例显示由变更集的完整ARN部分指定的变更集的详细信息:

aws cloudformation describe-change-set \ --change-set-name arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/bc9555ba-a949-xmpl-bfb8-f41d04ec5784

输出:

{ "Changes": [ { "Type": "Resource", "ResourceChange": { "Action": "Modify", "LogicalResourceId": "function", "PhysicalResourceId": "my-function-SEZV4XMPL4S5", "ResourceType": "AWS::Lambda::Function", "Replacement": "False", "Scope": [ "Properties" ], "Details": [ { "Target": { "Attribute": "Properties", "Name": "Timeout", "RequiresRecreation": "Never" }, "Evaluation": "Static", "ChangeSource": "DirectModification" } ] } } ], "ChangeSetName": "my-change-set", "ChangeSetId": "arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/4eca1a01-e285-xmpl-8026-9a1967bfb4b0", "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "StackName": "my-stack", "Description": null, "Parameters": null, "CreationTime": "2019-10-02T05:20:56.651Z", "ExecutionStatus": "AVAILABLE", "Status": "CREATE_COMPLETE", "StatusReason": null, "NotificationARNs": [], "RollbackConfiguration": {}, "Capabilities": [ "CAPABILITY_IAM" ], "Tags": null }

以下代码示例显示了如何使用describe-publisher

AWS CLI

描述出版商

以下describe-publisher示例为发布者配置信息。

aws cloudformation describe-publisher \ --region us-west-2 \ --publisher-id 000q6TfUovXsEMmgKowxDZLlwqr2QUsh

输出:

{ "PublisherId": "000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c", "PublisherStatus": "VERIFIED", "IdentityProvider": "AWS_Marketplace", "PublisherProfile": "https://aws.amazon.com/marketplace/seller-profile?id=2c5dc1f0-17cd-4259-8e46-822a83gdtegd" }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用describe-stack-drift-detection-status

AWS CLI

检查偏移检测操作的状态

以下describe-stack-drift-detection-status示例显示了偏差检测操作的状态。获取运行detect-stack-drift命令的 by ID。

aws cloudformation describe-stack-drift-detection-status \ --stack-drift-detection-id 1a229160-e4d9-xmpl-ab67-0a4f93df83d4

输出:

{ "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "StackDriftDetectionId": "1a229160-e4d9-xmpl-ab67-0a4f93df83d4", "StackDriftStatus": "DRIFTED", "DetectionStatus": "DETECTION_COMPLETE", "DriftedStackResourceCount": 1, "Timestamp": "2019-10-02T05:54:30.902Z" }

以下代码示例显示了如何使用describe-stack-events

AWS CLI

描述堆栈事件

以下 describe-stack-events 示例显示了指定堆栈的 2 个最新事件。

aws cloudformation describe-stack-events \ --stack-name my-stack \ --max-items 2 { "StackEvents": [ { "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "EventId": "4e1516d0-e4d6-xmpl-b94f-0a51958a168c", "StackName": "my-stack", "LogicalResourceId": "my-stack", "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "ResourceType": "AWS::CloudFormation::Stack", "Timestamp": "2019-10-02T05:34:29.556Z", "ResourceStatus": "UPDATE_COMPLETE" }, { "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "EventId": "4dd3c810-e4d6-xmpl-bade-0aaf8b31ab7a", "StackName": "my-stack", "LogicalResourceId": "my-stack", "PhysicalResourceId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "ResourceType": "AWS::CloudFormation::Stack", "Timestamp": "2019-10-02T05:34:29.127Z", "ResourceStatus": "UPDATE_COMPLETE_CLEANUP_IN_PROGRESS" } ], "NextToken": "eyJOZXh0VG9XMPLiOiBudWxsLCAiYm90b190cnVuY2F0ZV9hbW91bnQiOiAyfQ==" }

以下代码示例显示了如何使用describe-stack-instance

AWS CLI

描述堆栈实例

以下命令描述了指定账户和区域中指定堆栈集的实例。堆栈集在当前区域和账户中,实例在账户中的us-west-2区域中123456789012。 :

aws cloudformation describe-stack-instance \ --stack-set-name my-stack-set \ --stack-instance-account 123456789012 \ --stack-instance-region us-west-2

输出:

{ "StackInstance": { "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743", "Region": "us-west-2", "Account": "123456789012", "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/StackSet-enable-config-e6cac20f-xmpl-46e9-8314-53e0d4591532/4287f9a0-e615-xmpl-894a-12b31d3117be", "ParameterOverrides": [], "Status": "OUTDATED", "StatusReason": "ResourceLogicalId:ConfigBucket, ResourceType:AWS::S3::Bucket, ResourceStatusReason:You have attempted to create more buckets than allowed (Service: Amazon S3; Status Code: 400; Error Code: TooManyBuckets; Request ID: F7F21CXMPL580224; S3 Extended Request ID: egd/Fdt89BXMPLyiqbMNljVk55Yqqvi3NYW2nKLUVWhUGEhNfCmZdyj967lhriaG/dWMobSO40o=)." } }

以下代码示例显示了如何使用describe-stack-resource-drifts

AWS CLI

获取有关偏离堆栈定义的资源的信息

以下命令显示有关指定堆栈的漂移资源的信息。要启动偏移检测,请使用detect-stack-drift命令。 :

aws cloudformation describe-stack-resource-drifts \ --stack-name my-stack

输出显示了一个经过修改的 AWS Lambda 函数: out-of-band

{ "StackResourceDrifts": [ { "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "LogicalResourceId": "function", "PhysicalResourceId": "my-function-SEZV4XMPL4S5", "ResourceType": "AWS::Lambda::Function", "ExpectedProperties": "{\"Description\":\"Write a file to S3.\",\"Environment\":{\"Variables\":{\"bucket\":\"my-stack-bucket-1vc62xmplgguf\"}},\"Handler\":\"index.handler\",\"MemorySize\":128,\"Role\":\"arn:aws:iam::123456789012:role/my-functionRole-HIZXMPLEOM9E\",\"Runtime\":\"nodejs10.x\",\"Tags\":[{\"Key\":\"lambda:createdBy\",\"Value\":\"SAM\"}],\"Timeout\":900,\"TracingConfig\":{\"Mode\":\"Active\"}}", "ActualProperties": "{\"Description\":\"Write a file to S3.\",\"Environment\":{\"Variables\":{\"bucket\":\"my-stack-bucket-1vc62xmplgguf\"}},\"Handler\":\"index.handler\",\"MemorySize\":256,\"Role\":\"arn:aws:iam::123456789012:role/my-functionRole-HIZXMPLEOM9E\",\"Runtime\":\"nodejs10.x\",\"Tags\":[{\"Key\":\"lambda:createdBy\",\"Value\":\"SAM\"}],\"Timeout\":22,\"TracingConfig\":{\"Mode\":\"Active\"}}", "PropertyDifferences": [ { "PropertyPath": "/MemorySize", "ExpectedValue": "128", "ActualValue": "256", "DifferenceType": "NOT_EQUAL" }, { "PropertyPath": "/Timeout", "ExpectedValue": "900", "ActualValue": "22", "DifferenceType": "NOT_EQUAL" } ], "StackResourceDriftStatus": "MODIFIED", "Timestamp": "2019-10-02T05:54:44.064Z" } ] }

以下代码示例显示了如何使用describe-stack-resource

AWS CLI

获取有关堆栈资源的信息

以下 describe-stack-resource 示例显示了指定堆栈中名为 MyFunction 的资源的详细信息。

aws cloudformation describe-stack-resource \ --stack-name MyStack \ --logical-resource-id MyFunction

输出:

{ "StackResourceDetail": { "StackName": "MyStack", "StackId": "arn:aws:cloudformation:us-east-2:123456789012:stack/MyStack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "LogicalResourceId": "MyFunction", "PhysicalResourceId": "my-function-SEZV4XMPL4S5", "ResourceType": "AWS::Lambda::Function", "LastUpdatedTimestamp": "2019-10-02T05:34:27.989Z", "ResourceStatus": "UPDATE_COMPLETE", "Metadata": "{}", "DriftInformation": { "StackResourceDriftStatus": "IN_SYNC" } } }

以下代码示例显示了如何使用describe-stack-resources

AWS CLI

获取有关堆栈资源的信息

以下 describe-stack-resources 示例显示了指定堆栈中的资源详细信息。

aws cloudformation describe-stack-resources \ --stack-name my-stack

输出:

{ "StackResources": [ { "StackName": "my-stack", "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "LogicalResourceId": "bucket", "PhysicalResourceId": "my-stack-bucket-1vc62xmplgguf", "ResourceType": "AWS::S3::Bucket", "Timestamp": "2019-10-02T04:34:11.345Z", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "IN_SYNC" } }, { "StackName": "my-stack", "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "LogicalResourceId": "function", "PhysicalResourceId": "my-function-SEZV4XMPL4S5", "ResourceType": "AWS::Lambda::Function", "Timestamp": "2019-10-02T05:34:27.989Z", "ResourceStatus": "UPDATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "IN_SYNC" } }, { "StackName": "my-stack", "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "LogicalResourceId": "functionRole", "PhysicalResourceId": "my-functionRole-HIZXMPLEOM9E", "ResourceType": "AWS::IAM::Role", "Timestamp": "2019-10-02T04:34:06.350Z", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "IN_SYNC" } } ] }

以下代码示例显示了如何使用describe-stack-set-operation

AWS CLI

获取有关堆栈集操作的信息

以下 describe-stack-set-operation `示例显示了对指定堆栈集执行更新操作的详细信息。

aws cloudformation describe-stack-set-operation \ --stack-set-name enable-config \ --operation-id 35d45ebc-ed88-xmpl-ab59-0197a1fc83a0

输出:

{ "StackSetOperation": { "OperationId": "35d45ebc-ed88-xmpl-ab59-0197a1fc83a0", "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743", "Action": "UPDATE", "Status": "SUCCEEDED", "OperationPreferences": { "RegionOrder": [ "us-east-1", "us-west-2", "eu-west-1", "us-west-1" ], "FailureToleranceCount": 7, "MaxConcurrentCount": 2 }, "AdministrationRoleARN": "arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole", "ExecutionRoleName": "AWSCloudFormationStackSetExecutionRole", "CreationTimestamp": "2019-10-03T16:28:44.377Z", "EndTimestamp": "2019-10-03T16:42:08.607Z" } }

以下代码示例显示了如何使用describe-stack-set

AWS CLI

获取有关堆栈集的信息

以下 describe-stack-set `示例显示有关指定堆栈集的详细信息。

aws cloudformation describe-stack-set \ --stack-set-name my-stack-set

输出:

{ "StackSet": { "StackSetName": "my-stack-set", "StackSetId": "my-stack-set:296a3360-xmpl-40af-be78-9341e95bf743", "Description": "Create an Amazon SNS topic", "Status": "ACTIVE", "TemplateBody": "AWSTemplateFormatVersion: '2010-09-09'\nDescription: An AWS SNS topic\nResources:\n topic:\n Type: AWS::SNS::Topic", "Parameters": [], "Capabilities": [], "Tags": [], "StackSetARN": "arn:aws:cloudformation:us-west-2:123456789012:stackset/enable-config:296a3360-xmpl-40af-be78-9341e95bf743", "AdministrationRoleARN": "arn:aws:iam::123456789012:role/AWSCloudFormationStackSetAdministrationRole", "ExecutionRoleName": "AWSCloudFormationStackSetExecutionRole" } }

以下代码示例显示了如何使用describe-stacks

AWS CLI

描述 AWS CloudFormation 堆栈

以下 describe-stacks 命令显示了 myteststack 堆栈的摘要信息:

aws cloudformation describe-stacks --stack-name myteststack

输出:

{ "Stacks": [ { "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896", "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.", "Tags": [], "Outputs": [ { "Description": "Name of S3 bucket to hold website content", "OutputKey": "BucketName", "OutputValue": "myteststack-s3bucket-jssofi1zie2w" } ], "StackStatusReason": null, "CreationTime": "2013-08-23T01:02:15.422Z", "Capabilities": [], "StackName": "myteststack", "StackStatus": "CREATE_COMPLETE", "DisableRollback": false } ] }

有关更多信息,请参阅AWS CloudFormation 用户指南中的堆栈。

以下代码示例显示了如何使用describe-type-registration

AWS CLI

显示类型注册信息

以下describe-type-registration示例显示有关指定类型注册的信息,包括该类型的当前状态、类型和版本。

aws cloudformation describe-type-registration \ --registration-token a1b2c3d4-5678-90ab-cdef-EXAMPLE11111

输出:

{ "ProgressStatus": "COMPLETE", "TypeArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Logs-LogGroup", "Description": "Deployment is currently in DEPLOY_STAGE of status COMPLETED; ", "TypeVersionArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Logs-LogGroup/00000001" }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 CloudFormation 注册表

以下代码示例显示了如何使用describe-type

AWS CLI

显示类型信息

以下describe-type示例显示了指定类型的信息。

aws cloudformation describe-type \ --type-name My::Logs::LogGroup \ --type RESOURCE

输出:

{ "SourceUrl": "https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs.git", "Description": "Customized resource derived from AWS::Logs::LogGroup", "TimeCreated": "2019-12-03T23:29:33.321Z", "Visibility": "PRIVATE", "TypeName": "My::Logs::LogGroup", "LastUpdated": "2019-12-03T23:29:33.321Z", "DeprecatedStatus": "LIVE", "ProvisioningType": "FULLY_MUTABLE", "Type": "RESOURCE", "Arn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Logs-LogGroup/00000001", "Schema": "[details omitted]" }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 CloudFormation 注册表

以下代码示例显示了如何使用detect-stack-drift

AWS CLI

检测漂移的资源

以下detect-stack-drift示例启动指定堆栈的偏差检测。

aws cloudformation detect-stack-drift \ --stack-name my-stack

输出:

{ "StackDriftDetectionId": "1a229160-e4d9-xmpl-ab67-0a4f93df83d4" }

然后,您可以将此 ID 与describe-stack-resource-drifts命令一起使用来描述漂移的资源。

以下代码示例显示了如何使用detect-stack-resource-drift

AWS CLI

检测资源的偏差

以下detect-stack-resource-drift示例检查在名为 drift 的堆栈MyFunction中命MyStack名的资源:

aws cloudformation detect-stack-resource-drift \ --stack-name MyStack \ --logical-resource-id MyFunction

输出显示了一个经过修改的 AWS Lambda 函数: out-of-band

{ "StackResourceDrift": { "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/MyStack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "LogicalResourceId": "MyFunction", "PhysicalResourceId": "my-function-SEZV4XMPL4S5", "ResourceType": "AWS::Lambda::Function", "ExpectedProperties": "{\"Description\":\"Write a file to S3.\",\"Environment\":{\"Variables\":{\"bucket\":\"my-stack-bucket-1vc62xmplgguf\"}},\"Handler\":\"index.handler\",\"MemorySize\":128,\"Role\":\"arn:aws:iam::123456789012:role/my-functionRole-HIZXMPLEOM9E\",\"Runtime\":\"nodejs10.x\",\"Tags\":[{\"Key\":\"lambda:createdBy\",\"Value\":\"SAM\"}],\"Timeout\":900,\"TracingConfig\":{\"Mode\":\"Active\"}}", "ActualProperties": "{\"Description\":\"Write a file to S3.\",\"Environment\":{\"Variables\":{\"bucket\":\"my-stack-bucket-1vc62xmplgguf\"}},\"Handler\":\"index.handler\",\"MemorySize\":256,\"Role\":\"arn:aws:iam::123456789012:role/my-functionRole-HIZXMPLEOM9E\",\"Runtime\":\"nodejs10.x\",\"Tags\":[{\"Key\":\"lambda:createdBy\",\"Value\":\"SAM\"}],\"Timeout\":22,\"TracingConfig\":{\"Mode\":\"Active\"}}", "PropertyDifferences": [ { "PropertyPath": "/MemorySize", "ExpectedValue": "128", "ActualValue": "256", "DifferenceType": "NOT_EQUAL" }, { "PropertyPath": "/Timeout", "ExpectedValue": "900", "ActualValue": "22", "DifferenceType": "NOT_EQUAL" } ], "StackResourceDriftStatus": "MODIFIED", "Timestamp": "2019-10-02T05:58:47.433Z" } }

以下代码示例显示了如何使用detect-stack-set-drift

AWS CLI

检测堆栈集和所有关联堆栈实例上的偏差

以下detect-stack-set-drift示例在指定的堆栈集(包括与该堆栈集关联的所有堆栈实例)上启动偏差检测操作,并返回一个可用于跟踪偏移操作状态的操作 ID。

aws cloudformation detect-stack-set-drift \ --stack-set-name stack-set-drift-example

输出:

{ "OperationId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }

有关更多信息,请参阅《AWS CloudFormation 用户指南》中的 “检测堆栈集中的非托管配置更改”。

以下代码示例显示了如何使用estimate-template-cost

AWS CLI

估算模板成本

以下 estimate-template-cost 示例为当前文件夹中名为 template.yaml 的模板生成了成本估算。

aws cloudformation estimate-template-cost \ --template-body file://template.yaml

输出:

{ "Url": "http://calculator.s3.amazonaws.com/calc5.html?key=cloudformation/7870825a-xmpl-4def-92e7-c4f8dd360cca" }

以下代码示例显示了如何使用execute-change-set

AWS CLI

执行更改集

以下execute-change-set示例执行由更改集名称和堆栈名称指定的更改集。

aws cloudformation execute-change-set \ --change-set-name my-change-set \ --stack-name my-stack

以下execute-change-set示例执行由变更集的完整ARN部分指定的变更集。

aws cloudformation execute-change-set \ --change-set-name arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/bc9555ba-a949-xmpl-bfb8-f41d04ec5784

以下代码示例显示了如何使用get-stack-policy

AWS CLI

查看堆栈策略

以下get-stack-policy示例显示了指定堆栈的堆栈策略。要将策略附加到堆栈,请使用set-stack-policy命令。

aws cloudformation get-stack-policy \ --stack-name my-stack

输出:

{ "StackPolicyBody": "{\n \"Statement\" : [\n {\n \"Effect\" : \"Allow\",\n \"Action\" : \"Update:*\",\n \"Principal\": \"*\",\n \"Resource\" : \"*\"\n },\n {\n \"Effect\" : \"Deny\",\n \"Action\" : \"Update:*\",\n \"Principal\": \"*\",\n \"Resource\" : \"LogicalResourceId/bucket\"\n }\n ]\n}\n" }

以下代码示例显示了如何使用get-template-summary

AWS CLI

显示模板摘要

以下命令显示有关指定模板文件的资源和元数据的摘要信息。

aws cloudformation get-template-summary \ --template-body file://template.yaml

输出:

{ "Parameters": [], "Description": "A VPC and subnets.", "ResourceTypes": [ "AWS::EC2::VPC", "AWS::EC2::Subnet", "AWS::EC2::Subnet", "AWS::EC2::RouteTable", "AWS::EC2::VPCEndpoint", "AWS::EC2::SubnetRouteTableAssociation", "AWS::EC2::SubnetRouteTableAssociation", "AWS::EC2::VPCEndpoint" ], "Version": "2010-09-09" }

以下代码示例显示了如何使用get-template

AWS CLI

查看 AWS CloudFormation 堆栈的模板正文

以下 get-template 命令显示了 myteststack 堆栈的模板:

aws cloudformation get-template --stack-name myteststack

输出:

{ "TemplateBody": { "AWSTemplateFormatVersion": "2010-09-09", "Outputs": { "BucketName": { "Description": "Name of S3 bucket to hold website content", "Value": { "Ref": "S3Bucket" } } }, "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.", "Resources": { "S3Bucket": { "Type": "AWS::S3::Bucket", "Properties": { "AccessControl": "PublicRead" } } } } }

以下代码示例显示了如何使用list-change-sets

AWS CLI

列出变更集

以下list-change-sets示例显示了指定堆栈的待处理更改集列表。

aws cloudformation list-change-sets \ --stack-name my-stack

输出:

{ "Summaries": [ { "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204", "StackName": "my-stack", "ChangeSetId": "arn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/70160340-7914-xmpl-bcbf-128a1fa78b5d", "ChangeSetName": "my-change-set", "ExecutionStatus": "AVAILABLE", "Status": "CREATE_COMPLETE", "CreationTime": "2019-10-02T05:38:54.297Z" } ] }

以下代码示例显示了如何使用list-exports

AWS CLI

列出导出

以下list-exports示例显示了当前区域堆栈的导出列表。

aws cloudformation list-exports

输出:

{ "Exports": [ { "ExportingStackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/private-vpc/99764070-b56c-xmpl-bee8-062a88d1d800", "Name": "private-vpc-subnet-a", "Value": "subnet-07b410xmplddcfa03" }, { "ExportingStackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/private-vpc/99764070-b56c-xmpl-bee8-062a88d1d800", "Name": "private-vpc-subnet-b", "Value": "subnet-075ed3xmplebd2fb1" }, { "ExportingStackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/private-vpc/99764070-b56c-xmpl-bee8-062a88d1d800", "Name": "private-vpc-vpcid", "Value": "vpc-011d7xmpl100e9841" } ] }

以下代码示例显示了如何使用list-imports

AWS CLI

列出进口商品

以下list-imports示例列出了导入指定导出的堆栈。要获取可用导出的列表,请使用list-exports命令。

aws cloudformation list-imports \ --export-name private-vpc-vpcid

输出:

{ "Imports": [ "my-database-stack" ] }

以下代码示例显示了如何使用list-stack-instances

AWS CLI

列出堆栈的实例

以下list-stack-instances示例列出了根据指定堆栈集创建的实例。

aws cloudformation list-stack-instances \ --stack-set-name enable-config

示例输出包括有关由于错误而无法更新的堆栈的详细信息:

{ "Summaries": [ { "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743", "Region": "us-west-2", "Account": "123456789012", "StackId": "arn:aws:cloudformation:ap-northeast-1:123456789012:stack/StackSet-enable-config-35a6ac50-d9f8-4084-86e4-7da34d5de4c4/a1631cd0-e5fb-xmpl-b474-0aa20f14f06e", "Status": "CURRENT" }, { "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743", "Region": "us-west-2", "Account": "123456789012", "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/StackSet-enable-config-e6cac20f-xmpl-46e9-8314-53e0d4591532/eab53680-e5fa-xmpl-ba14-0a522351f81e", "Status": "OUTDATED", "StatusReason": "ResourceLogicalId:ConfigDeliveryChannel, ResourceType:AWS::Config::DeliveryChannel, ResourceStatusReason:Failed to put delivery channel 'StackSet-enable-config-e6cac20f-xmpl-46e9-8314-53e0d4591532-ConfigDeliveryChannel-1OJWJ7XD59WR0' because the maximum number of delivery channels: 1 is reached. (Service: AmazonConfig; Status Code: 400; Error Code: MaxNumberOfDeliveryChannelsExceededException; Request ID: d14b34a0-ef7c-xmpl-acf8-8a864370ae56)." } ] }

以下代码示例显示了如何使用list-stack-resources

AWS CLI

列出堆栈中的资源

以下命令显示了指定堆栈中的资源列表。

aws cloudformation list-stack-resources \ --stack-name my-stack

输出:

{ "StackResourceSummaries": [ { "LogicalResourceId": "bucket", "PhysicalResourceId": "my-stack-bucket-1vc62xmplgguf", "ResourceType": "AWS::S3::Bucket", "LastUpdatedTimestamp": "2019-10-02T04:34:11.345Z", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "IN_SYNC" } }, { "LogicalResourceId": "function", "PhysicalResourceId": "my-function-SEZV4XMPL4S5", "ResourceType": "AWS::Lambda::Function", "LastUpdatedTimestamp": "2019-10-02T05:34:27.989Z", "ResourceStatus": "UPDATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "IN_SYNC" } }, { "LogicalResourceId": "functionRole", "PhysicalResourceId": "my-functionRole-HIZXMPLEOM9E", "ResourceType": "AWS::IAM::Role", "LastUpdatedTimestamp": "2019-10-02T04:34:06.350Z", "ResourceStatus": "CREATE_COMPLETE", "DriftInformation": { "StackResourceDriftStatus": "IN_SYNC" } } ] }

以下代码示例显示了如何使用list-stack-set-operation-results

AWS CLI

列出堆栈集操作结果

以下命令显示对指定堆栈集中的实例执行更新操作的结果。

aws cloudformation list-stack-set-operation-results \ --stack-set-name enable-config \ --operation-id 35d45ebc-ed88-xmpl-ab59-0197a1fc83a0

输出:

{ "Summaries": [ { "Account": "223456789012", "Region": "us-west-2", "Status": "SUCCEEDED", "AccountGateResult": { "Status": "SKIPPED", "StatusReason": "Function not found: arn:aws:lambda:eu-west-1:223456789012:function:AWSCloudFormationStackSetAccountGate" } }, { "Account": "223456789012", "Region": "ap-south-1", "Status": "CANCELLED", "StatusReason": "Cancelled since failure tolerance has exceeded" } ] }

注意:除非您创建账户门禁函数,否则的SKIPPED状态为AccountGateResult成功操作的预期。

以下代码示例显示了如何使用list-stack-set-operations

AWS CLI

列出堆栈集操作

以下list-stack-set-operations示例显示了对指定堆栈集的最新操作列表。

aws cloudformation list-stack-set-operations \ --stack-set-name my-stack-set

输出:

{ "Summaries": [ { "OperationId": "35d45ebc-ed88-xmpl-ab59-0197a1fc83a0", "Action": "UPDATE", "Status": "SUCCEEDED", "CreationTimestamp": "2019-10-03T16:28:44.377Z", "EndTimestamp": "2019-10-03T16:42:08.607Z" }, { "OperationId": "891aa98f-7118-xmpl-00b2-00954d1dd0d6", "Action": "UPDATE", "Status": "FAILED", "CreationTimestamp": "2019-10-03T15:43:53.916Z", "EndTimestamp": "2019-10-03T15:45:58.925Z" } ] }

以下代码示例显示了如何使用list-stack-sets

AWS CLI

列出堆栈集

以下list-stack-sets示例显示了当前区域和账户中的堆栈集列表。

aws cloudformation list-stack-sets

输出:

{ "Summaries": [ { "StackSetName": "enable-config", "StackSetId": "enable-config:296a3360-xmpl-40af-be78-9341e95bf743", "Description": "Enable AWS Config", "Status": "ACTIVE" } ] }

以下代码示例显示了如何使用list-stacks

AWS CLI

列出 AWS CloudFormation 堆栈

以下 list-stacks 命令显示了具有 CREATE_COMPLETE 状态的所有堆栈的摘要信息:

aws cloudformation list-stacks --stack-status-filter CREATE_COMPLETE

输出:

[ { "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896", "TemplateDescription": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.", "StackStatusReason": null, "CreationTime": "2013-08-26T03:27:10.190Z", "StackName": "myteststack", "StackStatus": "CREATE_COMPLETE" } ]

以下代码示例显示了如何使用list-type-registrations

AWS CLI

列出某一类型的已完成注册

以下list-type-registrations示例显示了指定类型的已完成类型注册的列表。

aws cloudformation list-type-registrations \ --type RESOURCE \ --type-name My::Logs::LogGroup \ --registration-status-filter COMPLETE

输出:

{ "RegistrationTokenList": [ "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333" ] }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 CloudFormation 注册表

以下代码示例显示了如何使用list-type-versions

AWS CLI

列出扩展程序的版本

以下list-type-versions示例返回有关扩展版本的摘要信息。

aws cloudformation list-type-versions \ --endpoint https://example.com \ --region us-west-2 \ --type RESOURCE \ --type-name My::Resource::Example \ --publisher-id 123456789012

此命令不生成任何输出。

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用list-types

AWS CLI

列出账户中的私有资源类型

以下list-types示例显示当前在当前 AWS 账户中注册的私有资源类型的列表。

aws cloudformation list-types

输出:

{ "TypeSummaries": [ { "Description": "WordPress blog resource for internal use", "LastUpdated": "2019-12-04T18:28:15.059Z", "TypeName": "My::WordPress::BlogExample", "TypeArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-WordPress-BlogExample", "DefaultVersionId": "00000005", "Type": "RESOURCE" }, { "Description": "Customized resource derived from AWS::Logs::LogGroup", "LastUpdated": "2019-12-04T18:28:15.059Z", "TypeName": "My::Logs::LogGroup", "TypeArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/My-Logs-LogGroup", "DefaultVersionId": "00000003", "Type": "RESOURCE" } ] }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 CloudFormation 注册表

以下代码示例显示了如何使用package

AWS CLI

以下命令将template.json通过将本地项目上传到 S3 存储桶来导出一个名为的模板,bucket-name并将导出的模板写入到packaged-template.json

aws cloudformation package --template-file /path_to_template/template.json --s3-bucket bucket-name --output-template-file packaged-template.json --use-json
  • 有关API详细信息,请参阅《AWS CLI 命令参考》中的 Pack ag e。

以下代码示例显示了如何使用publish-type

AWS CLI

发布扩展

以下publish-type示例将指定的扩展作为该区域的公共扩展发布到 CloudFormation 注册表。

aws cloudformation publish-type \ --region us-west-2 \ --type RESOURCE \ --type-name Example::Test::1234567890abcdef0

输出:

{ "PublicTypeArn":"arn:aws:cloudformation:us-west-2::type/resource/000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c/Example-Test-1234567890abcdef0/1.0.0" }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用register-publisher

AWS CLI

注册出版商

以下register-publisher示例注册发布者并接受条款和条件参数。

aws cloudformation register-publisher \ --region us-west-2 \ --accept-terms-and-conditions

输出:

{ "PublisherId": "000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c" }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用register-type

AWS CLI

注册资源类型

以下register-type示例将指定的资源类型注册为用户账户中的私有资源类型。

aws cloudformation register-type \ --type-name My::Organization::ResourceName \ --schema-handler-package s3://bucket_name/my-organization-resource_name.zip \ --type RESOURCE

输出:

{ "RegistrationToken": "f5525280-104e-4d35-bef5-8f1f1example" }

有关更多信息,请参阅《类型开发CloudFormation 命令行界面用户指南》中的注册资源提供者

以下代码示例显示了如何使用set-stack-policy

AWS CLI

应用堆栈策略

以下set-stack-policy示例禁用指定堆栈中指定资源的更新。 stack-policy.json是一JSON份定义允许对堆栈中资源执行的操作的文档。

aws cloudformation set-stack-policy \ --stack-name my-stack \ --stack-policy-body file://stack-policy.json

输出:

{ "Statement" : [ { "Effect" : "Allow", "Action" : "Update:*", "Principal": "*", "Resource" : "*" }, { "Effect" : "Deny", "Action" : "Update:*", "Principal": "*", "Resource" : "LogicalResourceId/bucket" } ] }

以下代码示例显示了如何使用set-type-configuration

AWS CLI

配置数据

以下set-type-configuration示例指定了给定账户和区域中已注册的 CloudFormation 扩展程序的配置数据。

aws cloudformation set-type-configuration \ --region us-west-2 \ --type RESOURCE \ --type-name Example::Test::Type \ --configuration-alias default \ --configuration "{\"CredentialKey\": \"testUserCredential\"}"

输出:

{ "ConfigurationArn": "arn:aws:cloudformation:us-west-2:123456789012:type-configuration/resource/Example-Test-Type/default" }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用set-type-default-version

AWS CLI

设置类型的默认版本

以下set-type-default-version示例将指定类型的版本设置为该类型的默认版本。

aws cloudformation set-type-default-version \ --type RESOURCE \ --type-name My::Logs::LogGroup \ --version-id 00000003

此命令不生成任何输出。

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 CloudFormation 注册表

以下代码示例显示了如何使用signal-resource

AWS CLI

向资源发出信号

以下signal-resource示例表示满足名success为的堆栈MyWaitCondition中命名的等待条件my-stack

aws cloudformation signal-resource \ --stack-name my-stack \ --logical-resource-id MyWaitCondition \ --unique-id 1234 \ --status SUCCESS

此命令不生成任何输出。

以下代码示例显示了如何使用stop-stack-set-operation

AWS CLI

停止堆栈集操作

以下stop-stack-set-operation示例停止了对指定堆栈集的正在进行的更新操作。

aws cloudformation stop-stack-set-operation \ --stack-set-name my-stack-set \ --operation-id 1261cd27-490b-xmpl-ab42-793a896c69e6

此命令不生成任何输出。

以下代码示例显示了如何使用test-type

AWS CLI

测试扩展

以下test-type示例测试已注册的扩展,以确保其满足在注册 CloudFormation 表中发布的所有必要要求。

aws cloudformation test-type \ --arn arn:aws:cloudformation:us-west-2:123456789012:type/resource/Sample-Test-Resource123/00000001

输出:

{ "TypeVersionArn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/Sample-Test-Resource123/00000001" }

有关更多信息,请参阅AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 注册表

以下代码示例显示了如何使用update-stack-instances

AWS CLI

更新堆栈实例

以下update-stack-instances示例使用最新设置重试两个区域中两个账户的堆栈实例的更新。指定的容错设置可确保在所有账户和地区尝试更新,即使某些堆栈无法更新。

aws cloudformation update-stack-instances \ --stack-set-name my-stack-set \ --accounts 123456789012 567890123456 \ --regions us-east-1 us-west-2 \ --operation-preferences FailureToleranceCount=3

输出:

{ "OperationId": "103ebdf2-21ea-xmpl-8892-de5e30733132" }

以下代码示例显示了如何使用update-stack-set

AWS CLI

更新堆栈集

以下update-stack-set示例向指定堆栈集中的堆栈实例添加一个密钥名称Owner和值为的标签。IT

aws cloudformation update-stack-set \ --stack-set-name my-stack-set \ --use-previous-template \ --tags Key=Owner,Value=IT

输出:

{ "OperationId": "e2b60321-6cab-xmpl-bde7-530c6f47950e" }

以下代码示例显示了如何使用update-stack

AWS CLI

更新 AWS CloudFormation 堆栈

以下 update-stack 命令更新了 mystack 堆栈的模板和输入参数:

aws cloudformation update-stack --stack-name mystack --template-url https://s3.amazonaws.com/sample/updated.template --parameters ParameterKey=KeyPairName,ParameterValue=SampleKeyPair ParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,SampleSubnetID2

以下 update-stack 命令更新了 mystack 堆栈的 SubnetIDs 参数值:如果您没有指定参数值,则将使用模板中指定的默认值:

aws cloudformation update-stack --stack-name mystack --template-url https://s3.amazonaws.com/sample/updated.template --parameters ParameterKey=KeyPairName,UsePreviousValue=true ParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,UpdatedSampleSubnetID2

以下 update-stack 命令向 mystack 堆栈添加了两个堆栈通知主题:

aws cloudformation update-stack --stack-name mystack --use-previous-template --notification-arns "arn:aws:sns:use-east-1:123456789012:mytopic1" "arn:aws:sns:us-east-1:123456789012:mytopic2"

有关更多信息,请参阅《AWS CloudFormation 用户指南》中的AWS CloudFormation 堆栈更新

以下代码示例显示了如何使用update-termination-protection

AWS CLI

启用终止保护

以下update-termination-protection示例在指定堆栈上启用终止保护。

aws cloudformation update-termination-protection \ --stack-name my-stack \ --enable-termination-protection

输出:

{ "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204" }

以下代码示例显示了如何使用validate-template

AWS CLI

验证 AWS CloudFormation 模板

以下 validate-template 命令将验证 sampletemplate.json 模板:

aws cloudformation validate-template --template-body file://sampletemplate.json

输出:

{ "Description": "AWS CloudFormation Sample Template S3_Bucket: Sample template showing how to create a publicly accessible S3 bucket. **WARNING** This template creates an S3 bucket. You will be billed for the AWS resources used if you create a stack from this template.", "Parameters": [], "Capabilities": [] }

有关更多信息,请参阅《AWS CloudFormation 用户指南》中的使用 AWS CloudFormation 模板。