How to get started using aws_account_utils (ruby)? - ruby

After searching around, I found this aws_account_utils which does exactly what I hope to achieve - programmatically create aws account.
Unfortunately as a total ruby noob, I have no idea how to start using it even after reading the README.md.
I suspect I'd need the following steps:
Create create-account.rb
Use the util in the code
Run ruby create-account.rb
How should the content of create-account.rb be like?
Please show me a template.
With that I should be able to start experimenting and hacking.
Any other steps I should do?
Thanks in advance.

Plan below is rough and must be supplemented.
Create Gemfile file. This file is needed to specify project dependencies (libraries)
Put this line into Gemfile
gem 'aws_account_utils'
Run bundle install in your console / terminal
Create create-account.rb file with next code
require 'aws_account_utils'
aws_utils = AwsAccountUtils::AwsAccountUtils.new()
details = { 'fullName' => 'Herman Munster',
'company' => 'The Munsters',
'addressLine1' => '1313 Mockingbird Lane',
'city' => 'Mockingbird Heights',
'state' => 'CA',
'postalCode' => '92000',
'phoneNumber' => '(800) 555-1212',
'guess' => 'Test Account' }
resp = aws_utils.create_account(account_name: 'My Test Account 01',
account_email: 'adfefef#gmail.com',
account_password: 'foobar1212121',
account_details: details)
This code uses aws_account_utils library. Documentation you can find here.
After steps above you can run ruby create-account.rb.

Related

Puppet - unable to execute ONLY ONCE ordered chain of Exec commands after notification

