Я пытаюсь прочитать файл .csv
из корзины S3 через функцию Lambda на AWS.
CODE
private string GetCsvContentFromS3(S3Event s3Event)
{
string responseBody = string.Empty;
try
{
S3EventNotification.S3EventNotificationRecord eventRecord = s3Event.Records.First();
string bucketName = eventRecord.S3.Bucket.Name;
string keyName = eventRecord.S3.Object.Key;
_logger.LogTrace(EventIds.AFileHasBeenUploaded, () => $"A file has been uploaded: Bucket Name: {bucketName}, Key Name: {keyName}");
GetObjectRequest request = new GetObjectRequest
{
BucketName = bucketName,
Key = keyName
};
AmazonS3Client s3Client = new AmazonS3Client(BucketRegion);
_logger.LogInfo(
EventIds.AmazonS3ClientInitialized,
() => $"AmazonS3Client has been initialized with Region: {s3Client.Config.RegionEndpoint.DisplayName}");
using (GetObjectResponse response = s3Client.GetObjectAsync(request).Result)
using (Stream responseStream = response.ResponseStream)
using (StreamReader reader = new StreamReader(responseStream))
{
responseBody = reader.ReadToEnd(); // Now you process the response body.
}
}
catch (AmazonS3Exception e)
{
_logger.LogCritical(
EventIds.SomethingWentWrong,
() => $"AmazonS3Exception. Exception Message: {e.Message}");
}
catch (Exception e)
{
_logger.LogCritical(
EventIds.SomethingWentWrong,
() => $"Exception. Exception Message: {e.Message}");
}
return responseBody;
}
Код выбрасываетException
(последний улов в try / catch) с сообщением:
Exception. Exception Message: One or more errors occurred. (A task was canceled.)
Чего мне не хватает?