My cookbook is not compiling throwing the error uninitialized constant Chef::Recipe::AWS. The chef_gem aws-sdk installed fine, but still doesn't compile when AWS.config(access_key_id: 'key', secret_access_key: 'pass') is called.
chef_gem "aws-sdk"
AWS.config(access_key_id: key, secret_access_key: pass)
rds = AWS::RDS.new
According to the doc from aws-sdk-ruby here and to the code, the class name is Aws
and not AWS
.
But your main problem here is that you're not including the lib installed by the gem.
add require 'aws-sdk'
before trying to call it's class.
To avoid being bitten by a name conflict with the Chef::Recipe
namespace call the lib as a top level lib like ::Aws.config(...)
Edit from personnal research: AWS
namespace is from the sdk v1, if you really wish to use this one and not the v2 you have to change your recipe to:
chef_gem "aws-sdk-v1"
require 'aws-sdk-v1'
AWS.config(access_key_id: key, secret_access_key: pass)
rds = AWS::RDS.new
You need to provide to aws-sdk gem your aws credentials. As you can read in the gem documentation:
Basic Configuration
You need to provide your AWS security credentials and choose a default region.
AWS.config(access_key_id: '...', secret_access_key: '...', region: 'us-west-2')
You can also specify these values via ENV:
export AWS_ACCESS_KEY_ID='...' export AWS_SECRET_ACCESS_KEY='...' export AWS_REGION='us-west-2'
Edit 'key'
and 'pass'
with your credentials, and add the aws region you want to use.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.