예제 #1
0
 def setUpClass(cls):
     cls._logger = taco.logger.logger.get_logger('TestDynamoDB')
     cls._ssm_wrapper = ssm_wrapper.SSMWrapper(logger=cls._logger)
     cls._auto_scaler = auto_scaler_wrapper.AutoScalerWrapper(
         logger=cls._logger,
         aws_access_key=cls._ssm_wrapper.aws_access_key,
         aws_secret_key=cls._ssm_wrapper.aws_secret_key)
     cls._dynamodb_wrapper = dynamodb_wrapper.DynamoDBWrapper(
         logger=cls._logger,
         aws_access_key=cls._ssm_wrapper.aws_access_key,
         aws_secret_key=cls._ssm_wrapper.aws_secret_key,
         region_name=dynamodb_test_consts.DEFAULT_REGION,
         auto_scaler=cls._auto_scaler)
     cls._table_list = []
예제 #2
0
def initialize_wrappers(aws_access_key=None,
                        aws_secret_key=None,
                        region_name=Regions.n_virginia.value):
    # ---- Logger ----
    logger = taco.logger.logger.get_logger(name='initialize_wrappers_samples')

    # ---- AWS Services ----

    # SSM
    ssm = ssm_wrapper.SSMWrapper(logger=logger)
    if aws_secret_key is None:
        aws_secret_key = ssm.aws_secret_key

    if aws_access_key is None:
        aws_access_key = ssm.aws_access_key

    wrappers_default_kwargs = {
        'logger': logger,
        'aws_access_key': aws_access_key,
        'aws_secret_key': aws_secret_key,
        'region_name': region_name
    }

    # SQS
    sqs = sqs_wrapper.SQSWrapper(**wrappers_default_kwargs)

    # S3 wrapper
    s3 = s3_wrapper.S3Wrapper(**wrappers_default_kwargs)

    # Auto Scaler
    auto_scaler = auto_scaler_wrapper.AutoScalerWrapper(
        **wrappers_default_kwargs)

    # DynamoDB - without auto scaler
    dynamodb = dynamodb_wrapper.DynamoDBWrapper(**wrappers_default_kwargs)
    dynamodb_with_auto_scaler = dynamodb_wrapper.DynamoDBWrapper(
        auto_scaler=auto_scaler, **wrappers_default_kwargs)
예제 #3
0
    def setUpClass(cls):
        cls._logger = taco.logger.logger.get_logger(cls.__name__)
        cls._mutex_table_name = 'mutex_{0}'.format(uuid.uuid1())
        cls._ssm_wrapper = ssm_wrapper.SSMWrapper(logger=cls._logger)
        cls._dynamodb_wrapper = dynamodb_wrapper_module.DynamoDBWrapper(
            logger=cls._logger,
            aws_access_key=cls._ssm_wrapper.aws_access_key,
            aws_secret_key=cls._ssm_wrapper.aws_secret_key,
            region_name=message_duplication_handler_tests_consts.DEFAULT_REGION
        )

        # Create the mutex table
        cls._dynamodb_wrapper.create_table(
            mutex_table_creation_config.MutexTableCreation(
                table_name=cls._mutex_table_name))
예제 #4
0
파일: test.py 프로젝트: Intsights/taco
    def setUpClass(cls):
        cls._logger = taco.logger.logger.get_logger('TestRuntimeConfigManager')
        cls._ssm_wrapper = ssm_wrapper.SSMWrapper(logger=cls._logger)

        # Create Run Time Config Table
        cls._table_name = 'test_ref_count_{0}'.format(uuid.uuid1())
        cls._dynamodb_wrapper = dynamodb_wrapper_module.DynamoDBWrapper(
            logger=cls._logger,
            aws_access_key=cls._ssm_wrapper.aws_access_key,
            aws_secret_key=cls._ssm_wrapper.aws_secret_key)
        cls._dynamodb_wrapper.create_table(
            ref_count_table_creation_config.RefCountTableCreation(
                table_name=cls._table_name))
        cls._ref_count_manager = ref_count_manager.RefCountManager(
            cls._dynamodb_wrapper, table_name=cls._table_name)
예제 #5
0
 def __init__(self,
              reprocess_timeout=message_duplication_global_consts.
              REPROCESS_TIMEOUT,
              is_chalice_function=False,
              logger=None,
              mutex_table_name=None):
     super().__init__(logger=logger)
     self._reprocess_timeout = reprocess_timeout
     self._is_chalice_function = is_chalice_function
     self._mutex_table_name = mutex_table_name
     self._ssm_wrapper = ssm_wrapper.SSMWrapper(logger=self._logger)
     self._dynamodb_wrapper = dynamodb_wrapper_module.DynamoDBWrapper(
         logger=self._logger,
         aws_access_key=self._ssm_wrapper.aws_access_key,
         aws_secret_key=self._ssm_wrapper.aws_secret_key)
