AWS 文档 SDK 示例
将 EstimateTemplateCost 与 CLI 配合使用
以下代码示例演示如何使用 EstimateTemplateCost。
- CLI
-
- AWS 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 详细信息,请参阅《AWS CLI 命令参考》中的 EstimateTemplateCost
。
-
- PowerShell
-
- Tools for PowerShell V4
-
示例 1:返回一个 AWS 简单月度计算器 URL,其中包含描述运行模板所需资源的查询字符串。模板是从指定的 Amazon S3 URL 获取的,并且应用了单个自定义参数。也可以使用“键”和“值”来指定该参数,而不是“ParameterKey”和“ParameterValue”。
Measure-CFNTemplateCost -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template ` -Region us-west-1 ` -Parameter @{ ParameterKey="KeyName"; ParameterValue="myKeyPairName" }示例 2:返回一个 AWS 简单月度计算器 URL,其中包含描述运行模板所需资源的查询字符串。模板是根据提供的内容解析的,并且应用了自定义参数(此示例假设模板内容会声明“KeyName”和“InstanceType”这两个参数)。也可以使用“键”和“值”来指定自定义参数,而不是“ParameterKey”和“ParameterValue”。
Measure-CFNTemplateCost -TemplateBody "{TEMPLATE CONTENT HERE}" ` -Parameter @( @{ ParameterKey="KeyName"; ParameterValue="myKeyPairName" },` @{ ParameterKey="InstanceType"; ParameterValue="m1.large" })示例 3:使用 New-Object 来构建一组模板参数,并返回一个 AWS 简单月度计算器 URL,其中包含描述运行模板所需资源的查询字符串。模板是根据提供的内容解析的,并且包含自定义参数(此示例假设模板内容会声明“KeyName”和“InstanceType”这两个参数)。
$p1 = New-Object -Type Amazon.CloudFormation.Model.Parameter $p1.ParameterKey = "KeyName" $p1.ParameterValue = "myKeyPairName" $p2 = New-Object -Type Amazon.CloudFormation.Model.Parameter $p2.ParameterKey = "InstanceType" $p2.ParameterValue = "m1.large" Measure-CFNTemplateCost -TemplateBody "{TEMPLATE CONTENT HERE}" -Parameter @( $p1, $p2 )-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V4)》中的 EstimateTemplateCost。
-
- Tools for PowerShell V5
-
示例 1:返回一个 AWS 简单月度计算器 URL,其中包含描述运行模板所需资源的查询字符串。模板是从指定的 Amazon S3 URL 获取的,并且应用了单个自定义参数。也可以使用“键”和“值”来指定该参数,而不是“ParameterKey”和“ParameterValue”。
Measure-CFNTemplateCost -TemplateURL https://s3.amazonaws.com/amzn-s3-demo-bucket/templatefile.template ` -Region us-west-1 ` -Parameter @{ ParameterKey="KeyName"; ParameterValue="myKeyPairName" }示例 2:返回一个 AWS 简单月度计算器 URL,其中包含描述运行模板所需资源的查询字符串。模板是根据提供的内容解析的,并且应用了自定义参数(此示例假设模板内容会声明“KeyName”和“InstanceType”这两个参数)。也可以使用“键”和“值”来指定自定义参数,而不是“ParameterKey”和“ParameterValue”。
Measure-CFNTemplateCost -TemplateBody "{TEMPLATE CONTENT HERE}" ` -Parameter @( @{ ParameterKey="KeyName"; ParameterValue="myKeyPairName" },` @{ ParameterKey="InstanceType"; ParameterValue="m1.large" })示例 3:使用 New-Object 来构建一组模板参数,并返回一个 AWS 简单月度计算器 URL,其中包含描述运行模板所需资源的查询字符串。模板是根据提供的内容解析的,并且包含自定义参数(此示例假设模板内容会声明“KeyName”和“InstanceType”这两个参数)。
$p1 = New-Object -Type Amazon.CloudFormation.Model.Parameter $p1.ParameterKey = "KeyName" $p1.ParameterValue = "myKeyPairName" $p2 = New-Object -Type Amazon.CloudFormation.Model.Parameter $p2.ParameterKey = "InstanceType" $p2.ParameterValue = "m1.large" Measure-CFNTemplateCost -TemplateBody "{TEMPLATE CONTENT HERE}" -Parameter @( $p1, $p2 )-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet Reference (V5)》中的 EstimateTemplateCost。
-