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.
Related
I'm trying to use the Ruby SMS Fu gem to send automated SMS messages to someone from my email address. Also, I'm not using Rails; this is a simple Ruby script that's getting some information from a site somewhere and then sending messages to someone based on said information. Unfortunately, I'm running into a very strange error when I try to use SMS Fu in my script:
/Users/my_username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/psych.rb:377:in `parse': (<unknown>): found character that cannot start any token while scanning for the next token at line 7 column 12 (Psych::SyntaxError)
from /Users/my_username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/psych.rb:377:in `parse_stream'
from /Users/my_username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/psych.rb:325:in `parse'
from /Users/my_username/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/psych.rb:252:in `load'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:55:in `config_yaml'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:61:in `carriers'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:77:in `carrier'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:73:in `carrier_email'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:85:in `sms_address'
from /Users/my_username/.rvm/gems/ruby-2.4.0/gems/sms_fu-1.1.2/lib/sms_fu/sms_fu.rb:43:in `deliver'
from ./my_script.rb:69:in `<main>'
What I've got going in my script looks like this:
#!/usr/bin/env ruby
require "active_support" # action_mailer, one of sms_fu's dependencies, throws
# an error without this
require "sms_fu"
# gather information from our site...
# Pony delivery via SMTP
PONY_CONFIG = {
:via => :smtp,
:via_options => {
:address => "smtp.gmail.com",
:port => "587",
:user_name => "me#example.com",
:password => "pass",
:authentication => :plain,
:enable_starttls_auto => true,
:domain => "localhost.localdomain"
}}
sms_fu = SMSFu::Client.configure(:delivery => :pony, :pony_config => PONY_CONFIG)
sms_fu.deliver("123456789", "some carrier", "my message", from: "me#example") # this line triggers the error
The odd thing is that this error is complaining about parsing YAML, but according to SMS Fu's README file, I only need to worry about setting up a YAML file if I'm using Rails, which I'm not. However, it seems that, upon examining SMS Fu's sources, it is hard-coded to work with a YAML file in the SMSFu.config_yaml method, which is subsequently used indirectly or directly by other methods in SMS Fu, all the way back to SMSFu::Client#deliver, which is the one causing the error here.
So, I guess my question is: how can I get this error to stop happening so that I can just send my SMS message without all the YAML hassle?
EDIT:
Forgot to give some version / environment info: I'm running this script on OS X 10.12.2 and I'm using Ruby 2.4.0 (although this Ruby version is manifest in the error above).
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.
I'm thinking I installed this wrong, but keep getting the same error. Installed league/flysystem-aws-s3-v3. S3 creds are setup in .env file.
Added these to the require in composer.
"aws/aws-sdk-php"
"aws/aws-sdk-php-laravel": "~3.0"
--------------------------------------------
Code:
$s3 = \Storage::disk('s3');
$s3->put($location, file_get_contents($image), 'public');
Getting the following error:
exception 'InvalidArgumentException' with message 'Missing required client configuration options:
' in /var/www/laravel/vendor/aws/aws-sdk-php/src/ClientResolver.php:328
Did some research online and couldn't find a solution.
Try to update :
composer update
Try This: go into config/filesystems.php and eliminate any env that encompasses a value.
For example mine showed 'cloud' => env('FILESYSTEM_CLOUD', 's3'),
so I changed it into 'cloud' => 'FILESYSTEM_CLOUD', 's3',
Do this to ALL values in this file, INCLUDING the S3 key, secret, region, and bucket. After that it should get you up and going.
I believe the issue is with Caching the values as Null rather than the actual edited values.
I have written manifest that installs an .exe and applies a hotfix to it every-time it installs on a new machine.
windowsinstaller { 'AppFabric install 1.1 install':
software_title => 'AppFabric 1.1 for Windows Server',
software_path => '/Microsoft/AppFabric1.1/WindowsServerAppFabricSetup_x64.exe',
install_options => ['/i','/SkipUpdates'],
}
windowsinstaller { 'AppFabric 1.1 HotFix install':
software_title => 'Windows Server AppFabric v1.1 CU5 [KB2932678]',
software_path => '/Microsoft/AppFabric1.1/AppFabric1.1-KB2932678-x64-ENU.exe',
install_options => ['/q','/norestart'],
subscribe => Windowsinstaller['AppFabric install 1.1 install']
}
service { 'Remote Registry Service':
name => 'RemoteRegistry',
ensure => running,
restart => true,
}
I am trying to get this install to run only if it's registry key is absent.
Using puppetlabs registry module you can manage keys, redirect them, and change the values.
reference: http://puppetlabs.com/blog/module-of-the-week-puppetlabs-registry-windows
Unfortunately, I can't seem to find a way to simply check if the key is there, I can either delete it or make sure its present using ensure => present and ensure => absent.
As I can't put resources into variables I am finding it hard to use conditional statements, and as present and absent set the key instead of check it, I don't think I can use meta parameters with the registry_key resource.
I know that I can wrap everything in an if statement and use a custom fact but I have been told that this is not the right way to proceed.
If anyone has an example of where this has been done before either using this module or something else registered in the puppet forge or any ideas it would be greatly appreciated.
The user manbart found the answer 7 months ago with this question
Exec onlyif registry value is not present
calling reg.exe to query the registry in an exec resource.
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