diff --git a/.doc_gen/cross-content/cross_FSA_NetV3_block.xml b/.doc_gen/cross-content/cross_FSA_NetV3_block.xml index e778df46c48..23b074c624a 100644 --- a/.doc_gen/cross-content/cross_FSA_NetV3_block.xml +++ b/.doc_gen/cross-content/cross_FSA_NetV3_block.xml @@ -28,6 +28,6 @@ The full app can be deployed with the &CDK;. For source code and deployment instructions, see the project in + url="https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/dotnetv3/cross-service/FeedbackSentimentAnalyzer"> GitHub. \ No newline at end of file diff --git a/dotnetv3/cross-service/FeedbackSentimentAnalyzer/README.md b/dotnetv3/cross-service/FeedbackSentimentAnalyzer/README.md index b83dc81f71b..8925c6b5b53 100644 --- a/dotnetv3/cross-service/FeedbackSentimentAnalyzer/README.md +++ b/dotnetv3/cross-service/FeedbackSentimentAnalyzer/README.md @@ -19,4 +19,4 @@ This document discusses the language-specific nuances of deploying the Feedback ### .NET Implementation Details - This example includes AWS Lambda functions for the various operations of the Feedback Sentiment Analyzer. - Each function was created using the AWS Lambda Template from the [AWS Toolkit for Visual Studio](https://aws.amazon.com/visualstudio/). - - Each function also uses [Powertools for AWS Lamba (.NET)](https://github.com/aws-powertools/powertools-lambda-dotnet) for enhanced logging. \ No newline at end of file + - Each function also uses [Powertools for AWS Lambda (.NET)](https://github.com/aws-powertools/powertools-lambda-dotnet) for enhanced logging. \ No newline at end of file diff --git a/dotnetv3/cross-service/PhotoAssetManager/PamApi/Controllers/ApiController.cs b/dotnetv3/cross-service/PhotoAssetManager/PamApi/Controllers/ApiController.cs index 08a12c62fa5..435d0bacf1e 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/PamApi/Controllers/ApiController.cs +++ b/dotnetv3/cross-service/PhotoAssetManager/PamApi/Controllers/ApiController.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using Amazon.Lambda.Core; +using AWS.Lambda.Powertools.Logging; using Microsoft.AspNetCore.Mvc; using PamServices; @@ -51,7 +52,7 @@ public IActionResult Upload([FromBody] UploadRequest uploadRequest) [HttpGet("labels")] public async Task Get() { - LambdaLogger.Log($"Test logging: getting labels."); + Logger.LogInformation($"Getting labels."); var allLabels = await _labelService.GetAllItems(); var response = new LabelsResponse(allLabels.ToList()); return Ok(response); diff --git a/dotnetv3/cross-service/PhotoAssetManager/PamApi/DetectLabelsFunction.cs b/dotnetv3/cross-service/PhotoAssetManager/PamApi/DetectLabelsFunction.cs index 75df8d90b82..cf4ddb7d972 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/PamApi/DetectLabelsFunction.cs +++ b/dotnetv3/cross-service/PhotoAssetManager/PamApi/DetectLabelsFunction.cs @@ -9,6 +9,7 @@ using Amazon.Rekognition; using Amazon.S3; using Amazon.Util; +using AWS.Lambda.Powertools.Logging; using PamServices; // Assembly attribute to enable the AWS Lambda function's JSON input to be converted into a .NET class. @@ -66,19 +67,16 @@ public async Task FunctionHandler(S3Event evnt, ILambdaContext context) var s3Event = evnt.Records?[0].S3; try { - context.Logger.LogInformation( - $"Processing object {s3Event!.Object.Key} from bucket {s3Event.Bucket.Name}"); + Logger.LogInformation($"Processing object {s3Event!.Object.Key} from bucket {s3Event.Bucket.Name}"); var detectedLabels = await _imageService.DetectLabels(s3Event.Object.Key, s3Event.Bucket.Name); await _labelService.AddImageLabels(s3Event.Object.Key, detectedLabels); - context.Logger.LogInformation( - $"Added labels {string.Join(',', detectedLabels)}"); + Logger.LogInformation($"Added labels {string.Join(',', detectedLabels)}"); } catch (Exception e) { - context.Logger.LogInformation($"Error getting object {s3Event!.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function."); - context.Logger.LogInformation(e.Message); - context.Logger.LogInformation(e.StackTrace); + Logger.LogError($"Error getting object {s3Event!.Object.Key} from bucket {s3Event.Bucket.Name}. " + + $"Make sure they exist and your bucket is in the same region as this function.", e); throw; } } diff --git a/dotnetv3/cross-service/PhotoAssetManager/PamApi/DownloadFunction.cs b/dotnetv3/cross-service/PhotoAssetManager/PamApi/DownloadFunction.cs index 834089ee476..926d2e41511 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/PamApi/DownloadFunction.cs +++ b/dotnetv3/cross-service/PhotoAssetManager/PamApi/DownloadFunction.cs @@ -1,7 +1,6 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -using System.Text.Json; using Amazon; using Amazon.DynamoDBv2; using Amazon.DynamoDBv2.DataModel; @@ -9,6 +8,7 @@ using Amazon.S3; using Amazon.SimpleNotificationService; using Amazon.Util; +using AWS.Lambda.Powertools.Logging; using PamServices; namespace PamApi; @@ -69,7 +69,7 @@ public async Task FunctionHandler(DownloadRequest request, ILambdaContext contex try { - context.Logger.LogInformation($"Starting download and zip operation: {JsonSerializer.Serialize(request)}"); + Logger.LogInformation($"Starting download and zip operation.", request); var labelsList = request.labels.ToList(); var imageKeys = await _labelService.GetAllImagesForLabels(labelsList); var zipArchiveUrl = @@ -77,13 +77,11 @@ await _storageService.GenerateZipFromImages(imageKeys, storageBucketName!, workingBucketName!); await _notificationService.SendNotification(topicArn!, "Image download", $"Your images are available here: {zipArchiveUrl}"); - LambdaLogger.Log($"url: {zipArchiveUrl}"); + Logger.LogInformation($"url: {zipArchiveUrl}"); } catch (Exception e) { - context.Logger.LogInformation($"Error starting download."); - context.Logger.LogInformation(e.Message); - context.Logger.LogInformation(e.StackTrace); + Logger.LogError(e, $"Error starting download."); throw; } } diff --git a/dotnetv3/cross-service/PhotoAssetManager/PamApi/PamApi.csproj b/dotnetv3/cross-service/PhotoAssetManager/PamApi/PamApi.csproj index bcaf76da39f..305b7b310ae 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/PamApi/PamApi.csproj +++ b/dotnetv3/cross-service/PhotoAssetManager/PamApi/PamApi.csproj @@ -28,6 +28,7 @@ + diff --git a/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/DetectLabelsFunction.cs b/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/DetectLabelsFunction.cs index 5100d8da871..65ea97a92d0 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/DetectLabelsFunction.cs +++ b/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/DetectLabelsFunction.cs @@ -9,6 +9,7 @@ using Amazon.Rekognition; using Amazon.S3; using Amazon.Util; +using AWS.Lambda.Powertools.Logging; using PamServices; // Assembly attribute to enable the AWS Lambda function's JSON input to be converted into a .NET class. @@ -66,19 +67,16 @@ public async Task FunctionHandler(S3Event evnt, ILambdaContext context) var s3Event = evnt.Records?[0].S3; try { - context.Logger.LogInformation( - $"Processing object {s3Event!.Object.Key} from bucket {s3Event.Bucket.Name}"); + Logger.LogInformation($"Processing object {s3Event!.Object.Key} from bucket {s3Event.Bucket.Name}"); var detectedLabels = await _imageService.DetectLabels(s3Event.Object.Key, s3Event.Bucket.Name); await _labelService.AddImageLabels(s3Event.Object.Key, detectedLabels); - context.Logger.LogInformation( - $"Added labels {string.Join(',', detectedLabels)}"); + Logger.LogInformation($"Added labels {string.Join(',', detectedLabels)}"); } catch (Exception e) { - context.Logger.LogInformation($"Error getting object {s3Event!.Object.Key} from bucket {s3Event.Bucket.Name}. Make sure they exist and your bucket is in the same region as this function."); - context.Logger.LogInformation(e.Message); - context.Logger.LogInformation(e.StackTrace); + Logger.LogError($"Error getting object {s3Event!.Object.Key} from bucket {s3Event.Bucket.Name}. " + + $"Make sure they exist and your bucket is in the same region as this function.", e); throw; } } diff --git a/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/DownloadFunction.cs b/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/DownloadFunction.cs index 41c0da66da9..0342aa660b6 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/DownloadFunction.cs +++ b/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/DownloadFunction.cs @@ -9,6 +9,7 @@ using Amazon.S3; using Amazon.SimpleNotificationService; using Amazon.Util; +using AWS.Lambda.Powertools.Logging; using PamApi; using PamServices; @@ -70,7 +71,7 @@ public async Task FunctionHandler(DownloadRequest request, ILambdaContext contex try { - context.Logger.LogInformation($"Starting download and zip operation: {JsonSerializer.Serialize(request)}"); + Logger.LogInformation($"Starting download and zip operation: ", request); var labelsList = request.labels.ToList(); var imageKeys = await _labelService.GetAllImagesForLabels(labelsList); var zipArchiveUrl = @@ -78,13 +79,11 @@ await _storageService.GenerateZipFromImages(imageKeys, storageBucketName!, workingBucketName!); await _notificationService.SendNotification(topicArn!, "Image download", $"Your images are available here: {zipArchiveUrl}"); - LambdaLogger.Log($"url: {zipArchiveUrl}"); + Logger.LogInformation($"url: {zipArchiveUrl}"); } catch (Exception e) { - context.Logger.LogInformation($"Error starting download."); - context.Logger.LogInformation(e.Message); - context.Logger.LogInformation(e.StackTrace); + Logger.LogError($"Error starting download.", e); throw; } } diff --git a/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/Functions.cs b/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/Functions.cs index cee628cb4de..d7163cc7e61 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/Functions.cs +++ b/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/Functions.cs @@ -4,6 +4,7 @@ using Amazon.Lambda.Annotations.APIGateway; using Amazon.Lambda.APIGatewayEvents; using Amazon.Lambda.Core; +using AWS.Lambda.Powertools.Logging; using PamServices; [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))] @@ -36,7 +37,7 @@ public Functions(StorageService storageService, LabelService labelService) [HttpApi(LambdaHttpMethod.Get, "/labels")] public async Task GetLabels(ILambdaContext context) { - context.Logger.Log($"Test logging: getting labels."); + Logger.LogInformation($"Getting labels."); var allLabels = await _labelService.GetAllItems(); var labelsResponse = new LabelsResponse(allLabels.ToList()); diff --git a/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/PamApiAnnotations.csproj b/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/PamApiAnnotations.csproj index ecd874a15c4..b1397cf4b1c 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/PamApiAnnotations.csproj +++ b/dotnetv3/cross-service/PhotoAssetManager/PamApiAnnotations/PamApiAnnotations.csproj @@ -31,6 +31,7 @@ + diff --git a/dotnetv3/cross-service/PhotoAssetManager/README.md b/dotnetv3/cross-service/PhotoAssetManager/README.md index 6d1a4fef54d..fa209dba550 100644 --- a/dotnetv3/cross-service/PhotoAssetManager/README.md +++ b/dotnetv3/cross-service/PhotoAssetManager/README.md @@ -49,7 +49,7 @@ to use the AWS Cloud Development Kit (AWS CDK) or AWS Command Line Interface ## Build the code -The Visual Studio solution **PhotoAssetManager.sln** includes several projects with different purposes for this example. +The Visual Studio solution **PhotoAssetManager.sln** includes several projects with different purposes for this example. The Lambda functions included in the solution also use [Powertools for AWS Lambda (.NET)](https://github.com/aws-powertools/powertools-lambda-dotnet) for enhanced logging. - **PamApi** - A Lambda Serverless API project that includes an ApiController for the serverless endpoints, a Swagger UI for development environments, and separate Download and DetectLabels functions. - This is the project that will be packaged and deployed when using the `dotnet` language option when setting up the CDK stack.