cloudformation-tool 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cloud_formation_tool/cli/invalidate.rb +23 -0
- data/lib/cloud_formation_tool/cli/main.rb +1 -0
- data/lib/cloud_formation_tool/cloud_formation/cloud_front_distribution.rb +50 -0
- data/lib/cloud_formation_tool/cloud_formation/stack.rb +10 -0
- data/lib/cloud_formation_tool/version.rb +1 -1
- data/lib/cloud_formation_tool.rb +5 -0
- metadata +17 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3166ce06d5291e9554a5a51c61c02f24a756c2e570f71cc9bb9fdc1cb3ad8761
|
4
|
+
data.tar.gz: 4c633dab08f1a52d0a7f0a22fe55fefcb319f61f3489d657a1762833475fd052
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffb9f5120bbb596f3878ead695e47257f3e26f334b99cfcd0336e69d6bf5436baf068c6a11f25401fb9b8c8409115940d9692dd9fe9e2fbb665cdbe888d8f3a2
|
7
|
+
data.tar.gz: 7d30c30cc1dde13828a0e990b22c37b50f8d7798a413a623010745c2b4eb8132907fd318b89edd7bf4e424b0b2c5807ca4addf704b5fabd97c1dfecb3af5f63c
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CloudFormationTool
|
2
|
+
module CLI
|
3
|
+
|
4
|
+
class Invalidate < Clamp::Command
|
5
|
+
include CloudFormationTool
|
6
|
+
|
7
|
+
parameter "STACK_NAME", "Name of the stack to invalidate CloudFront caches in"
|
8
|
+
|
9
|
+
def execute
|
10
|
+
st = CloudFormation::Stack.new(stack_name)
|
11
|
+
st.cdns.collect do |res|
|
12
|
+
Thread.new do
|
13
|
+
log "Creating cache invalidation for #{res.distribution.id} #{res.domain_names} /*"
|
14
|
+
inv = res.invalidate("/*")
|
15
|
+
log "Invalidation #{inv.id}: #{inv.status}"
|
16
|
+
inv.wait
|
17
|
+
log "Invalidation #{inv.id}: #{inv.status}"
|
18
|
+
end
|
19
|
+
end.each(&:join).length > 0 or error "No valid CloudFront distributions found"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -55,6 +55,7 @@ module CloudFormationTool
|
|
55
55
|
subcommand 'groups', 'List stack Autoscaling groups', Groups
|
56
56
|
subcommand 'recycle', 'Recycle servers in an auto scaling group', Recycle
|
57
57
|
subcommand 'scale', 'Set the number of desired servesr in an auto scaling group', Scale
|
58
|
+
subcommand 'invalidate', 'Invalidate CloudFront caches in the stack', Invalidate
|
58
59
|
subcommand 'output', 'Retrieve output values from the stack', Output
|
59
60
|
end
|
60
61
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module CloudFormationTool
|
2
|
+
class CloudFormation
|
3
|
+
|
4
|
+
module CloudFrontDistribution
|
5
|
+
include CloudFormationTool
|
6
|
+
|
7
|
+
def distribution
|
8
|
+
@__dist ||= awscdn.get_distribution(id: self.physical_resource_id).distribution
|
9
|
+
end
|
10
|
+
|
11
|
+
def domain_names
|
12
|
+
distribution.distribution_config.aliases.items.join(",")
|
13
|
+
end
|
14
|
+
|
15
|
+
def invalidate(path_expression)
|
16
|
+
callerref = Time.now.strftime("%Y%m%d%H%M%S")
|
17
|
+
awscdn.create_invalidation(
|
18
|
+
distribution_id: self.physical_resource_id,
|
19
|
+
invalidation_batch: {
|
20
|
+
paths: { quantity: 1, items: [ path_expression ] },
|
21
|
+
caller_reference: callerref
|
22
|
+
}
|
23
|
+
).invalidation.tap do |i|
|
24
|
+
i.extend(CloudFrontInvalidation)
|
25
|
+
i.distribution_id = self.physical_resource_id
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
module CloudFrontInvalidation
|
32
|
+
include CloudFormationTool
|
33
|
+
|
34
|
+
def distribution_id= distid
|
35
|
+
@distid = distid
|
36
|
+
end
|
37
|
+
|
38
|
+
def status
|
39
|
+
awscdn.get_invalidation(distribution_id: @distid, id: self.id).invalidation.status
|
40
|
+
end
|
41
|
+
|
42
|
+
def wait
|
43
|
+
while self.status == "InProgress"
|
44
|
+
sleep 5
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -118,6 +118,16 @@ module CloudFormationTool
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
def cdns
|
122
|
+
output = []
|
123
|
+
resources do |res|
|
124
|
+
output << res if res.resource_type == 'AWS::CloudFront::Distribution'
|
125
|
+
end
|
126
|
+
output.collect do |res|
|
127
|
+
res.extend(CloudFrontDistribution)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
121
131
|
def see_events
|
122
132
|
each { |e| @seenev << e.event_id }
|
123
133
|
end
|
data/lib/cloud_formation_tool.rb
CHANGED
@@ -95,6 +95,11 @@ module CloudFormationTool
|
|
95
95
|
$__aws_as ||= Aws::AutoScaling::Client.new aws_config
|
96
96
|
end
|
97
97
|
|
98
|
+
def awscdn
|
99
|
+
require 'aws-sdk-cloudfront'
|
100
|
+
$__aws_cdn ||= Aws::CloudFront::Client.new aws_config
|
101
|
+
end
|
102
|
+
|
98
103
|
def s3_bucket_name(region)
|
99
104
|
name = nil
|
100
105
|
# see if we already have a cf-templates bucket for this region
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudformation-tool
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oded Arbel
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: aws-sdk-cloudfront
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: autoloaded
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,6 +154,7 @@ files:
|
|
140
154
|
- lib/cloud_formation_tool/cli/create.rb
|
141
155
|
- lib/cloud_formation_tool/cli/delete.rb
|
142
156
|
- lib/cloud_formation_tool/cli/groups.rb
|
157
|
+
- lib/cloud_formation_tool/cli/invalidate.rb
|
143
158
|
- lib/cloud_formation_tool/cli/list_stacks.rb
|
144
159
|
- lib/cloud_formation_tool/cli/main.rb
|
145
160
|
- lib/cloud_formation_tool/cli/monitor.rb
|
@@ -151,6 +166,7 @@ files:
|
|
151
166
|
- lib/cloud_formation_tool/cli/servers.rb
|
152
167
|
- lib/cloud_formation_tool/cli/status.rb
|
153
168
|
- lib/cloud_formation_tool/cloud_formation.rb
|
169
|
+
- lib/cloud_formation_tool/cloud_formation/cloud_front_distribution.rb
|
154
170
|
- lib/cloud_formation_tool/cloud_formation/lambda_code.rb
|
155
171
|
- lib/cloud_formation_tool/cloud_formation/stack.rb
|
156
172
|
- lib/cloud_formation_tool/cloud_init.rb
|