本文整理汇总了Python中c7n.cwe.CloudWatchEvents.get_ids方法的典型用法代码示例。如果您正苦于以下问题:Python CloudWatchEvents.get_ids方法的具体用法?Python CloudWatchEvents.get_ids怎么用?Python CloudWatchEvents.get_ids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c7n.cwe.CloudWatchEvents
的用法示例。
在下文中一共展示了CloudWatchEvents.get_ids方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: disabled_xtest_get_ids
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def disabled_xtest_get_ids(self):
self.assertEqual(
CloudWatchEvents.get_ids(
event_data('event-instance-state.json'),
{'type': 'ec2-instance-state'}),
['i-a2d74f12'])
self.assertEqual(
CloudWatchEvents.get_ids(
{'detail': event_data('event-cloud-trail-run-instances.json')},
{'type': 'cloudtrail', 'events': ['RunInstances']}),
['i-d49cf94c'])
示例2: test_asg_state
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_asg_state(self):
self.assertEqual(
CloudWatchEvents.get_ids(
event_data('event-asg-instance-failed.json'),
{'type': 'asg-instance-state',
'events': ['EC2 Instance Launch Unsuccessful']}),
['CustodianTest'])
示例3: test_get_ids_multiple_events
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_get_ids_multiple_events(self):
d = event_data('event-cloud-trail-run-instances.json')
d['eventName'] = 'StartInstances'
self.assertEqual(
CloudWatchEvents.get_ids(
{'detail': d},
{'type': 'cloudtrail', 'events': [
# wrong event name
{'source': 'ec2.amazonaws.com',
'event': 'CreateTags',
'ids': 'requestParameters.resourcesSet.items[].resourceId'},
# wrong event source
{'source': 'ecs.amazonaws.com',
'event': 'StartInstances',
'ids': 'responseElements.instancesSet.items'},
# matches no resource ids
{'source': 'ec2.amazonaws.com',
'event': 'StartInstances',
'ids': 'responseElements.instancesSet2.items[].instanceId'},
# correct
{'source': 'ec2.amazonaws.com',
'event': 'StartInstances',
'ids': 'responseElements.instancesSet.items[].instanceId'},
# we don't fall off the end
{'source': 'ec2.amazonaws.com',
'event': 'StartInstances',
'ids': 'responseElements.instancesSet.items[]'},
]}),
['i-784cdacd', u'i-7b4cdace'])
示例4: test_ec2_state
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_ec2_state(self):
self.assertEqual(
CloudWatchEvents.get_ids(
event_data("event-instance-state.json"), {"type": "ec2-instance-state"}
),
["i-a2d74f12"],
)
示例5: test_get_ids
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_get_ids(self):
self.assertEqual(
CloudWatchEvents.get_ids(
{"detail": event_data("event-cloud-trail-run-instances.json")},
{"type": "cloudtrail", "events": ["RunInstances"]},
),
["i-784cdacd", u"i-7b4cdace"],
)
示例6: test_custom_event
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_custom_event(self):
d = {'detail': event_data('event-cloud-trail-run-instances.json')}
d['detail']['eventName'] = 'StartInstances'
self.assertEqual(
CloudWatchEvents.get_ids(
d,
{'type': 'cloudtrail', 'events': [{
'event': 'StartInstances',
'ids': 'responseElements.instancesSet.items[].instanceId',
'source': 'ec2.amazonaws.com'}]}),
['i-784cdacd', u'i-7b4cdace'])
示例7: push
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def push(self, event, lambda_ctx):
"""Run policy in push mode against given event.
Lambda automatically generates cloud watch logs, and metrics
for us, albeit with some deficienies, metrics no longer count
against valid resources matches, but against execution.
Fortunately we already have replacements.
TODO: better customization around execution context outputs
TODO: support centralized lambda exec across accounts.
"""
mode = self.data.get('mode', {})
mode_type = mode.get('type')
if mode_type == 'periodic':
return self.poll()
resource_ids = CloudWatchEvents.get_ids(event, mode)
if resource_ids is None:
raise ValueError("Unknown push event mode %s" % self.data)
self.log.info('Found resource ids: %s' % resource_ids)
if not resource_ids:
self.log.warning("Could not find resource ids")
return
resources = self.resource_manager.get_resources(resource_ids)
if 'debug' in event:
self.log.info("Resources %s", resources)
resources = self.resource_manager.filter_resources(resources, event)
if 'debug' in event:
self.log.info("Filtered resources %d" % len(resources))
if not resources:
self.log.info("policy: %s resources: %s no resources matched" % (
self.name, self.resource_type))
return
self.ctx.metrics.put_metric(
'ResourceCount', len(resources), 'Count', Scope="Policy",
buffer=False)
if 'debug' in event:
self.log.info("Invoking actions %s", self.resource_manager.actions)
for action in self.resource_manager.actions:
self.log.info(
"policy: %s invoking action: %s resources: %d",
self.name, action.name, len(resources))
if isinstance(action, EventAction):
action.process(resources, event)
else:
action.process(resources)
return resources
示例8: test_asg_state
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_asg_state(self):
self.assertEqual(
CloudWatchEvents.get_ids(
event_data("event-asg-instance-failed.json"),
{
"type": "asg-instance-state",
"events": ["EC2 Instance Launch Unsuccessful"],
},
),
["CustodianTest"],
)
示例9: resolve_resources
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def resolve_resources(self, event):
mode = self.policy.data.get('mode', {})
resource_ids = CloudWatchEvents.get_ids(event, mode)
if resource_ids is None:
raise ValueError("Unknown push event mode %s" % self.data)
self.policy.log.info('Found resource ids: %s' % resource_ids)
if not resource_ids:
self.policy.log.warning("Could not find resource ids")
return []
resources = self.policy.resource_manager.get_resources(resource_ids)
if 'debug' in event:
self.policy.log.info("Resources %s", resources)
return resources
示例10: resolve_resources
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def resolve_resources(self, event):
self.assume_member(event)
mode = self.policy.data.get('mode', {})
resource_ids = CloudWatchEvents.get_ids(event, mode)
if resource_ids is None:
raise ValueError("Unknown push event mode %s", self.data)
self.policy.log.info('Found resource ids: %s', resource_ids)
# Handle multi-resource type events, like ec2 CreateTags
resource_ids = self.policy.resource_manager.match_ids(resource_ids)
if not resource_ids:
self.policy.log.warning("Could not find resource ids")
return []
resources = self.policy.resource_manager.get_resources(resource_ids)
if 'debug' in event:
self.policy.log.info("Resources %s", resources)
return resources
示例11: test_get_ids_multiple_events
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_get_ids_multiple_events(self):
d = event_data("event-cloud-trail-run-instances.json")
d["eventName"] = "StartInstances"
self.assertEqual(
CloudWatchEvents.get_ids(
{"detail": d},
{
"type": "cloudtrail",
"events": [
# wrong event name
{
"source": "ec2.amazonaws.com",
"event": "CreateTags",
"ids": "requestParameters.resourcesSet.items[].resourceId",
},
# wrong event source
{
"source": "ecs.amazonaws.com",
"event": "StartInstances",
"ids": "responseElements.instancesSet.items",
},
# matches no resource ids
{
"source": "ec2.amazonaws.com",
"event": "StartInstances",
"ids": "responseElements.instancesSet2.items[].instanceId",
},
# correct
{
"source": "ec2.amazonaws.com",
"event": "StartInstances",
"ids": "responseElements.instancesSet.items[].instanceId",
},
# we don't fall off the end
{
"source": "ec2.amazonaws.com",
"event": "StartInstances",
"ids": "responseElements.instancesSet.items[]",
},
],
},
),
["i-784cdacd", u"i-7b4cdace"],
)
示例12: test_custom_event
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_custom_event(self):
d = {"detail": event_data("event-cloud-trail-run-instances.json")}
d["detail"]["eventName"] = "StartInstances"
self.assertEqual(
CloudWatchEvents.get_ids(
d,
{
"type": "cloudtrail",
"events": [
{
"event": "StartInstances",
"ids": "responseElements.instancesSet.items[].instanceId",
"source": "ec2.amazonaws.com",
}
],
},
),
["i-784cdacd", u"i-7b4cdace"],
)
示例13: test_ec2_state
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_ec2_state(self):
self.assertEqual(
CloudWatchEvents.get_ids(
event_data('event-instance-state.json'),
{'type': 'ec2-instance-state'}),
['i-a2d74f12'])
示例14: test_get_ids
# 需要导入模块: from c7n.cwe import CloudWatchEvents [as 别名]
# 或者: from c7n.cwe.CloudWatchEvents import get_ids [as 别名]
def test_get_ids(self):
self.assertEqual(
CloudWatchEvents.get_ids(
{'detail': event_data('event-cloud-trail-run-instances.json')},
{'type': 'cloudtrail', 'events': ['RunInstances']}),
['i-784cdacd', u'i-7b4cdace'])