I have the following code in my app.
require 'aws-sdk'
require 'rubygems'
AWS.config({
:access_key_id => 'XXXXXXXXXXXXXXXXX',
:secret_access_key => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
})
ec2 = AWS::EC2.new(:ec2_endpoint => 'ec2.ap-southeast-1.amazonaws.com')
##i = ec2.instances.create(:image_id => 'ami-aabXXXXX', :instance_type => 't1.micro', :security_groups=> ['Drum-Factory'], :key_name => 'some-key' )
sleep 1 while ##i.status == :pending
......
How can i name my instance while creating it, so that it will appear in the Name column of my AWS Management Console.
Name column is actually a tag added to the instance
So you need to set the value of "Name" tag
My guess is something like this
##i.tags["Name"] = "value"
or
tag = ec2.tags.create(##i, "Name","Value")
check http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/EC2/TagCollection.html#create-instance_method
also this SO answer might be of help
For AWS, how do you set tags to a resource with the ruby aws-sdk?
Related
trying to add this to my rails project https://github.com/adelevie/parse-ruby-client
so i first obviously bundle installed the gem, then i created a parse.rb file in config/initializers with this code :
require 'parse-ruby-client'
client = Parse.create :application_id => 'API_KEY',
:api_key => 'API_KEY',
when i call client anywhere i get a error that its undefined
In your example client is a local variable. By the time you try to access it, it has already left the scope. What you should do is create or use a globally visible object. One example:
require 'parse-ruby-client'
::MyParse = Parse.create :application_id => 'APP_ID',
:api_key => 'API_KEY',
You can access such object as MyParse in the code.
Another example:
require 'parse-ruby-client'
MyApp::Application.configure do
config.parse = Parse.create :application_id => 'APP_ID',
:api_key => 'API_KEY',
end
And use it like this:
MyApp::Application.config.parse
I'm actually working on the test environment of Gandi.
I'm using the gandi gem (https://github.com/veilleperso/gandi)
I can connect with my API key etc... but when I want to create a new domain :
domain_spec = {
'owner' => 'FLN123-GANDI',
'admin' => 'FLN123-GANDI',
'bill' => 'FLN123-GANDI',
'tech' => 'FLN123-GANDI',
'nameservers' => ['a.dns.gandi-ote.net', 'b.dns.gandi-ote.net',
'c.dns.gandi-ote.net'],
'duration' => 1
}
#api.domain.create('foo.fr', domain_spec)
I got this message :
Error on object : OBJECT_CONTACT (CAUSE_INVALID) [Your are not the owner of the domain nor a reseller]
You can only create domains in both OTE and production environment which wasn't registered.
The OTE is not an empty sandbox, it's based on the data from production environment.
I am currently working in a project with Rails, and I have faced the need to import the existing server details from Amazon using the fog library.
I have tried some initial code to get the access to AWS, and at this point I have got the connection with the credentials.
The issue is that when I continue to get that instance details, it does not return anything.
require 'fog'
aws_credentials = {
:aws_access_key_id => "ACCESS ID"
:aws_secret_access_key "SECRET ID"
}
conn2 = Fog::Compute.new(aws_credentials.merge(:provider => 'AWS'))
conn2.servers.all.each do |i|
puts i.id
end
Could anyone please help me fixing this behavior?
The Amazon provider in fog defaults to using the us-east-1 region. It could be that your servers are in another region. To specify a different region by passing the :region into your Fog::Compute constructor. Valid regions include ['ap-northeast-1', 'ap-southeast-1', 'ap-southeast-2', 'eu-west-1', 'sa-east-1', 'us-east-1', 'us-west-1', 'us-west-2'.
So for instance if you are using region ap-northeast-1, your code would look like the following:
require 'fog'
aws_credentials = {
:aws_access_key_id => "ACCESS ID"
:aws_secret_access_key "SECRET ID"
}
conn2 = Fog::Compute.new(aws_credentials.merge(:provider => 'AWS', :region => 'ap-northeast-1' ))
conn2.servers.all.each do |i|
puts i.id
end
Hi I'm playing around with the aws/s3 gem so that my rails app can store and then download files from Amazon s3. I'm finding that I can't access the methods contained within the gem.
I followed the instructions in the documentation:
Entered into irb
required 'aws/s3'
entered interactive shell provided by aws/s3: % s3sh
AWS::S3::Base.establish_connection!(
:access_key_id => 'my credentials',
:secret_access_key => 'my credentials'
)
From here I believe I should be able to access my buckets and objects within them but when I call Service.buckets I get an error that states undefined method 'buckets'.
I also tried (not using s3sh):
service = AWS::S3::Base.establish_connection!(
:access_key_id => 'my credentials',
:secret_access_key => 'my credentials'
)
then service.buckets but still I get undefined method 'buckets'. How do I use this gem correctly?
Any help appreciated, thanks a lot.
AWS::S3::Service.buckets listed the buckets.
Can anyone tell me how to implement badgeville in ruby on rails?
EDIT:
how can I apply this on ruby on rails?
https://github.com/badgeville/badgeville-ruby
I'm not sure how this particular gem work, but normally it should work with following steps
create a file called 'badgeville.rb' inside app/config/initializers
add the following code to badgeville.rb
BadgevilleBerlin::Config.conf(
:host_name => "http://example.com",
:api_key => MY_API_KEY)
restart
then you should be able to use the following commands inside your
controllers/ models
Ex:
new_site = BadgevilleBerlin::Site.new(
:name => "My Website",
:url => "mydomain.com",
:network_id => MY_NETWORK_ID )
success = new_site.save