aws-sdk-utils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/cloudformation_converger.rb +43 -0
- data/lib/lambda_alias_switcher.rb +33 -0
- metadata +60 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2c8229a4b96b285d3e03b2675e1f482fe446a029
|
4
|
+
data.tar.gz: f127949374fe7a17bbd379750bd468629fdcd9d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90f49e47addaea72f2cefd066c879fe21a0874937f4a26418d8b25b922d0723581e079084238999293a7d02b207a97d7bd24a6e951b270178d8d28eee97d6fbb
|
7
|
+
data.tar.gz: 6f55efe16b543299e2f64881e133172468e56c73cb2bb70c3e288eb441d9c81276ee86745bf5c67706c639b3b3ea182f00f7a4fe2bf17a85df2cc8acf16b6f97
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
class CloudFormationConverger
|
4
|
+
|
5
|
+
def converge(stack_name:,
|
6
|
+
stack_path:,
|
7
|
+
parameters:nil)
|
8
|
+
|
9
|
+
cloudformation_client = Aws::CloudFormation::Client.new
|
10
|
+
resource = Aws::CloudFormation::Resource.new(client: cloudformation_client)
|
11
|
+
if resource.stacks.find {|stack| stack.name == stack_name }
|
12
|
+
stack = resource.stack(stack_name)
|
13
|
+
begin
|
14
|
+
stack.update(template_body: IO.read(stack_path),
|
15
|
+
capabilities: %w(CAPABILITY_IAM))
|
16
|
+
rescue Exception => error
|
17
|
+
if error.to_s =~ /No updates are to be performed/
|
18
|
+
puts 'no updates necessary'
|
19
|
+
else
|
20
|
+
raise error
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
else
|
25
|
+
stack = resource.create_stack(stack_name: stack_name,
|
26
|
+
template_body: IO.read(stack_path),
|
27
|
+
capabilities: %w(CAPABILITY_IAM))
|
28
|
+
end
|
29
|
+
|
30
|
+
stack.wait_until(max_attempts:100, delay:15) do |stack|
|
31
|
+
stack.stack_status =~ /COMPLETE/ or stack.stack_status =~ /FAILED/
|
32
|
+
end
|
33
|
+
|
34
|
+
if stack.stack_status =~ /FAILED/
|
35
|
+
raise "#{stack_name} failed to converge: #{stack.stack_status}"
|
36
|
+
end
|
37
|
+
|
38
|
+
stack.outputs.inject({}) do |hash, output|
|
39
|
+
hash[output.output_key] = output.output_value
|
40
|
+
hash
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
class LambdaAliasSwitcher
|
4
|
+
|
5
|
+
def switch_alias(function_name:,
|
6
|
+
alias_arg:,
|
7
|
+
function_version: '$LATEST')
|
8
|
+
fail 'function name is nil' if function_name.nil?
|
9
|
+
fail 'alias arg is nil' if alias_arg.nil?
|
10
|
+
|
11
|
+
client = Aws::Lambda::Client.new
|
12
|
+
|
13
|
+
list_aliases_response = client.list_aliases function_name: function_name
|
14
|
+
|
15
|
+
found_alias = list_aliases_response.aliases.find do |alias_iter|
|
16
|
+
alias_iter.name == alias_arg
|
17
|
+
end
|
18
|
+
|
19
|
+
if found_alias.nil?
|
20
|
+
|
21
|
+
create_alias_response = client.create_alias function_name: function_name,
|
22
|
+
name: alias_arg,
|
23
|
+
function_version: function_version
|
24
|
+
|
25
|
+
create_alias_response.alias_arn
|
26
|
+
else
|
27
|
+
update_alias_response = client.update_alias function_name: function_name,
|
28
|
+
name: alias_arg,
|
29
|
+
function_version: function_version
|
30
|
+
update_alias_response.alias_arn
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws-sdk-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- someguy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.2.17
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.2.17
|
27
|
+
description: Low level utilities for dealing with AWS SDK
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/cloudformation_converger.rb
|
34
|
+
- lib/lambda_alias_switcher.rb
|
35
|
+
homepage: https://github.com/stelligent/aws-sdk-utils
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 2.1.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.6.0
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: aws-sdk-utils
|
60
|
+
test_files: []
|