Пример #1
0
def test_event_source_lifecycle_kinesis(awsclient, vendored_folder,
                                        temp_lambda, temp_kinesis):
    log.info('running test_event_source_lifecycle_kinesis')

    lambda_name = temp_lambda[0]

    # lookup lambda arn
    lambda_client = awsclient.get_client('lambda')
    alias_name = 'ACTIVE'
    lambda_arn = lambda_client.get_alias(FunctionName=lambda_name,
                                         Name=alias_name)['AliasArn']

    # define event source
    evt_source = {
        #"arn":  "arn:aws:dynamodb:us-east-1:1234554:table/YourTable/stream/2016-05-11T00:00:00.000",
        "arn": temp_kinesis[1],
        "starting_position":
        "TRIM_HORIZON",  # Supported values: TRIM_HORIZON, LATEST
        "batch_size": 50,  # Max: 1000
        "enabled": True  # Default is false
    }

    # event source lifecycle
    _add_event_source(awsclient, evt_source, lambda_arn)
    status = _get_event_source_status(awsclient, evt_source, lambda_arn)
    assert status['EventSourceArn']
    _remove_event_source(awsclient, evt_source, lambda_arn)
Пример #2
0
def test_event_source_lifecycle_s3(awsclient, vendored_folder, temp_lambda,
                                   temp_bucket):
    log.info('running test_event_source_lifecycle_s3')

    lambda_name = temp_lambda[0]

    # lookup lambda arn
    lambda_client = awsclient.get_client('lambda')
    alias_name = 'ACTIVE'
    lambda_arn = lambda_client.get_alias(FunctionName=lambda_name,
                                         Name=alias_name)['AliasArn']

    # define event source
    bucket_arn = 'arn:aws:s3:::' + temp_bucket
    evt_source = {
        'arn': bucket_arn,
        'events': ['s3:ObjectCreated:*'],
        "suffix": ".gz"
    }

    # event source lifecycle
    _add_event_source(awsclient, evt_source, lambda_arn)
    status = _get_event_source_status(awsclient, evt_source, lambda_arn)
    assert status['EventSourceArn']
    _remove_event_source(awsclient, evt_source, lambda_arn)
Пример #3
0
def test_event_source_lifecycle_cloudwatch_pattern(awsclient, vendored_folder,
                                                   cleanup_lambdas_deprecated,
                                                   cleanup_roles):
    log.info('running test_event_source_lifecycle_cloudwatch_pattern')

    lambda_folder = './resources/sample_lambda_event_pattern/'

    temp_string = utils.random_string()
    lambda_name = 'jenkins_test_sample-lambda-event-pattern_' + temp_string
    role_name = 'unittest_%s_lambda' % temp_string
    role_arn = create_lambda_role_helper(awsclient, role_name)

    # create the function
    create_lambda_helper(awsclient,
                         lambda_name,
                         role_arn,
                         here(lambda_folder + 'handler.py'),
                         lambda_handler='handler.handler',
                         folders_from_file=[],
                         runtime='python2.7')

    cleanup_roles.append(role_name)
    cleanup_lambdas_deprecated.append(lambda_name)

    # lookup lambda arn
    # us-east-1 is the only region that implements lambda@edge
    lambda_client = awsclient.get_client('lambda')
    alias_name = 'ACTIVE'
    lambda_arn = lambda_client.get_alias(FunctionName=lambda_name,
                                         Name=alias_name)['AliasArn']

    # define event source
    evt_source = {
        "name": "ssm_parameter_changed",
        "input_path": "$.detail",
        "pattern": {
            "source": ["aws.ssm"],
            "detail-type": ["Parameter Store Change"]
        }
    }

    # event source lifecycle
    _add_event_source(awsclient, evt_source, lambda_arn)
    status = _get_event_source_status(awsclient, evt_source, lambda_arn)
    assert status['EventSourceArn']
    _remove_event_source(awsclient, evt_source, lambda_arn)
Пример #4
0
def test_event_source_lifecycle_cloudwatch_schedule(awsclient, vendored_folder,
                                                    temp_lambda):
    log.info('running test_event_source_lifecycle_cloudwatch_schedule')

    lambda_name = temp_lambda[0]

    # lookup lambda arn
    lambda_client = awsclient.get_client('lambda')
    alias_name = 'ACTIVE'
    lambda_arn = lambda_client.get_alias(FunctionName=lambda_name,
                                         Name=alias_name)['AliasArn']

    # define event source
    evt_source = {
        "name": "unittest_execute_backup",
        "schedule": "rate(1 minute)"
    }

    # event source lifecycle
    _add_event_source(awsclient, evt_source, lambda_arn)
    status = _get_event_source_status(awsclient, evt_source, lambda_arn)
    assert status['EventSourceArn']
    assert status['State'] == 'ENABLED'
    _remove_event_source(awsclient, evt_source, lambda_arn)
Пример #5
0
def test_event_source_lifecycle_sns(awsclient, vendored_folder, temp_lambda,
                                    temp_sns_topic):
    log.info('running test_event_source_lifecycle_sns')

    lambda_name = temp_lambda[0]

    # lookup lambda arn
    lambda_client = awsclient.get_client('lambda')
    alias_name = 'ACTIVE'
    lambda_arn = lambda_client.get_alias(FunctionName=lambda_name,
                                         Name=alias_name)['AliasArn']

    # define event source
    evt_source = {
        #"arn":  "arn:aws:sns:::your-event-topic-arn",
        "arn": temp_sns_topic[1],
        "events": ["sns:Publish"]
    }

    # event source lifecycle
    _add_event_source(awsclient, evt_source, lambda_arn)
    status = _get_event_source_status(awsclient, evt_source, lambda_arn)
    assert status['EventSourceArn']
    _remove_event_source(awsclient, evt_source, lambda_arn)