def test_s3_put_object_notification_with_lambda(self):
    bucket_name = ('bucket-%s' % short_uid())
    function_name = ('func-%s' % short_uid())
    table_name = ('table-%s' % short_uid())
    self.s3_client.create_bucket(Bucket=bucket_name)
    testutil.create_lambda_function(handler_file=TEST_LAMBDA_PYTHON_ECHO, func_name=function_name, runtime=LAMBDA_RUNTIME_PYTHON36)
    aws_stack.create_dynamodb_table(table_name=table_name, partition_key='uuid')
    self.s3_client.put_bucket_notification_configuration(Bucket=bucket_name, NotificationConfiguration={'LambdaFunctionConfigurations': [{'LambdaFunctionArn': aws_stack.lambda_function_arn(function_name), 'Events': ['s3:ObjectCreated:*']}]})
    obj = self.s3_client.put_object(Bucket=bucket_name, Key=table_name, Body='something..')
    etag = obj['ETag']
    time.sleep(2)
    table = aws_stack.connect_to_resource('dynamodb').Table(table_name)

    def check_table():
        rs = table.scan()
        self.assertEqual(len(rs['Items']), 1)
        return rs
    rs = retry(check_table, retries=4, sleep=3)
    record = rs['Items'][0]
    self.assertEqual(record['data']['s3']['bucket']['name'], bucket_name)
    self.assertEqual(record['data']['s3']['object']['eTag'], etag)
    self._delete_bucket(bucket_name, [table_name])
    lambda_client = aws_stack.connect_to_service('lambda')
    lambda_client.delete_function(FunctionName=function_name)
    dynamodb_client = aws_stack.connect_to_service('dynamodb')
    dynamodb_client.delete_table(TableName=table_name)
def test_s3_put_object_notification_with_lambda(self):
    bucket_name = ('bucket-%s' % short_uid())
    function_name = ('func-%s' % short_uid())
    table_name = ('table-%s' % short_uid())
    self.s3_client.create_bucket(Bucket=bucket_name)
    testutil.create_lambda_function(handler_file=TEST_LAMBDA_PYTHON_ECHO, func_name=function_name, runtime=LAMBDA_RUNTIME_PYTHON36)
    aws_stack.create_dynamodb_table(table_name=table_name, partition_key='uuid')
    self.s3_client.put_bucket_notification_configuration(Bucket=bucket_name, NotificationConfiguration={'LambdaFunctionConfigurations': [{'LambdaFunctionArn': aws_stack.lambda_function_arn(function_name), 'Events': ['s3:ObjectCreated:*']}]})
    obj = self.s3_client.put_object(Bucket=bucket_name, Key=table_name, Body='something..')
    etag = obj['ETag']
    time.sleep(2)
    table = aws_stack.connect_to_resource('dynamodb').Table(table_name)

    def check_table():
        rs = table.scan()
        self.assertEqual(len(rs['Items']), 1)
        return rs
    rs = retry(check_table, retries=4, sleep=3)
    record = rs['Items'][0]
    self.assertEqual(record['data']['s3']['bucket']['name'], bucket_name)
    self.assertEqual(record['data']['s3']['object']['eTag'], etag)
    self._delete_bucket(bucket_name, [table_name])
    lambda_client = aws_stack.connect_to_service('lambda')
    lambda_client.delete_function(FunctionName=function_name)
    dynamodb_client = aws_stack.connect_to_service('dynamodb')
    dynamodb_client.delete_table(TableName=table_name)