cfn-model 0.4.16 → 0.4.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cfn-model/transforms/serverless.rb +78 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee4e39515d2ee0750c7ef71ec03c1f74d2345493621b99ad454ed0ef73013767
|
4
|
+
data.tar.gz: acff3ed655ee47fb57c2fcd1c107c6bd0a6e6d47695ee1d7bab69ae6716b83d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ea5adf97d67de8fa64278cd5d83c7b3482f53d559eac400dd2be17c0024e42b7b8225248e1b007c32a51ec8b24f717c5559721405d5ce15f5a81e78e346c4ec
|
7
|
+
data.tar.gz: bdc94a195a2f246874bc6d8e98b0b222c45e7a14efa4bfe913b760f489336b2955ed57f66c5663682c86fa5ffaf53a5656e12a6f9544806a13a56327b2b3aeb4
|
@@ -83,8 +83,10 @@ class CfnModel
|
|
83
83
|
lambda_fn_params = serverless_function_properties(cfn_hash, serverless_function)
|
84
84
|
|
85
85
|
cfn_hash['Resources'][resource_name] = lambda_function lambda_fn_params
|
86
|
-
|
87
86
|
cfn_hash['Resources']['FunctionNameRole'] = function_name_role
|
87
|
+
|
88
|
+
transform_function_events(cfn_hash, serverless_function, resource_name) if \
|
89
|
+
serverless_function['Properties']['Events']
|
88
90
|
end
|
89
91
|
|
90
92
|
def lambda_service_can_assume_role
|
@@ -140,6 +142,81 @@ class CfnModel
|
|
140
142
|
}
|
141
143
|
lambda_function_code(fn_resource, code_bucket, code_key)
|
142
144
|
end
|
145
|
+
|
146
|
+
# Return the Event structure of a AWS::Lambda::Function as created
|
147
|
+
# by Serverless transform
|
148
|
+
def transform_function_events(cfn_hash, serverless_function, function_name)
|
149
|
+
serverless_function['Properties']['Events'].each do |_, event|
|
150
|
+
serverlessrestapi_resources(cfn_hash, event, function_name) if event['Type'] == 'Api'
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
def serverlessrestapi_resources(cfn_hash, event, func_name)
|
155
|
+
# ServerlessRestApi
|
156
|
+
cfn_hash['Resources']['ServerlessRestApi'] ||= serverlessrestapi_base
|
157
|
+
add_serverlessrestapi_event(
|
158
|
+
cfn_hash['Resources']['ServerlessRestApi']['Properties']['Body']['paths'],
|
159
|
+
event,
|
160
|
+
func_name
|
161
|
+
)
|
162
|
+
|
163
|
+
# ServerlessRestApiDeployment
|
164
|
+
cfn_hash['Resources']['ServerlessRestApiDeployment'] = serverlessrestapi_deployment
|
165
|
+
|
166
|
+
# ServerlessRestApiProdStage
|
167
|
+
cfn_hash['Resources']['ServerlessRestApiProdStage'] = serverlessrestapi_stage
|
168
|
+
end
|
169
|
+
|
170
|
+
def serverlessrestapi_base
|
171
|
+
{
|
172
|
+
'Type' => 'AWS::ApiGateway::RestApi',
|
173
|
+
'Properties' => {
|
174
|
+
'Body' => {
|
175
|
+
'info' => {
|
176
|
+
'title' => { 'Ref' => 'AWS::StackName' },
|
177
|
+
'version' => '1.0'
|
178
|
+
},
|
179
|
+
'paths' => {},
|
180
|
+
'swagger' => '2.0'
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
end
|
185
|
+
|
186
|
+
def add_serverlessrestapi_event(paths_hash, event, function_name)
|
187
|
+
paths_hash[event['Properties']['Path']] = {
|
188
|
+
event['Properties']['Method'] => {
|
189
|
+
'responses' => {},
|
190
|
+
'x-amazon-apigateway-integration' => {
|
191
|
+
'httpMethod' => 'POST',
|
192
|
+
'type' => 'aws_proxy',
|
193
|
+
'uri' => { 'Fn::Sub' => "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${#{function_name}.Arn}/invocations" }
|
194
|
+
}
|
195
|
+
}
|
196
|
+
}
|
197
|
+
end
|
198
|
+
|
199
|
+
def serverlessrestapi_deployment
|
200
|
+
{
|
201
|
+
'Type' => 'AWS::ApiGateway::Deployment',
|
202
|
+
'Properties' => {
|
203
|
+
'Description' => 'Generated by cfn-model',
|
204
|
+
'RestApiId' => { 'Ref' => 'ServerlessRestApi' },
|
205
|
+
'StageName' => 'Stage'
|
206
|
+
}
|
207
|
+
}
|
208
|
+
end
|
209
|
+
|
210
|
+
def serverlessrestapi_stage
|
211
|
+
{
|
212
|
+
'Type' => 'AWS::ApiGateway::Stage',
|
213
|
+
'Properties' => {
|
214
|
+
'DeploymentId' => { 'Ref' => 'ServerlessRestApiDeployment' },
|
215
|
+
'RestApiId' => { 'Ref' => 'ServerlessRestApi' },
|
216
|
+
'StageName' => 'Prod'
|
217
|
+
}
|
218
|
+
}
|
219
|
+
end
|
143
220
|
end
|
144
221
|
end
|
145
222
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cfn-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Kascic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|