【发布时间】:2015-02-11 07:03:20
【问题描述】:
我有我用来在 AWS 上创建 RDS 实例的说明书。我不想将 AWS 凭证存储在我的代码中,因此我编写了一小段 Ruby 代码 sn-p 来从存储在本地计算机上的文件中获取凭证。代码如下:
Dir.glob("#{Dir.home}/.aws/config1") do |my_config_file|
access_key = File.readlines(my_config_file)[0]
secret_access_key = File.readlines(my_config_file)[1]
#puts access_key
#puts "\n"
#puts secret_access_key
end
include_recipe "aws-rds"
aws_rds db_info[:name] do
# will use the iam role if available
# optionally place the keys
# see http://docs.aws.amazon.com/AWSSdkDocsRuby/latest/DeveloperGuide/ruby-dg-roles.html
aws_access_key access_key
aws_secret_access_key secret_access_key
engine 'postgres'
db_instance_class 'db.t1.micro'
region 'us-east-1'
allocated_storage 5
master_username db_info[:username]
master_user_password db_info[:password]
end
当我运行我的食谱时,我不断收到如下错误:
Recipe Compile Error in C:/Users/amohamme1/.chef/local-mode-cache/cache/cookbooks/amir_rds_test-machines/recipes/up-machines.rb
================================================================================
NoMethodError
-------------
undefined method `access_key' for Chef::Resource::AwsRds
我是红宝石新手。我尝试将 access_key 和 secret_access_key 变量声明为全局变量。那并没有解决问题。我不确定如何解决这个问题。任何帮助表示赞赏。
【问题讨论】:
标签: ruby amazon-web-services chef-infra chef-recipe