aws-sdk-utils 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7bcb9cd6ed38ebf703d00f256ef1cd81ddf76332
4
- data.tar.gz: 0d334f6d7417d18d178b4fe8a62ee323da5b43da
3
+ metadata.gz: cb5eabb9468ec7846c03e1aad6fde58961c664c8
4
+ data.tar.gz: 700ce35e176f8f0269cc90375a4f62a6857fc090
5
5
  SHA512:
6
- metadata.gz: fe4c5b5095ad6817f6da5e33412ad626ce84a42ae92cddd81ce03a9e4fbb59a1fbf7d0c60a21d1f5f3fb28a68efbc8686459329f050220f7ce1b7d329c919bd9
7
- data.tar.gz: 953ff6e31ad4e40586b4bc196cf74251d4712bbaacddb45ddc6b0c057d23d44c326292f3ca404fa11aaa072bece0a7e1042d6064f6bbabcc09cc3eb7c3c02834
6
+ metadata.gz: 8a715354936be3baef9ec97d472325145d08a0f89cd38fe0e3bcabb442dd5db80076993280ae8225bb88be9c38595c76b2ed47233074a050dc41fae09c36c7df
7
+ data.tar.gz: 0efd49dd7d5682d19f5e9f5aa072a8a8c27e4c89b36c72cb60e547de47b1aa2f27aec591884003876c33f46a5c1dea28ac49e29fe46093472d0584d0afff1751
@@ -1,2 +1,3 @@
1
1
  require_relative 'cloudformation_converger'
2
- require_relative 'lambda_alias_switcher'
2
+ require_relative 'lambda_alias_switcher'
3
+ require_relative 'waf_util'
@@ -0,0 +1,97 @@
1
+ require 'aws-sdk'
2
+ require 'cfndsl'
3
+ require 'tempfile'
4
+
5
+ class CfndslConverger
6
+
7
+ def chain_converge(cfndsl_stacks:,
8
+ input_bindings: nil)
9
+
10
+ previous_output_bindings = input_bindings
11
+ cfndsl_stacks.each do |cfndsl_stack|
12
+ previous_output_bindings = converge stack_name: cfndsl_stack[:stack_name],
13
+ path_to_stack: cfndsl_stack[:path_to_stack],
14
+ bindings: previous_output_bindings
15
+ end
16
+ previous_output_bindings
17
+ end
18
+
19
+ def converge(stack_name:,
20
+ path_to_stack:,
21
+ bindings: nil)
22
+ extras = []
23
+ unless bindings.nil?
24
+ temp_file = Tempfile.new('cfnstackfortesting')
25
+ temp_file.write bindings.to_yaml
26
+ temp_file.close
27
+
28
+ extras << [:yaml,File.expand_path(temp_file)]
29
+ end
30
+
31
+ verbose = false
32
+ model = CfnDsl::eval_file_with_extras(File.expand_path(path_to_stack),
33
+ extras,
34
+ verbose)
35
+
36
+ outputs = converge_stack stack_name: stack_name,
37
+ stack_body: model.to_json
38
+ outputs
39
+ end
40
+
41
+ ##
42
+ # Delete the specified Cloudformation stack by name
43
+ #
44
+ def cleanup(cloudformation_stack_name)
45
+ resource = Aws::CloudFormation::Resource.new
46
+ stack_to_delete = resource.stack(cloudformation_stack_name)
47
+
48
+ stack_to_delete.delete
49
+ begin
50
+ stack_to_delete.wait_until(max_attempts:100, delay:15) do |stack|
51
+ stack.stack_status.match /DELETE_COMPLETE/
52
+ end
53
+ rescue
54
+ #squash any errors - when stack is gone, the waiter might freak
55
+ end
56
+ end
57
+
58
+ private
59
+
60
+ def converge_stack(stack_name:,
61
+ stack_body:)
62
+
63
+ cloudformation_client = Aws::CloudFormation::Client.new
64
+ resource = Aws::CloudFormation::Resource.new(client: cloudformation_client)
65
+ if resource.stacks.find {|stack| stack.name == stack_name }
66
+ stack = resource.stack(stack_name)
67
+ begin
68
+ stack.update(template_body: stack_body,
69
+ capabilities: %w(CAPABILITY_IAM))
70
+ rescue Exception => error
71
+ if error.to_s =~ /No updates are to be performed/
72
+ puts 'no updates necessary'
73
+ else
74
+ raise error
75
+ end
76
+ end
77
+
78
+ else
79
+ stack = resource.create_stack(stack_name: stack_name,
80
+ template_body: stack_body,
81
+ capabilities: %w(CAPABILITY_IAM))
82
+ end
83
+
84
+ stack.wait_until(max_attempts:100, delay:15) do |stack|
85
+ stack.stack_status =~ /COMPLETE/ or stack.stack_status =~ /FAILED/
86
+ end
87
+
88
+ if stack.stack_status =~ /FAILED/
89
+ raise "#{stack_name} failed to converge: #{stack.stack_status}"
90
+ end
91
+
92
+ stack.outputs.inject({}) do |hash, output|
93
+ hash[output.output_key] = output.output_value
94
+ hash
95
+ end
96
+ end
97
+ end
@@ -3,8 +3,7 @@ require 'aws-sdk'
3
3
  class CloudFormationConverger
4
4
 
5
5
  def converge(stack_name:,
6
- stack_path:,
7
- parameters:nil)
6
+ stack_path:)
8
7
 
9
8
  cloudformation_client = Aws::CloudFormation::Client.new
10
9
  resource = Aws::CloudFormation::Resource.new(client: cloudformation_client)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sdk-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - someguy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-09 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 2.2.17
27
+ - !ruby/object:Gem::Dependency
28
+ name: cfndsl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.0
27
41
  description: Low level utilities for dealing with AWS SDK
28
42
  email:
29
43
  executables: []
@@ -31,6 +45,7 @@ extensions: []
31
45
  extra_rdoc_files: []
32
46
  files:
33
47
  - lib/aws-sdk-utils.rb
48
+ - lib/cfndsl_converger.rb
34
49
  - lib/cloudformation_converger.rb
35
50
  - lib/lambda_alias_switcher.rb
36
51
  - lib/waf_util.rb
@@ -55,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
70
  version: '0'
56
71
  requirements: []
57
72
  rubyforge_project:
58
- rubygems_version: 2.6.0
73
+ rubygems_version: 2.6.2
59
74
  signing_key:
60
75
  specification_version: 4
61
76
  summary: aws-sdk-utils