コード例 #1
0
ファイル: test_package.py プロジェクト: Manelmc/chalice
 def test_can_generate_cloudwatch_event(self):
     function = self.lambda_function()
     event = models.CloudWatchEvent(
         resource_name='foo-event',
         rule_name='myrule',
         event_pattern='{"source": ["aws.ec2"]}',
         lambda_function=function,
     )
     template = self.template_gen.generate(
         [function, event]
     )
     resources = template['Resources']
     assert len(resources) == 1
     cfn_resource = list(resources.values())[0]
     assert cfn_resource['Properties']['Events'] == {
         'FooEvent': {
             'Type': 'CloudWatchEvent',
             'Properties': {
                 'Pattern': {
                     'source': [
                         'aws.ec2'
                     ]
                 }
             },
         },
     }
コード例 #2
0
ファイル: appgraph.py プロジェクト: devangmehta123/chalice
    def _create_cwe_subscription(
            self,
            config,  # type: Config
            deployment,  # type: models.DeploymentPackage
            event_source,  # type: app.CloudWatchEventConfig
            stage_name,  # type: str
    ):
        # type: (...) -> models.CloudWatchEvent
        lambda_function = self._create_lambda_model(
            config=config,
            deployment=deployment,
            name=event_source.name,
            handler_name=event_source.handler_string,
            stage_name=stage_name)

        resource_name = event_source.name + '-event'
        rule_name = '%s-%s-%s' % (config.app_name, config.chalice_stage,
                                  resource_name)
        cwe = models.CloudWatchEvent(
            resource_name=resource_name,
            rule_name=rule_name,
            event_pattern=json.dumps(event_source.event_pattern),
            lambda_function=lambda_function,
        )
        return cwe
コード例 #3
0
ファイル: test_package.py プロジェクト: Manelmc/chalice
 def test_can_generate_cloudwatch_event(self):
     function = self.lambda_function()
     event = models.CloudWatchEvent(
         resource_name='foo-event',
         rule_name='myrule',
         event_pattern='{"source": ["aws.ec2"]}',
         lambda_function=function,
     )
     template = self.template_gen.generate(
         [function, event]
     )
     rule = template['resource'][
         'aws_cloudwatch_event_rule'][event.resource_name]
     assert rule == {
         'name': event.resource_name,
         'event_pattern': event.event_pattern}
     target = template['resource'][
         'aws_cloudwatch_event_target'][event.resource_name]
     assert target == {
         'target_id': 'foo-event',
         'rule': '${aws_cloudwatch_event_rule.foo-event.name}',
         'arn': '${aws_lambda_function.foo.arn}'
     }