예제 #6
0
파일: test.py 프로젝트: Intsights/taco
    def setUpClass(cls):
        cls._logger = taco.logger.logger.get_logger('TestCloudMutex')
        cls._ssm_wrapper = ssm_wrapper.SSMWrapper(logger=cls._logger)
        cls._dynamodb_wrapper = dynamodb_wrapper_module.DynamoDBWrapper(
            logger=cls._logger,
            aws_access_key=cls._ssm_wrapper.aws_access_key,
            aws_secret_key=cls._ssm_wrapper.aws_secret_key,
            region_name=mutex_tests_consts.DEFAULT_REGION)
        cls._mutex_table_name = 'mutex_{0}'.format(uuid.uuid1())
        cls._dynamodb_wrapper.create_table(
            mutex_table_creation_config.MutexTableCreation(
                table_name=cls._mutex_table_name))

        cls._default_mutex_kwargs = {
            'logger': cls._logger,
            'table_name': cls._mutex_table_name,
            'dynamodb_wrapper': cls._dynamodb_wrapper
        }
예제 #7
0
    def setUpClass(cls):
        cls._logger = taco.logger.logger.get_logger('TestAutoScaler')
        cls._ssm_wrapper = ssm_wrapper.SSMWrapper(logger=cls._logger)
        aws_access_key = cls._ssm_wrapper.aws_access_key
        aws_secret_key = cls._ssm_wrapper.aws_secret_key
        cls._dynamodb_wrapper = dynamodb_wrapper.DynamoDBWrapper(
            logger=cls._logger,
            aws_access_key=aws_access_key,
            aws_secret_key=aws_secret_key,
            region_name=test_consts.DEFAULT_REGION)
        cls._auto_scaler_wrapper = auto_scaler_wrapper.AutoScalerWrapper(
            logger=cls._logger,
            region_name=test_consts.DEFAULT_REGION,
            aws_access_key=aws_access_key,
            aws_secret_key=aws_secret_key)

        cls._table_name = str(uuid.uuid1())
        cls._resource_id = 'table/{table_name}'.format(
            table_name=cls._table_name)
        cls._dynamodb_wrapper.create_table(
            mutex_table_creation_config.MutexTableCreation(
                table_name=cls._table_name))
예제 #8
0
def hello_world(aws_access_key=None,
                aws_secret_key=None,
                region_name=Regions.n_virginia.value):
    logger = taco.logger.logger.get_logger(name='hello_world')

    ssm = ssm_wrapper.SSMWrapper(logger=logger)
    if aws_secret_key is None:
        aws_secret_key = ssm.aws_secret_key

    if aws_access_key is None:
        aws_access_key = ssm.aws_access_key

    wrappers_default_kwargs = {
        'logger': logger,
        'aws_access_key': aws_access_key,
        'aws_secret_key': aws_secret_key,
        'region_name': region_name
    }

    sqs = sqs_wrapper.SQSWrapper(**wrappers_default_kwargs)
    s3 = s3_wrapper.S3Wrapper(**wrappers_default_kwargs)
    dynamo = dynamodb_wrapper.DynamoDBWrapper(**wrappers_default_kwargs)

    # SQS create queue
    queue_name = 'queue_name'
    creating_sqs_config = sqs_configs.SQSCreationConfig(
        queue_name, enable_dead_letter_queue=True, force_clean_queue=False)
    sqs.create_queue(creating_sqs_config)

    # SQS send message
    sqs.send_message(
        queue_name,
        data='with all this romantic atmosphere Disaster\'s in the air')

    # read a message
    read_message = sqs.read_message(queue_name=queue_name,
                                    delete_after_receive=True)

    # S3 create bucket
    bucket_name = str(uuid.uuid1().hex)
    s3.create_bucket(bucket_name, region_name=Regions.ohio.value)

    # upload the data to s3
    file_path = 'hello_world'
    s3.upload_data_to_file(bucket_name=bucket_name,
                           file_path=file_path,
                           data=read_message.data)

    # update file metadata
    new_metadata = {'a': 'b'}
    s3.update_file_metadata(bucket_name=bucket_name,
                            file_path=file_path,
                            new_metadata=new_metadata)

    print(s3.get_file_data(bucket_name=bucket_name, file_path=file_path))
    print(s3.get_file_metadata(bucket_name=bucket_name, file_path=file_path))

    # DynamoDB create table
    table_name = 'table_name'
    primary_key_name = 'primary_key_name'
    attribute_definitions = [
        dynamodb_consts.property_schema(
            primary_key_name, dynamodb_consts.AttributeTypes.string_type.value)
    ]
    primary_keys = [
        dynamodb_consts.property_schema(
            primary_key_name, dynamodb_consts.PrimaryKeyTypes.hash_type.value)
    ]
    table_config = table_creation_config.TableCreationConfig(
        table_name=table_name,
        primary_keys=primary_keys,
        attribute_definitions=attribute_definitions)
    dynamo.create_table(table_config)

    # Add raw to table
    primary_key_value = 'primary_key_value'
    item_to_put = {
        primary_key_name: primary_key_value,
        'another random key': 25
    }
    dynamo.put_item(table_name, item_to_put)

    # Read from Dynamo
    get_requests = dynamodb_consts.batch_get_config(table_name,
                                                    primary_key_name,
                                                    [primary_key_value])
    print(dynamo.batch_get(get_requests))

    # delete the bucket and the sqs
    s3.delete_bucket(bucket_name=bucket_name, delete_non_empty_bucket=True)
    sqs.delete_queue(queue_name=queue_name)
    dynamo.delete_table(table_name=table_name)