Add cloudformation support for EventBridge
This commit is contained in:
parent
fc9cecc154
commit
7318523b50
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import functools
|
import functools
|
||||||
import json
|
import json
|
||||||
@ -18,6 +19,7 @@ from moto.ec2 import models as ec2_models
|
|||||||
from moto.ecs import models as ecs_models
|
from moto.ecs import models as ecs_models
|
||||||
from moto.elb import models as elb_models
|
from moto.elb import models as elb_models
|
||||||
from moto.elbv2 import models as elbv2_models
|
from moto.elbv2 import models as elbv2_models
|
||||||
|
from moto.events import models as events_models
|
||||||
from moto.iam import models as iam_models
|
from moto.iam import models as iam_models
|
||||||
from moto.kinesis import models as kinesis_models
|
from moto.kinesis import models as kinesis_models
|
||||||
from moto.kms import models as kms_models
|
from moto.kms import models as kms_models
|
||||||
@ -94,6 +96,7 @@ MODEL_MAP = {
|
|||||||
"AWS::SNS::Topic": sns_models.Topic,
|
"AWS::SNS::Topic": sns_models.Topic,
|
||||||
"AWS::S3::Bucket": s3_models.FakeBucket,
|
"AWS::S3::Bucket": s3_models.FakeBucket,
|
||||||
"AWS::SQS::Queue": sqs_models.Queue,
|
"AWS::SQS::Queue": sqs_models.Queue,
|
||||||
|
"AWS::Events::Rule": events_models.Rule,
|
||||||
}
|
}
|
||||||
|
|
||||||
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-name.html
|
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-name.html
|
||||||
|
@ -55,6 +55,24 @@ class Rule(BaseModel):
|
|||||||
if index is not None:
|
if index is not None:
|
||||||
self.targets.pop(index)
|
self.targets.pop(index)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def create_from_cloudformation_json(
|
||||||
|
cls, resource_name, cloudformation_json, region_name
|
||||||
|
):
|
||||||
|
properties = cloudformation_json["Properties"]
|
||||||
|
event_backend = events_backends[region_name]
|
||||||
|
event_name = properties.get("Name") or resource_name
|
||||||
|
return event_backend.put_rule(name=event_name, **properties)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def delete_from_cloudformation_json(
|
||||||
|
cls, resource_name, cloudformation_json, region_name
|
||||||
|
):
|
||||||
|
properties = cloudformation_json["Properties"]
|
||||||
|
event_backend = events_backends[region_name]
|
||||||
|
event_name = properties.get("Name") or resource_name
|
||||||
|
event_backend.delete_rule(name=event_name)
|
||||||
|
|
||||||
|
|
||||||
class EventBus(BaseModel):
|
class EventBus(BaseModel):
|
||||||
def __init__(self, region_name, name):
|
def __init__(self, region_name, name):
|
||||||
|
@ -596,6 +596,30 @@ def test_create_stack_kinesis():
|
|||||||
assert len(resources) == 1
|
assert len(resources) == 1
|
||||||
|
|
||||||
|
|
||||||
|
@mock_cloudformation_deprecated
|
||||||
|
def test_create_stack_events():
|
||||||
|
conn = boto.connect_cloudformation()
|
||||||
|
dummy_template = {
|
||||||
|
"AWSTemplateFormatVersion": "2010-09-09",
|
||||||
|
"Description": "Stack Kinesis Test 1",
|
||||||
|
"Parameters": {},
|
||||||
|
"Resources": {
|
||||||
|
"event": {
|
||||||
|
"Type": "AWS::Events::Rule",
|
||||||
|
"Properties": {
|
||||||
|
"State": "ENABLED",
|
||||||
|
"ScheduleExpression": "rate(5 minutes)",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
conn.create_stack("test_stack_events_1", template_body=json.dumps(dummy_template))
|
||||||
|
stack = conn.describe_stacks()[0]
|
||||||
|
|
||||||
|
resources = stack.list_resources()
|
||||||
|
resources.should.have.length_of(1)
|
||||||
|
|
||||||
|
|
||||||
def get_role_name():
|
def get_role_name():
|
||||||
with mock_iam_deprecated():
|
with mock_iam_deprecated():
|
||||||
iam = boto.connect_iam()
|
iam = boto.connect_iam()
|
||||||
|
Loading…
Reference in New Issue
Block a user