Skip to content
This repository was archived by the owner on Aug 14, 2024. It is now read-only.

Commit f522dfb

Browse files
committed
add CF support for Logs::SubscriptionFilter resources
1 parent 0728a51 commit f522dfb

File tree

4 files changed

+71
-15
lines changed

4 files changed

+71
-15
lines changed

localstack/services/cloudformation/service_models.py

+56
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,62 @@ def fetch_state(self, stack_name, resources):
285285
groups = logs.describe_log_groups(logGroupNamePrefix=group_name)['logGroups']
286286
return ([g for g in groups if g['logGroupName'] == group_name] or [None])[0]
287287

288+
@staticmethod
289+
def get_deploy_templates():
290+
return {
291+
'create': {
292+
'function': 'create_log_group',
293+
'parameters': {
294+
'logGroupName': 'LogGroupName'
295+
}
296+
},
297+
'delete': {
298+
'function': 'delete_log_group',
299+
'parameters': {
300+
'logGroupName': 'LogGroupName'
301+
}
302+
}
303+
}
304+
305+
306+
class LogsSubscriptionFilter(GenericBaseModel):
307+
@staticmethod
308+
def cloudformation_type():
309+
return 'AWS::Logs::SubscriptionFilter'
310+
311+
def get_physical_resource_id(self, attribute=None, **kwargs):
312+
return self.props.get('LogGroupName')
313+
314+
def fetch_state(self, stack_name, resources):
315+
props = self.props
316+
group_name = self.resolve_refs_recursively(stack_name, props.get('LogGroupName'), resources)
317+
filter_pattern = self.resolve_refs_recursively(stack_name, props.get('FilterPattern'), resources)
318+
logs = aws_stack.connect_to_service('logs')
319+
groups = logs.describe_subscription_filters(logGroupName=group_name)
320+
groups = [g for g in groups['subscriptionFilters'] if g.get('filterPattern') == filter_pattern]
321+
return (groups or [None])[0]
322+
323+
@staticmethod
324+
def get_deploy_templates():
325+
return {
326+
'create': {
327+
'function': 'put_subscription_filter',
328+
'parameters': {
329+
'logGroupName': 'LogGroupName',
330+
'filterName': 'LogGroupName', # there can only be one filter associated with a log group
331+
'filterPattern': 'FilterPattern',
332+
'destinationArn': 'DestinationArn'
333+
}
334+
},
335+
'delete': {
336+
'function': 'delete_subscription_filter',
337+
'parameters': {
338+
'logGroupName': 'LogGroupName',
339+
'filterName': 'LogGroupName'
340+
}
341+
}
342+
}
343+
288344

289345
class CloudFormationStack(GenericBaseModel):
290346
@staticmethod

localstack/services/route53/route53_listener.py

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Route53Backend(RegionBackend):
1212
def __init__(self):
1313
# maps zone ID to association details
1414
self.vpc_hosted_zone_associations = {}
15+
# maps delegation set ID to reusable delegation set details
16+
self.reusable_delegation_sets = {}
1517

1618

1719
class ProxyListenerRoute53(PersistingProxyListener):

localstack/utils/cloudformation/template_deployer.py

-14
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,6 @@ def get_apigw_resource_params(params, **kwargs):
146146
}
147147
}
148148
},
149-
'Logs::LogGroup': {
150-
'create': {
151-
'function': 'create_log_group',
152-
'parameters': {
153-
'logGroupName': 'LogGroupName'
154-
}
155-
},
156-
'delete': {
157-
'function': 'delete_log_group',
158-
'parameters': {
159-
'logGroupName': 'LogGroupName'
160-
}
161-
}
162-
},
163149
'Lambda::Version': {
164150
'create': {
165151
'function': 'publish_version',

tests/integration/templates/template23.yaml

+13-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ Resources:
3030
# - - aws/lambda/
3131
# - !Ref Environment
3232
# - -function
33+
LogSubscription:
34+
Type: AWS::Logs::SubscriptionFilter
35+
Properties:
36+
LogGroupName: !Ref LogGroup
37+
FilterPattern: "{$.userIdentity.type = Root}"
38+
DestinationArn: !GetAtt KinesisStream.Arn
39+
40+
KinesisStream:
41+
Type: AWS::Kinesis::Stream
42+
Properties:
43+
Name: stream-logs-sub-tgt-512
44+
ShardCount: 1
3345

3446
Role:
3547
Type: AWS::IAM::Role
@@ -105,4 +117,4 @@ Resources:
105117
}
106118
- {
107119
apiKey: !Ref ApiKey
108-
}
120+
}

0 commit comments

Comments
 (0)