TLDR:
I can't configure ordered chain of Puppet "Exec" commands to run ONLY ONCE.
Details:
I want to use Vagrant and Puppet modules to setup VM with installed Redmine and some sample data loaded into it.
I'm using https://forge.puppetlabs.com/johanek/redmine and it works great - Redmine is installed and it works.
My goal:
Now I want to load sample data into Redmine using REST API:
Create 1 test project
Import 2 issues into this project
I want to run 2 simple "Exec", one after another and ONLY ONCE, but I can't achieve this, hence the question.
My current effort:
I've tried to subscribe to one of latest steps in redmine installation
subscribe => [Exec['rails_migrations']]
and then import data, but the first step "create-project1" always notifies second step "import-issues", so it creates duplicated data.
And if run vagrant provision few times, the "import-issues" creates duplicates of this issues.
Here is my code:
exec {'create-project1':
subscribe => [Exec['rails_migrations']],
path => ['/usr/bin', '/usr/sbin', '/bin'],
creates => "$redmine_install_dir/.data_loaded",
command => "curl WHICH_CREATES_PROJECT && touch $redmine_install_dir/.data_loaded",
notify => [Exec['import-issues']],
} ->
exec {'import-issues':
path => ['/usr/bin', '/usr/sbin', '/bin'],
command => "curl WHICH_IMPORTS_ISSUES",
refreshonly => true,
}
Question:
How to configure those Exec commands to run in chain and ONLY ONCE?
Im also thinking about extending this chain to 5 commands in near future, so keep that in mind.
you were almost there with 'ONLY ONCE' - Puppet has onlyif properties that you can include in your exec block to test if a file already exists or not.
you could then do something like
exec {'create-project1':
subscribe => [Exec['rails_migrations']],
path => ['/usr/bin', '/usr/sbin', '/bin'],
onlyif => "test ! -f $redmine_install_dir/.data_loaded"
command => "curl WHICH_CREATES_PROJECT && touch $redmine_install_dir/.data_loaded",
notify => [Exec['import-issues']],
which test on the existence of the $redmine_install_dir/.data_loaded- you should be able to play a bit with that to achieve what you want

Fatal Error caused from failed upgrade - restore - CS Cart 4.2.4 > 4.3.1

I have recently upgraded my CS Cart website from 4.2.4 to 4.3.1
We have a custom theme installed so encountered a few issues that we didnt have time to address immediatley - so as per instruction, re ran the restore.
Now we have the following fatal error and I don't really know where to start. I am not much of a dev, but can follow instruction and am quite technically minded.
Thanks for any help in advance.
To fix the assets issue please open the config.local.php file in the root directory and replace:
'custom_files' => array(
'dir' => & $config['dir']['var'],
'prefix' => 'custom_files'
)
with
'custom_files' => array(
'dir' => & $config['dir']['var'],
'prefix' => 'custom_files'
),
'assets' => array(
'dir' => & $config['dir']['cache_misc'],
'prefix' => 'assets',
'cdn' => true
),
This is a very interesting issue. I think the fastest way to resolve it, to contact the official CS-Cart Support Team. If you have a legal license, you have support credits, ask the team to resolve the issue will be free.

How to use Fog Library to create CDN in AWS

I am new in the DevOps world and my company uses Fog library to deploy EC2 instances for our Dev Environment. One of my company's products needs a CDN and I am trying to figure out how I can automate CDN using the same Fog Library.
I found info at fog.io and here is the code I put in makeCDN.rb (with a .sh wrapper to deploy it).
#!/usr/bin/ruby
require 'fog'
# create a connection to the service
cdn = Fog::CDN.new({
:provider => 'AWS',
:aws_access_key_id => 'fake_key_id',
:aws_secret_access_key => '2345fake_access_key6789'
})
cdn.post_distribution({
'CustomOrigin' => {
'DNSName' => 'hostname.domain.org', #example name
'HTTPPort' => '80',
'OriginProtocolPolicy' => 'match-viewer',
'DefaultRootObject' => '/',
'Enabled' => 'true',
}
})
So, I am unsure what I am doing wrong but the error I am getting is:
/home/eztheog/.rvm/gems/ruby-1.9.3-p547#fogDev/gems/excon-0.38.0/lib/excon/middlewares/expects.rb:10:in
`response_call': Expected(201) <=> Actual(400 Bad Request) (Excon::Errors::BadRequest)
response => #<Excon::Response:0x00000001d73b78 #data={:body=>"<?xml version=\"1.0\"?>\n<ErrorResponse
xmlns=\"http://cloudfront.amazonaws.com/doc/2010-11-01/\"><Error>
<Type>Sender</Type><Code>MalformedXML</Code><Message>1 validation error
detected: Value null at 'distributionConfig.enabled' failed to satisfy
constraint: Member must not be null</Message></Error>
<RequestId>c2b33cda-abee-11e4-8115-b584e1255c70</RequestId>
</ErrorResponse>", :headers=>{"x-amzn-RequestId"=>"c2b33cda-abee-11e4-8115-b584e1255c70",
"Content-Type"=>"text/xml", "Content-Length"=>"371", "Date"=>"Tue, 03
Feb 2015 21:51:07 GMT"}, :status=>400, :remote_ip=>"205.251.242.229",
:local_port=>39733, :local_address=>"10.100.6.203"}, #body="<?xml
version=\"1.0\"?>\n<ErrorResponse
xmlns=\"http://cloudfront.amazonaws.com/doc/2010-11-01/\"><Error>
<Type>Sender</Type><Code>MalformedXML</Code><Message>1 validation error
detected: Value null at 'distributionConfig.enabled' failed to satisfy
constraint: Member must not be null</Message></Error>
<RequestId>c2b33cda-abee-11e4-8115-b584e1255c70</RequestId>
</ErrorResponse>", #headers={"x-amzn-RequestId"=>"c2b33cda-abee-11e4-
8115-b584e1255c70", "Content-Type"=>"text/xml", "Content-Length"=>"371",
"Date"=>"Tue, 03 Feb 2015 21:51:07 GMT"}, #status=400,
#remote_ip="205.251.242.229", #local_port=39733,
#local_address="10.100.6.203">
I have found information here but am unsure how to parse the info into the ruby file.
There seems to be little blog stuff that I can find to figure out how to do this.
Can anyone point me the right direction?
I found this gist that explains the context.
So, the RubyDoc.info link (in question) said that the Enabled Boolean was an Option. But, in AWS it is not (or so it seems based on the error I got).
But, to resolve this, the :Enabled => true has to be OUTSIDE of the cdn.distribution block.
Hope this helps anyone who is looking for this in the future!
Also, this might be a BUG because the Fog library says that this feature is OPTIONAL but it seems mandatory by AWS.

Chef : Create a process as another user

So I have some code for running a batch file as a specific user. This was my attempt to automate the following syntax
runas /user:thisguy "C:\ThisGuysScript.bat"
so it looks like this in Ruby
Process.create(:command_line => "C:\\ThisGuysScript.bat ", :domain => "MYServer", :with_logon => "thisguy", :password => "thisguyspassword", :cwd =>"C:\\")
So I try to put this in a recipe in chef and disaster strikes
require 'win32/process'
::Process.create(:command_line => "C:\\ThisGuysScript.bat ", :domain => "MYServer", :with_logon => "thisguy", :password => "thisguyspassword", :cwd =>"C:\\")
Is failing with the following error
[Tue, 30 Oct 2012 15:57:03 +0000] FATAL: ArgumentError: You must supply a name when declaring a user resource
So it seems to not realise that I want to use the win32 flavour process. Chef seems to override the win32 module (I know recipes are the opscode DSL rather than really ruby right?)
Anyone been able to get this working? Or the same function with a different implementation. Checked out the windows cookbook but didn't spot much
It sounds like you want to make an LWRP for creating a process on a windows machine.
The error you are getting means you have something like
user do # Missing name
gid 500
home "..."
end
the correct syntax is
user "apache" do # or whatever the user name should be
# ...
end
If you don't have the above in your cookbook, it is possible that the included file has a variable named user which would also cause this issue.
To answer your subquestion, Chef is straight ruby with some functions made available and a frame work to run things. Note, there are several stages in a chef run. I think you are having issues in the compilation stage.
Making an LWRP seems like the way to go. If you don't want to go that far you could do something like.
ruby_block "Firing process lazers" do
require 'win32/process'
::Process.create(:command_line => "C:\\ThisGuysScript.bat ", :domain => "MYServer", :with_logon => "thisguy", :password => "thisguyspassword", :cwd =>"C:\\")
end

Cannot load 'paperclip/storage/ftp' when using paperclipftp in Rails 3

I've just installed paperclip 2.3.3 and paperclipftp 0.1.0.
Paperclip was working fine, the attachments were saving and everything was great.
Enter paperclipftp.
I've included both gems in my Gemfile, installed it with bundle and made sure all dependencies were satisfied. I've also double checked that all my ftp info is correct and the server is working fine.
When I try to attach a file using ftp:
has_attached_file :photo,
:styles => {
:small => "204x159#",
:original => "460X370#"
},
:storage => :ftp,
:path => "/:attachment/:attachment/:id/:style/:filename",
:url => "http://kickassserver.com/_myfolder/:attachment/:attachment/:id/:style/:filename"
I get the following error:
Paperclip::StorageMethodNotFound in SetupsController#create
Cannot load 'paperclip/storage/ftp'
I'm thinking that paperclipftp isn't actually being loaded by my app. Is there a way I can check to see that it's actually being loaded, or has anyone else experienced this?
Thanks,
Matt
I have ruby 1.9.2p180 and the problem is that the timeout class being loaded.
Only add,
require 'timeout'
to the application.rb and this will fix your error.

Resources