AWS Ruby SDK Cloudformation 不会验证模板
AWS Ruby SDK Cloudformation will not validate a template
运行 进入 ruby Cloudformation 问题 我有一个超级简单的 cloudformation 模板将使用 AWS CLI 进行验证和 create_stack,但是当我 运行 时失败使用 Ruby SDK 的相同命令。
$ cat net.yml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
Vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
$ aws cloudformation validate-template --region us-east-1 --template-body file://./net.yml
{
"Parameters": []
}
$ irb
irb(main):001:0> require 'aws-sdk-cloudformation'
=> true
irb(main):002:1* cfn = Aws::CloudFormation::Client.new(
irb(main):003:1* region: 'us-east-1'
irb(main):004:0> )
irb(main):005:2* cfn.validate_template({
irb(main):006:2* template_body: 'file://./net.yml'
irb(main):007:0> })
Traceback (most recent call last):
13: from /usr/bin/irb:23:in `<main>'
12: from /usr/bin/irb:23:in `load'
11: from /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
10: from (irb):5
9: from /var/lib/gems/2.7.0/gems/aws-sdk-cloudformation-1.47.0/lib/aws-sdk-cloudformation/client.rb:5361:in `validate_template'
8: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/seahorse/client/request.rb:72:in `send_request'
7: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/seahorse/client/plugins/response_target.rb:24:in `call'
6: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/aws-sdk-core/plugins/response_paging.rb:12:in `call'
5: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/seahorse/client/plugins/request_callback.rb:71:in `call'
4: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/aws-sdk-core/plugins/param_converter.rb:26:in `call'
3: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/aws-sdk-core/plugins/idempotency_token.rb:19:in `call'
2: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:22:in `call'
1: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/seahorse/client/plugins/raise_response_errors.rb:17:in `call'
Aws::CloudFormation::Errors::ValidationError (Template format error: unsupported structure.)
irb(main):008:0>
我在template_body
字段中是否使用file://
并不重要。如果我将 Ruby 上传到 S3,我可以使用相同的模板,但我不想这样做。以前有人遇到过这个问题吗?
根据 documentation,template_body
的值应该是一个字符串
template_body (String) — Structure containing the template body with a minimum length of 1 byte and a maximum length of 51,200 bytes
所以你只需要读取文件并将其作为字符串传递给选项。
irb(main):001:0> File.read('x.yml')
=> "Resources:\n myvpc:\n Type: AWS::EC2::VPC\n
Properties: \n CidrBlock: String\n"
irb(main):002:0>
irb(main):038:0> cfn.validate_template({template_body: File.read('x.yml').to_s})
=> #<struct Aws::CloudFormation::Types::ValidateTemplateOutput parameters=[],
description=nil, capabilities=[], capabilities_reason=nil, declared_transforms=[]>
irb(main):039:0>
运行 进入 ruby Cloudformation 问题 我有一个超级简单的 cloudformation 模板将使用 AWS CLI 进行验证和 create_stack,但是当我 运行 时失败使用 Ruby SDK 的相同命令。
$ cat net.yml
AWSTemplateFormatVersion: '2010-09-09'
Resources:
Vpc:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
$ aws cloudformation validate-template --region us-east-1 --template-body file://./net.yml
{
"Parameters": []
}
$ irb
irb(main):001:0> require 'aws-sdk-cloudformation'
=> true
irb(main):002:1* cfn = Aws::CloudFormation::Client.new(
irb(main):003:1* region: 'us-east-1'
irb(main):004:0> )
irb(main):005:2* cfn.validate_template({
irb(main):006:2* template_body: 'file://./net.yml'
irb(main):007:0> })
Traceback (most recent call last):
13: from /usr/bin/irb:23:in `<main>'
12: from /usr/bin/irb:23:in `load'
11: from /usr/lib/ruby/gems/2.7.0/gems/irb-1.2.1/exe/irb:11:in `<top (required)>'
10: from (irb):5
9: from /var/lib/gems/2.7.0/gems/aws-sdk-cloudformation-1.47.0/lib/aws-sdk-cloudformation/client.rb:5361:in `validate_template'
8: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/seahorse/client/request.rb:72:in `send_request'
7: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/seahorse/client/plugins/response_target.rb:24:in `call'
6: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/aws-sdk-core/plugins/response_paging.rb:12:in `call'
5: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/seahorse/client/plugins/request_callback.rb:71:in `call'
4: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/aws-sdk-core/plugins/param_converter.rb:26:in `call'
3: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/aws-sdk-core/plugins/idempotency_token.rb:19:in `call'
2: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:22:in `call'
1: from /var/lib/gems/2.7.0/gems/aws-sdk-core-3.112.0/lib/seahorse/client/plugins/raise_response_errors.rb:17:in `call'
Aws::CloudFormation::Errors::ValidationError (Template format error: unsupported structure.)
irb(main):008:0>
我在template_body
字段中是否使用file://
并不重要。如果我将 Ruby 上传到 S3,我可以使用相同的模板,但我不想这样做。以前有人遇到过这个问题吗?
根据 documentation,template_body
的值应该是一个字符串
template_body (String) — Structure containing the template body with a minimum length of 1 byte and a maximum length of 51,200 bytes
所以你只需要读取文件并将其作为字符串传递给选项。
irb(main):001:0> File.read('x.yml')
=> "Resources:\n myvpc:\n Type: AWS::EC2::VPC\n
Properties: \n CidrBlock: String\n"
irb(main):002:0>
irb(main):038:0> cfn.validate_template({template_body: File.read('x.yml').to_s})
=> #<struct Aws::CloudFormation::Types::ValidateTemplateOutput parameters=[],
description=nil, capabilities=[], capabilities_reason=nil, declared_transforms=[]>
irb(main):039:0>