public AwsSqsFacade(IAspectLogger logger) { _logger = logger; _sqsClient = new AmazonSQSClient(); var numQueuesStr = Environment.GetEnvironmentVariable(NUM_SQS_QUEUES_ENVIRONMENT_VARIABLE_LOOKUP); if (string.IsNullOrEmpty(numQueuesStr)) { throw new Exception($"Missing Lambda Variable {NUM_SQS_QUEUES_ENVIRONMENT_VARIABLE_LOOKUP}"); } if (!int.TryParse(numQueuesStr, out _numSqsQueues) || _numSqsQueues < 1) { throw new Exception($"Invalid Lambda Variable {NUM_SQS_QUEUES_ENVIRONMENT_VARIABLE_LOOKUP}: value must be a positive integer"); } _sqsQueueUrls = new string[_numSqsQueues]; for (int i = 0; i < _numSqsQueues; ++i) { _sqsQueueUrls[i] = ParseQueue(i + 1); _logger.Debug($"SqsQueueUrl{i+1}: {_sqsQueueUrls[i]}"); } _sqsQueueMessageGroupId = Environment.GetEnvironmentVariable(SQS_QUEUE_MESSAGE_GROUP_ID_ENVIRONMENT_VARIABLE_LOOKUP); if (string.IsNullOrEmpty(_sqsQueueMessageGroupId)) { throw new Exception($"Missing Lambda Variable {SQS_QUEUE_MESSAGE_GROUP_ID_ENVIRONMENT_VARIABLE_LOOKUP}"); } _sqsQueueMessageGroupId = _sqsQueueMessageGroupId.Trim(); _logger.Debug($"SqsQueueMessagGroupId: {_sqsQueueMessageGroupId}"); }
public async Task AspectKinesisHandler(KinesisEvent kinesisEvent, ILambdaContext context) { if (_logger == null) { _logger = new AspectAwsLambdaLogger.AspectAwsLambdaLogger(context.Logger); //NOTE: Needed for Test or if using CloudWatch and not using NLog->CloudWatch setup in constructor } if (_sqsFacade == null) { _sqsFacade = new AwsSqsFacade(_logger); //NOTE: Needed for Test or if using CloudWatch and not using NLog->CloudWatch setup in constructor } _logger.Debug($"DynamoDbTableName: {_dynamoDbTableName}"); _logger.Trace("Beginning AspectKinesisHandler"); _logger.Info($"Record Count: {kinesisEvent.Records.Count}"); bool writeEventsToQueue = Convert.ToBoolean(Environment.GetEnvironmentVariable(WRITE_EVENTS_TO_QUEUE_ENVIRONMENT_VARIABLE_LOOKUP)); _logger.Debug($"WriteEventsToQueue: {writeEventsToQueue}"); foreach (var record in kinesisEvent.Records) { await ProcessEventRecord(record, writeEventsToQueue); } _logger.Trace("Ending AspectKinesisHandler"); }
public async Task AspectKinesisHandler(KinesisEvent kinesisEvent, ILambdaContext context) { if (_logger == null) { _logger = new AspectAwsLambdaLogger.AspectAwsLambdaLogger(context.Logger); //NOTE: Needed for Test or if using CloudWatch and not using NLog->CloudWatch setup in constructor } if (_sqsFacade == null) { _sqsFacade = new AwsSqsFacade(_logger); //NOTE: Needed for Test or if using CloudWatch and not using NLog->CloudWatch setup in constructor } _logger.Debug($"DynamoDbTableName: {_dynamoDbTableName}"); _logger.Trace("Beginning AspectKinesisHandler"); _logger.Info($"Record Count: {kinesisEvent.Records.Count}"); var writeEventsToQueue = await ReadWriteEventsToQueueFlag(); _logger.Debug($"WriteEventsToQueue: {writeEventsToQueue}"); foreach (var record in kinesisEvent.Records) { await ProcessEventRecord(record, writeEventsToQueue); } _logger.Trace("Ending AspectKinesisHandler"); }
public AwsSqsFacade(IAspectLogger logger) { _logger = logger; _sqsClient = new AmazonSQSClient(); _sqsQueueUrl = Environment.GetEnvironmentVariable(SQS_QUEUE_URL_ENVIRONMENT_VARIABLE_LOOKUP); var sqsQueueName = Environment.GetEnvironmentVariable(SQS_QUEUE_NAME_ENVIRONMENT_VARIABLE_LOOKUP); var sqsQueueOwner = Environment.GetEnvironmentVariable(SQS_QUEUE_OWNER_ENVIRONMENT_VARIABLE_LOOKUP); if (!string.IsNullOrEmpty(_sqsQueueUrl)) { _sqsQueueUrl = _sqsQueueUrl.Trim(); } if (string.IsNullOrEmpty(_sqsQueueUrl)) { if (string.IsNullOrEmpty(sqsQueueName)) { throw new Exception($"Missing Lambda Variable {SQS_QUEUE_NAME_ENVIRONMENT_VARIABLE_LOOKUP} or {SQS_QUEUE_URL_ENVIRONMENT_VARIABLE_LOOKUP}"); } sqsQueueName = sqsQueueName.Trim(); _logger.Debug($"SqsQueueName: {sqsQueueName}"); if (string.IsNullOrEmpty(sqsQueueOwner)) { throw new Exception($"Missing Lambda Variable {SQS_QUEUE_OWNER_ENVIRONMENT_VARIABLE_LOOKUP} or {SQS_QUEUE_URL_ENVIRONMENT_VARIABLE_LOOKUP}"); } sqsQueueOwner = sqsQueueOwner.Trim(); _logger.Debug($"SqsQueueOwner: {sqsQueueOwner}"); var request = new GetQueueUrlRequest { QueueName = sqsQueueName, QueueOwnerAWSAccountId = sqsQueueOwner }; //NOTE: Throws error if does not exist var response = _sqsClient.GetQueueUrlAsync(request).Result; _sqsQueueUrl = response.QueueUrl; } _logger.Debug($"SqsQueueUrl: {_sqsQueueUrl}"); _sqsQueueMessageGroupId = Environment.GetEnvironmentVariable(SQS_QUEUE_MESSAGE_GROUP_ID_ENVIRONMENT_VARIABLE_LOOKUP); if (string.IsNullOrEmpty(_sqsQueueMessageGroupId)) { throw new Exception($"Missing Lambda Variable {SQS_QUEUE_MESSAGE_GROUP_ID_ENVIRONMENT_VARIABLE_LOOKUP}"); } _sqsQueueMessageGroupId = _sqsQueueMessageGroupId.Trim(); _logger.Debug($"SqsQueueMessagGroupId: {_sqsQueueMessageGroupId}"); }
private void InitializeLogger() { _aspectLogger = new AspectLogger(LogManager.GetLogger(nameof(AspectLogger))); }
public LoggingInterceptor(IAspectLogger aspectLogger) { _aspectLogger = aspectLogger; }