本文整理匯總了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'])