本文档仅适用于 Amazon CLI 版本 1。有关 Amazon CLI 版本 2 的相关文档,请参阅版本 2 用户指南。
使用 Amazon CLI 的 Amazon CloudFormation示例
以下代码示例演示了如何通过将 Amazon Command Line Interface与 Amazon CloudFormation 结合使用,来执行操作和实现常见场景。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
每个示例都包含一个指向完整源代码的链接,您可以从中找到有关如何在上下文中设置和运行代码的说明。
主题
操作
以下代码示例演示了如何使用 activate-type。
- Amazon CLI
-
激活类型
以下
activate-type示例激活公有第三方扩展,使其可用于堆栈模板。aws cloudformation activate-type \ --regionus-west-2\ --typeRESOURCE\ --type-nameExample::Test::1234567890abcdef0\ --type-name-aliasExample::Test::Alias输出:
{ "Arn": "arn:aws:cloudformation:us-west-2:123456789012:type/resource/Example-Test-Alias" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ActivateType
。
-
以下代码示例演示了如何使用 batch-describe-type-configurations。
- Amazon CLI
-
批量描述类型配置
以下
batch-describe-type-configurations示例配置特定类型的数据。aws cloudformation batch-describe-type-configurations \ --regionus-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" } ] }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 BatchDescribeTypeConfigurations
。
-
以下代码示例演示了如何使用 cancel-update-stack。
- Amazon CLI
-
取消正在进行的堆栈更新
以下
cancel-update-stack命令会取消myteststack堆栈上的堆栈更新:aws cloudformation cancel-update-stack --stack-namemyteststack-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CancelUpdateStack
。
-
以下代码示例演示了如何使用 continue-update-rollback。
- Amazon CLI
-
重试更新回滚
以下
continue-update-rollback示例从之前失败的堆栈更新中恢复回滚操作。aws cloudformation continue-update-rollback \ --stack-namemy-stack此命令不生成任何输出。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ContinueUpdateRollback
。
-
以下代码示例演示了如何使用 create-change-set。
- Amazon CLI
-
创建更改集
以下
create-change-set示例创建一个具有CAPABILITY_IAM功能的更改集。文件template.yaml是当前文件夹中的 Amazon CloudFormation 模板,用于定义包含 IAM 资源的堆栈。aws cloudformation create-change-set \ --stack-namemy-application\ --change-set-namemy-change-set\ --template-bodyfile://template.yaml\ --capabilitiesCAPABILITY_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" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CreateChangeSet
。
-
以下代码示例演示了如何使用 create-stack-instances。
- Amazon CLI
-
创建堆栈实例
以下
create-stack-instances示例在两个账户和四个区域中创建堆栈集的实例。容错设置可确保在所有账户和地区尝试更新,即使某些堆栈无法创建。aws cloudformation create-stack-instances \ --stack-set-namemy-stack-set\ --accounts123456789012223456789012\ --regionsus-east-1us-east-2us-west-1us-west-2\ --operation-preferencesFailureToleranceCount=7输出:
{ "OperationId": "d7995c31-83c2-xmpl-a3d4-e9ca2811563f" }使用
create-stack-set命令创建堆栈。-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CreateStackInstances
。
-
以下代码示例演示了如何使用 create-stack-set。
- Amazon CLI
-
创建堆栈集
以下
create-stack-set示例使用指定的 YAML 文件模板创建堆栈集。template.yaml是当前文件夹中用于定义堆栈的 Amazon CloudFormation 模板。aws cloudformation create-stack-set \ --stack-set-namemy-stack-set\ --template-bodyfile://template.yaml\ --description"SNS topic"输出:
{ "StackSetId": "my-stack-set:8d0f160b-d157-xmpl-a8e6-c0ce8e5d8cc1" }使用
create-stack-instances命令将堆栈实例添加到堆栈集中。-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CreateStackSet
。
-
以下代码示例演示了如何使用 create-stack。
- Amazon CLI
-
创建 Amazon CloudFormation 堆栈
以下
create-stacks命令将使用sampletemplate.json模板创建名为myteststack的堆栈:aws cloudformation create-stack --stack-namemyteststack--template-bodyfile://sampletemplate.json--parametersParameterKey=KeyPairName,ParameterValue=TestKeyParameterKey=SubnetIDs,ParameterValue=SubnetID1\\,SubnetID2输出:
{ "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/myteststack/466df9e0-0dff-08e3-8e2f-5088487c4896" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的“堆栈”。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 CreateStack
。
-
以下代码示例演示了如何使用 deactivate-type。
- Amazon CLI
-
停用类型
以下
deactivate-type示例停用先前在此账户和区域中激活的公有扩展。aws cloudformation deactivate-type \ --regionus-west-2\ --typeMODULE\ --type-nameExample::Test::Type::MODULE此命令不生成任何输出。
有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeactivateType
。
-
以下代码示例演示了如何使用 delete-change-set。
- Amazon CLI
-
删除更改集
以下
delete-change-set示例通过指定更改集名称和堆栈名称来删除更改集。aws cloudformation delete-change-set \ --stack-namemy-stack\ --change-set-namemy-change-set此命令不生成任何输出。
以下
delete-change-set示例通过指定更改集的完整 ARN 来删除更改集。aws cloudformation delete-change-set \ --change-set-namearn:aws:cloudformation:us-east-2:123456789012:changeSet/my-change-set/4eca1a01-e285-xmpl-8026-9a1967bfb4b0此命令不生成任何输出。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeleteChangeSet
。
-
以下代码示例演示了如何使用 delete-stack-instances。
- Amazon CLI
-
删除堆栈实例
以下
delete-stack-instances示例删除两个区域中两个账户的堆栈集实例,并终止堆栈。aws cloudformation delete-stack-instances \ --stack-set-namemy-stack-set\ --accounts123456789012567890123456\ --regionsus-east-1us-west-1\ --no-retain-stacks输出:
{ "OperationId": "ad49f10c-fd1d-413f-a20a-8de6e2fa8f27" }使用
delete-stack-set命令删除空堆栈集。-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeleteStackInstances
。
-
以下代码示例演示了如何使用 delete-stack-set。
- Amazon CLI
-
删除堆栈集
以下命令删除指定的空堆栈集。堆栈集必须为空。
aws cloudformation delete-stack-set \ --stack-set-namemy-stack-set此命令不生成任何输出。
使用
delete-stack-instances命令从堆栈集中删除实例。-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeleteStackSet
。
-
以下代码示例演示了如何使用 delete-stack。
- Amazon CLI
-
删除堆栈
以下
delete-stack示例删除指定的堆栈。aws cloudformation delete-stack \ --stack-namemy-stack此命令不生成任何输出。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeleteStack
。
-
以下代码示例演示了如何使用 deploy。
- Amazon CLI
-
以下命令会将名为
template.json的模板部署到名为my-new-stack的堆栈中:aws cloudformation deploy --template-file/path_to_template/template.json--stack-namemy-new-stack--parameter-overridesKey1=Value1Key2=Value2--tagsKey1=Value1Key2=Value2-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 Deploy
。
-
以下代码示例演示了如何使用 deregister-type。
- Amazon CLI
-
取消注册类型版本
以下
deregister-type示例会将指定的类型版本从 CloudFormation 注册表中移除,使其无法再在 CloudFormation 操作中使用。aws cloudformation deregister-type \ --typeRESOURCE\ --type-nameMy::Logs::LogGroup\ --version-id00000002此命令不生成任何输出。
有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DeregisterType
。
-
以下代码示例演示了如何使用 describe-account-limits。
- Amazon CLI
-
获取有关您账户限制的信息
以下命令检索当前账户的区域限制列表。
aws cloudformation describe-account-limits输出:
{ "AccountLimits": [ { "Name": "StackLimit", "Value": 200 }, { "Name": "StackOutputsLimit", "Value": 60 }, { "Name": "ConcurrentResourcesLimit", "Value": 2500 } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeAccountLimits
。
-
以下代码示例演示了如何使用 describe-change-set。
- Amazon CLI
-
获取有关更改集的信息
以下
describe-change-set示例显示由更改集名称和堆栈名称指定的更改集的详细信息。aws cloudformation describe-change-set \ --change-set-namemy-change-set\ --stack-namemy-stack以下
describe-change-set示例显示由更改集的完整 ARN 指定的更改集的详细信息:aws cloudformation describe-change-set \ --change-set-namearn: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 }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeChangeSet
。
-
以下代码示例演示了如何使用 describe-publisher。
- Amazon CLI
-
描述发布者
以下
describe-publisher示例配置发布者的信息。aws cloudformation describe-publisher \ --regionus-west-2\ --publisher-id000q6TfUovXsEMmgKowxDZLlwqr2QUsh输出:
{ "PublisherId": "000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c", "PublisherStatus": "VERIFIED", "IdentityProvider": "AWS_Marketplace", "PublisherProfile": "https://aws.amazon.com/marketplace/seller-profile?id=2c5dc1f0-17cd-4259-8e46-822a83gdtegd" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribePublisher
。
-
以下代码示例演示了如何使用 describe-stack-drift-detection-status。
- Amazon CLI
-
检查偏离检测操作的状态
以下
describe-stack-drift-detection-status示例显示偏离检测操作的状态。运行detect-stack-drift命令获取该 ID。aws cloudformation describe-stack-drift-detection-status \ --stack-drift-detection-id1a229160-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" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeStackDriftDetectionStatus
。
-
以下代码示例演示了如何使用 describe-stack-events。
- Amazon CLI
-
描述堆栈事件
以下
describe-stack-events示例显示指定堆栈的 2 个最新事件。aws cloudformation describe-stack-events \ --stack-namemy-stack\ --max-items2{"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=="}-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeStackEvents
。
-
以下代码示例演示了如何使用 describe-stack-instance。
- Amazon CLI
-
描述堆栈实例
以下命令描述指定账户和区域中指定堆栈集的实例。堆栈集在当前区域和账户中,实例在账户
123456789012中的us-west-2区域中:aws cloudformation describe-stack-instance \ --stack-set-namemy-stack-set\ --stack-instance-account123456789012\ --stack-instance-regionus-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=)." } }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeStackInstance
。
-
以下代码示例演示了如何使用 describe-stack-resource-drifts。
- Amazon CLI
-
获取有关偏离堆栈定义的资源的信息
以下命令显示有关指定堆栈中偏离资源的信息。使用
detect-stack-drift命令启动偏离检测:aws cloudformation describe-stack-resource-drifts \ --stack-namemy-stack输出显示了由带外数据修改的 Amazon Lambda 函数:
{ "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" } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeStackResourceDrifts
。
-
以下代码示例演示了如何使用 describe-stack-resource。
- Amazon CLI
-
获取有关堆栈资源的信息
以下
describe-stack-resource示例显示指定堆栈中名为MyFunction的资源的详细信息。aws cloudformation describe-stack-resource \ --stack-nameMyStack\ --logical-resource-idMyFunction输出:
{ "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" } } }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeStackResource
。
-
以下代码示例演示了如何使用 describe-stack-resources。
- Amazon CLI
-
获取有关堆栈资源的信息
以下
describe-stack-resources示例显示指定堆栈中的资源详细信息。aws cloudformation describe-stack-resources \ --stack-namemy-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" } } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeStackResources
。
-
以下代码示例演示了如何使用 describe-stack-set-operation。
- Amazon CLI
-
获取有关堆栈集操作的信息
以下“describe-stack-set-operation`”示例显示对指定堆栈集执行更新操作的详细信息。
aws cloudformation describe-stack-set-operation \ --stack-set-nameenable-config\ --operation-id35d45ebc-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" } }-
有关 API 详细信息,请参阅《Amazon CLI 命令参数》中的 DescribeStackSetOperation
。
-
以下代码示例演示了如何使用 describe-stack-set。
- Amazon CLI
-
获取有关堆栈集的信息
以下“describe-stack-set`”示例显示有关指定堆栈集的详细信息。
aws cloudformation describe-stack-set \ --stack-set-namemy-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" } }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeStackSet
。
-
以下代码示例演示了如何使用 describe-stacks。
- Amazon CLI
-
描述 Amazon CloudFormation 堆栈
以下
describe-stacks命令显示myteststack堆栈的摘要信息:aws cloudformation describe-stacks --stack-namemyteststack输出:
{ "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 } ] }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的“堆栈”。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeStacks
。
-
以下代码示例演示了如何使用 describe-type-registration。
- Amazon CLI
-
显示类型注册信息
以下
describe-type-registration示例显示有关指定类型注册的信息,包括该类型的当前状态、类型和版本。aws cloudformation describe-type-registration \ --registration-tokena1b2c3d4-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" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeTypeRegistration
。
-
以下代码示例演示了如何使用 describe-type。
- Amazon CLI
-
显示类型信息
以下
describe-type示例显示指定类型的信息。aws cloudformation describe-type \ --type-nameMy::Logs::LogGroup\ --typeRESOURCE输出:
{ "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]" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DescribeType
。
-
以下代码示例演示了如何使用 detect-stack-drift。
- Amazon CLI
-
检测偏离的资源
以下
detect-stack-drift示例对指定堆栈启动偏离检测。aws cloudformation detect-stack-drift \ --stack-namemy-stack输出:
{ "StackDriftDetectionId": "1a229160-e4d9-xmpl-ab67-0a4f93df83d4" }然后,您可以将此 ID 与
describe-stack-resource-drifts命令一起使用来描述偏离的资源。-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DetectStackDrift
。
-
以下代码示例演示了如何使用 detect-stack-resource-drift。
- Amazon CLI
-
检测资源的偏离
以下
detect-stack-resource-drift示例检查名为MyStack的堆栈中名为MyFunction的资源是否偏离:aws cloudformation detect-stack-resource-drift \ --stack-nameMyStack\ --logical-resource-idMyFunction输出显示了由带外数据修改的 Amazon Lambda 函数:
{ "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" } }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DetectStackResourceDrift
。
-
以下代码示例演示了如何使用 detect-stack-set-drift。
- Amazon CLI
-
检测堆栈集及其所有关联堆栈实例的偏离
以下
detect-stack-set-drift示例在指定的堆栈集(包括与该堆栈集关联的所有堆栈实例)上启动偏离检测操作,并返回一个可用于跟踪偏离操作状态的操作 ID。aws cloudformation detect-stack-set-drift \ --stack-set-namestack-set-drift-example输出:
{ "OperationId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的检测堆栈集中的非托管配置更改。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 DetectStackSetDrift
。
-
以下代码示例演示了如何使用 estimate-template-cost。
- Amazon CLI
-
估算模板成本
以下
estimate-template-cost示例为当前文件夹中名为template.yaml的模板生成成本估算。aws cloudformation estimate-template-cost \ --template-bodyfile://template.yaml输出:
{ "Url": "http://calculator.s3.amazonaws.com/calc5.html?key=cloudformation/7870825a-xmpl-4def-92e7-c4f8dd360cca" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 EstimateTemplateCost
。
-
以下代码示例演示了如何使用 execute-change-set。
- Amazon CLI
-
执行更改集
以下
execute-change-set示例执行由更改集名称和堆栈名称指定的更改集。aws cloudformation execute-change-set \ --change-set-namemy-change-set\ --stack-namemy-stack以下
execute-change-set示例执行由更改集的完整 ARN 指定的更改集。aws cloudformation execute-change-set \ --change-set-namearn:aws:cloudformation:us-west-2:123456789012:changeSet/my-change-set/bc9555ba-a949-xmpl-bfb8-f41d04ec5784-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ExecuteChangeSet
。
-
以下代码示例演示了如何使用 get-stack-policy。
- Amazon CLI
-
查看堆栈策略
以下
get-stack-policy示例显示指定堆栈的堆栈策略。使用set-stack-policy命令将策略附加到堆栈。aws cloudformation get-stack-policy \ --stack-namemy-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" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 GetStackPolicy
。
-
以下代码示例演示了如何使用 get-template-summary。
- Amazon CLI
-
显示模板摘要
以下命令显示有关指定模板文件的资源和元数据的摘要信息。
aws cloudformation get-template-summary \ --template-bodyfile://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" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 GetTemplateSummary
。
-
以下代码示例演示了如何使用 get-template。
- Amazon CLI
-
查看 Amazon CloudFormation 堆栈的模板正文
以下
get-template命令显示myteststack堆栈的模板:aws cloudformation get-template --stack-namemyteststack输出:
{ "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" } } } } }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 GetTemplate
。
-
以下代码示例演示了如何使用 list-change-sets。
- Amazon CLI
-
列出更改集
以下
list-change-sets示例显示指定堆栈的待处理更改集列表。aws cloudformation list-change-sets \ --stack-namemy-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" } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListChangeSets
。
-
以下代码示例演示了如何使用 list-exports。
- Amazon 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" } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListExports
。
-
以下代码示例演示了如何使用 list-imports。
- Amazon CLI
-
列出导入
以下
list-imports示例列出导入指定导出的堆栈。使用list-exports命令获取可用的导出列表。aws cloudformation list-imports \ --export-nameprivate-vpc-vpcid输出:
{ "Imports": [ "my-database-stack" ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListImports
。
-
以下代码示例演示了如何使用 list-stack-instances。
- Amazon CLI
-
列出堆栈的实例
以下
list-stack-instances示例列出根据指定堆栈集创建的实例。aws cloudformation list-stack-instances \ --stack-set-nameenable-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)." } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListStackInstances
。
-
以下代码示例演示了如何使用 list-stack-resources。
- Amazon CLI
-
列出堆栈中的资源
以下命令显示指定堆栈中的资源列表。
aws cloudformation list-stack-resources \ --stack-namemy-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" } } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListStackResources
。
-
以下代码示例演示了如何使用 list-stack-set-operation-results。
- Amazon CLI
-
列出堆栈集操作结果
以下命令显示对指定堆栈集中的实例执行更新操作的结果。
aws cloudformation list-stack-set-operation-results \ --stack-set-nameenable-config\ --operation-id35d45ebc-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" } ] }注意:除非您创建账户门禁函数,否则
AccountGateResult的SKIPPED状态有望成功操作。-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListStackSetOperationResults
。
-
以下代码示例演示了如何使用 list-stack-set-operations。
- Amazon CLI
-
列出堆栈集操作
以下
list-stack-set-operations示例显示指定堆栈集的最新操作列表。aws cloudformation list-stack-set-operations \ --stack-set-namemy-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" } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListStackSetOperations
。
-
以下代码示例演示了如何使用 list-stack-sets。
- Amazon 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" } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListStackSets
。
-
以下代码示例演示了如何使用 list-stacks。
- Amazon CLI
-
列出 Amazon CloudFormation 堆栈
以下
list-stacks命令显示具有CREATE_COMPLETE状态的所有堆栈的摘要信息:aws cloudformation list-stacks --stack-status-filterCREATE_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" } ]-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListStacks
。
-
以下代码示例演示了如何使用 list-type-registrations。
- Amazon CLI
-
列出某一类型已完成的注册
以下
list-type-registrations示例显示指定类型的已完成类型注册的列表。aws cloudformation list-type-registrations \ --typeRESOURCE\ --type-nameMy::Logs::LogGroup\ --registration-status-filterCOMPLETE输出:
{ "RegistrationTokenList": [ "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111", "a1b2c3d4-5678-90ab-cdef-EXAMPLE22222", "a1b2c3d4-5678-90ab-cdef-EXAMPLE33333" ] }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListTypeRegistrations
。
-
以下代码示例演示了如何使用 list-type-versions。
- Amazon CLI
-
列出扩展的版本
以下
list-type-versions示例返回有关扩展版本的摘要信息。aws cloudformation list-type-versions \ --endpointhttps://example.com\ --regionus-west-2\ --typeRESOURCE\ --type-nameMy::Resource::Example\ --publisher-id123456789012此命令不生成任何输出。
有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListTypeVersions
。
-
以下代码示例演示了如何使用 list-types。
- Amazon CLI
-
列出账户中的私有资源类型
以下
list-types示例显示当前在当前 Amazon 账户中注册的私有资源类型的列表。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" } ] }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 ListTypes
。
-
以下代码示例演示了如何使用 package。
- Amazon CLI
-
以下命令将通过将本地构件上传到 S3 存储桶
bucket-name来导出一个名为template.json的模板,并将导出的模板写入packaged-template.json:aws cloudformation package --template-file/path_to_template/template.json--s3-bucketbucket-name--output-template-filepackaged-template.json--use-json-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 Package
。
-
以下代码示例演示了如何使用 publish-type。
- Amazon CLI
-
发布扩展
以下
publish-type示例会将指定扩展作为此区域中的公有扩展发布到 CloudFormation 注册表。aws cloudformation publish-type \ --regionus-west-2\ --typeRESOURCE\ --type-nameExample::Test::1234567890abcdef0输出:
{ "PublicTypeArn":"arn:aws:cloudformation:us-west-2::type/resource/000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c/Example-Test-1234567890abcdef0/1.0.0" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 PublishType
。
-
以下代码示例演示了如何使用 register-publisher。
- Amazon CLI
-
注册发布者
以下
register-publisher示例注册发布者并接受条款和条件参数。aws cloudformation register-publisher \ --regionus-west-2\ --accept-terms-and-conditions输出:
{ "PublisherId": "000q6TfUovXsEMmgKowxDZLlwqr2QUshd2e75c8c" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 RegisterPublisher
。
-
以下代码示例演示了如何使用 register-type。
- Amazon CLI
-
注册资源类型
以下
register-type示例会将指定的资源类型注册为用户账户中的私有资源类型。aws cloudformation register-type \ --type-nameMy::Organization::ResourceName\ --schema-handler-packages3://bucket_name/my-organization-resource_name.zip\ --typeRESOURCE输出:
{ "RegistrationToken": "f5525280-104e-4d35-bef5-8f1f1example" }有关更多信息,请参阅《CloudFormation 命令行界面类型开发用户指南》中的注册资源提供方。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 RegisterType
。
-
以下代码示例演示了如何使用 set-stack-policy。
- Amazon CLI
-
应用堆栈策略
以下
set-stack-policy示例禁用指定堆栈中指定的资源更新。stack-policy.json是一个 JSON 文档,可定义允许对堆栈中的资源执行的操作。aws cloudformation set-stack-policy \ --stack-namemy-stack\ --stack-policy-bodyfile://stack-policy.json输出:
{ "Statement" : [ { "Effect" : "Allow", "Action" : "Update:*", "Principal": "*", "Resource" : "*" }, { "Effect" : "Deny", "Action" : "Update:*", "Principal": "*", "Resource" : "LogicalResourceId/bucket" } ] }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 SetStackPolicy
。
-
以下代码示例演示了如何使用 set-type-configuration。
- Amazon CLI
-
配置数据
以下
set-type-configuration示例指定给定账户和区域中已注册的 CloudFormation 扩展的配置数据。aws cloudformation set-type-configuration \ --regionus-west-2\ --typeRESOURCE\ --type-nameExample::Test::Type\ --configuration-aliasdefault\ --configuration "{\"CredentialKey\": \"testUserCredential\"}"输出:
{ "ConfigurationArn": "arn:aws:cloudformation:us-west-2:123456789012:type-configuration/resource/Example-Test-Type/default" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 SetTypeConfiguration
。
-
以下代码示例演示了如何使用 set-type-default-version。
- Amazon CLI
-
设置类型的默认版本
以下
set-type-default-version示例会将指定的类型版本设置为该类型的默认版本。aws cloudformation set-type-default-version \ --typeRESOURCE\ --type-nameMy::Logs::LogGroup\ --version-id00000003此命令不生成任何输出。
有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 SetTypeDefaultVersion
。
-
以下代码示例演示了如何使用 signal-resource。
- Amazon CLI
-
发出资源信号
以下
signal-resource示例发出信号success,表示在名为my-stack的堆栈中满足名为MyWaitCondition的等待条件。aws cloudformation signal-resource \ --stack-namemy-stack\ --logical-resource-idMyWaitCondition\ --unique-id1234\ --statusSUCCESS此命令不生成任何输出。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 SignalResource
。
-
以下代码示例演示了如何使用 stop-stack-set-operation。
- Amazon CLI
-
停止堆栈集操作
以下
stop-stack-set-operation示例停止正在对指定堆栈集进行的更新操作。aws cloudformation stop-stack-set-operation \ --stack-set-namemy-stack-set\ --operation-id1261cd27-490b-xmpl-ab42-793a896c69e6此命令不生成任何输出。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 StopStackSetOperation
。
-
以下代码示例演示了如何使用 test-type。
- Amazon CLI
-
测试扩展
以下
test-type示例测试已注册的扩展,以确保其符合在 CloudFormation 注册表中发布的所有必要要求。aws cloudformation test-type \ --arnarn: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" }有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的使用 Amazon CloudFormation 注册表。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 TestType
。
-
以下代码示例演示了如何使用 update-stack-instances。
- Amazon CLI
-
更新堆栈实例
以下
update-stack-instances示例使用最新设置重试两个区域中两个账户的堆栈实例的更新。指定的容错设置可确保在所有账户和地区尝试更新,即使某些堆栈无法更新。aws cloudformation update-stack-instances \ --stack-set-namemy-stack-set\ --accounts123456789012567890123456\ --regionsus-east-1us-west-2\ --operation-preferencesFailureToleranceCount=3输出:
{ "OperationId": "103ebdf2-21ea-xmpl-8892-de5e30733132" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 UpdateStackInstances
。
-
以下代码示例演示了如何使用 update-stack-set。
- Amazon CLI
-
更新堆栈集
以下
update-stack-set示例为指定堆栈集中的堆栈实例添加键名称为Owner和值为IT的标签。aws cloudformation update-stack-set \ --stack-set-namemy-stack-set\ --use-previous-template \ --tagsKey=Owner,Value=IT输出:
{ "OperationId": "e2b60321-6cab-xmpl-bde7-530c6f47950e" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 UpdateStackSet
。
-
以下代码示例演示了如何使用 update-stack。
- Amazon CLI
-
更新 Amazon CloudFormation 堆栈
以下
update-stack命令更新mystack堆栈的模板和输入参数:aws cloudformation update-stack --stack-namemystack--template-urlhttps://s3.amazonaws.com/sample/updated.template--parametersParameterKey=KeyPairName,ParameterValue=SampleKeyPairParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,SampleSubnetID2以下
update-stack命令更新mystack堆栈的SubnetIDs参数值:如果您没有指定参数值,则将使用模板中指定的默认值:aws cloudformation update-stack --stack-namemystack--template-urlhttps://s3.amazonaws.com/sample/updated.template--parametersParameterKey=KeyPairName,UsePreviousValue=trueParameterKey=SubnetIDs,ParameterValue=SampleSubnetID1\\,UpdatedSampleSubnetID2以下
update-stack命令向mystack堆栈添加两个堆栈通知主题:aws cloudformation update-stack --stack-namemystack--use-previous-template --notification-arns"arn:aws:sns:use-east-1:123456789012:mytopic1""arn:aws:sns:us-east-1:123456789012:mytopic2"有关更多信息,请参阅《Amazon CloudFormation 用户指南》中的 Amazon 堆栈更新。
-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 UpdateStack
。
-
以下代码示例演示了如何使用 update-termination-protection。
- Amazon CLI
-
启用终止保护
以下
update-termination-protection示例在指定堆栈上启用终止保护。aws cloudformation update-termination-protection \ --stack-namemy-stack\ --enable-termination-protection输出:
{ "StackId": "arn:aws:cloudformation:us-west-2:123456789012:stack/my-stack/d0a825a0-e4cd-xmpl-b9fb-061c69e99204" }-
有关 API 详细信息,请参阅《Amazon CLI 命令参考》中的 UpdateTerminationProtection
。
-
以下代码示例演示了如何使用 validate-template。
- Amazon CLI
-
验证 Amazon CloudFormation 模板
以下
validate-template命令验证sampletemplate.json模板:aws cloudformation validate-template --template-bodyfile://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": [] }有关更多信息,请参阅《Amazon CloudTrail 用户指南》中的“使用 Amazon CloudFormation 模板”。
-
有关 API 的详细信息,请参阅《Amazon CLI 命令参考》中的 ValidateTemplate
。
-