How to use the zappa.utilities.add_event_source function in zappa

To help you get started, we’ve selected a few zappa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Miserlou / Zappa / tests / tests_placebo.py View on Github external
def test_add_event_source(self, session):

        event_source = {'arn': 'blah:blah:blah:blah', 'events': [
                    "s3:ObjectCreated:*"
                  ]}
        # Sanity. This should fail.
        try:
            es = add_event_source(event_source, 'blah:blah:blah:blah', 'test_settings.callback', session)
            self.fail("Success should have failed.")
        except ValueError:
            pass

        event_source = {'arn': 's3:s3:s3:s3', 'events': [
                    "s3:ObjectCreated:*"
                  ]}
        add_event_source(event_source, 'lambda:lambda:lambda:lambda', 'test_settings.callback', session, dry=True)
        remove_event_source(event_source, 'lambda:lambda:lambda:lambda', 'test_settings.callback', session, dry=True)
        # get_event_source_status(event_source, 'lambda:lambda:lambda:lambda', 'test_settings.callback', session, dry=True)
github Miserlou / Zappa / tests / tests_placebo.py View on Github external
def test_add_event_source(self, session):

        event_source = {'arn': 'blah:blah:blah:blah', 'events': [
                    "s3:ObjectCreated:*"
                  ]}
        # Sanity. This should fail.
        try:
            es = add_event_source(event_source, 'blah:blah:blah:blah', 'test_settings.callback', session)
            self.fail("Success should have failed.")
        except ValueError:
            pass

        event_source = {'arn': 's3:s3:s3:s3', 'events': [
                    "s3:ObjectCreated:*"
                  ]}
        add_event_source(event_source, 'lambda:lambda:lambda:lambda', 'test_settings.callback', session, dry=True)
        remove_event_source(event_source, 'lambda:lambda:lambda:lambda', 'test_settings.callback', session, dry=True)
        # get_event_source_status(event_source, 'lambda:lambda:lambda:lambda', 'test_settings.callback', session, dry=True)
github Miserlou / Zappa / zappa / core.py View on Github external
print("Problem scheduling {} with expression {}.".format(rule_name, expression))

            elif event_source:
                service = self.service_from_arn(event_source['arn'])

                if service not in pull_services:
                    svc = ','.join(event['event_source']['events'])
                    self.create_event_permission(
                        lambda_name,
                        service + '.amazonaws.com',
                        event['event_source']['arn']
                    )
                else:
                    svc = service

                rule_response = add_event_source(
                    event_source,
                    lambda_arn,
                    function,
                    self.boto_session
                )

                if rule_response == 'successful':
                    print("Created {} event schedule for {}!".format(svc, function))
                elif rule_response == 'failed':
                    print("Problem creating {} event schedule for {}!".format(svc, function))
                elif rule_response == 'exists':
                    print("{} event schedule for {} already exists - Nothing to do here.".format(svc, function))
                elif rule_response == 'dryrun':
                    print("Dryrun for creating {} event schedule for {}!!".format(svc, function))
            else:
                print("Could not create event {} - Please define either an expression or an event source".format(name))
github Miserlou / Zappa / zappa / core.py View on Github external
topic_arn = self.sns_client.create_topic(
            Name=topic_name)['TopicArn']
        # Create subscription
        self.sns_client.subscribe(
            TopicArn=topic_arn,
            Protocol='lambda',
            Endpoint=lambda_arn
        )
        # Add Lambda permission for SNS to invoke function
        self.create_event_permission(
            lambda_name=lambda_name,
            principal='sns.amazonaws.com',
            source_arn=topic_arn
        )
        # Add rule for SNS topic as a event source
        add_event_source(
            event_source={
                "arn": topic_arn,
                "events": ["sns:Publish"]
            },
            lambda_arn=lambda_arn,
            target_function="zappa.async.route_task",
            boto_session=self.boto_session
        )
        return topic_arn