Best Python code snippet using localstack_python
kinesis.py
Source:kinesis.py
1# -*- coding: utf-8 -*-2# Copyright (c) 2014, 2015 Mitch Garnaat3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15import botocore.exceptions16import kappa.event_source.base17import logging18LOG = logging.getLogger(__name__)19class KinesisEventSource(kappa.event_source.base.EventSource):20 def __init__(self, context, config):21 super(KinesisEventSource, self).__init__(context, config)22 self._lambda = kappa.awsclient.create_client(23 'lambda', context.session)24 def _get_uuid(self, function):25 uuid = None26 response = self._lambda.call(27 'list_event_source_mappings',28 FunctionName=function.name,29 EventSourceArn=self.arn)30 LOG.debug(response)31 if len(response['EventSourceMappings']) > 0:32 uuid = response['EventSourceMappings'][0]['UUID']33 return uuid34 def add(self, function):35 try:36 response = self._lambda.call(37 'create_event_source_mapping',38 FunctionName=function.name,39 EventSourceArn=self.arn,40 BatchSize=self.batch_size,41 StartingPosition=self.starting_position,42 Enabled=self.enabled43 )44 LOG.debug(response)45 except Exception:46 LOG.exception('Unable to add event source')47 def enable(self, function):48 self._config['enabled'] = True49 try:50 response = self._lambda.call(51 'update_event_source_mapping',52 UUID=self._get_uuid(function),53 Enabled=self.enabled54 )55 LOG.debug(response)56 except Exception:57 LOG.exception('Unable to enable event source')58 def disable(self, function):59 self._config['enabled'] = False60 try:61 response = self._lambda.call(62 'update_event_source_mapping',63 FunctionName=function.name,64 Enabled=self.enabled65 )66 LOG.debug(response)67 except Exception:68 LOG.exception('Unable to disable event source')69 def update(self, function):70 response = None71 uuid = self._get_uuid(function)72 if uuid:73 try:74 response = self._lambda.call(75 'update_event_source_mapping',76 BatchSize=self.batch_size,77 Enabled=self.enabled,78 FunctionName=function.arn)79 LOG.debug(response)80 except Exception:81 LOG.exception('Unable to update event source')82 def remove(self, function):83 response = None84 uuid = self._get_uuid(function)85 if uuid:86 response = self._lambda.call(87 'delete_event_source_mapping',88 UUID=uuid)89 LOG.debug(response)90 return response91 def status(self, function):92 response = None93 LOG.debug('getting status for event source %s', self.arn)94 uuid = self._get_uuid(function)95 if uuid:96 try:97 response = self._lambda.call(98 'get_event_source_mapping',99 UUID=self._get_uuid(function))100 LOG.debug(response)101 except botocore.exceptions.ClientError:102 LOG.debug('event source %s does not exist', self.arn)103 response = None104 else:105 LOG.debug('No UUID for event source %s', self.arn)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!