I recently tackled a project where I wanted to identify faces, text, and objects in images using Amazon Rekognition, all from a .NET Lambda function in AWS. It was my first time doing anything like this in C#, and I definitely hit a few snags along the way. But by the end, I had a working serverless image analysis app that reads an image from S3 and returns everything from facial attributes to detected text and object labels. Here’s how I did it, step by step, plus some notes on what I learned the hard way.
Uploaded my Image to S3
First, I created an S3 bucket where my images would live. I logged into the AWS console and searched for S3. I clicked on it and then create bucket. I named it something like image-rek-pics and created it in my default region. Then I uploaded a sample image (detectionPhote.jpg) by selecting the bucket, clicked upload, and added the file. Simple enough thus far.
Created the Lambda Function
Next, I headed over to the Lambda Console to create my image analysis function. I searched for Lambda in the top left search bar to find it and go to it. I clicked create function, gave it the name ImageRekognition, and then chose the .NET runtime. I started with the .NET 6 runtime, but it wouldn’t allow me to work in Lambda. I then tried .NET 8 thinking perhaps this might fix the issue, but got the same result. I learned that Lambda console doesn’t allow direct inline editing for C# projects. That is when I realized that I needed to set up my project locally using the AWS toolkit for Visual Studio Code.
Setting Up My .NET Lambda Project Locally
Here’s how I got it working locally:
- Installed the AWS SAM CLI
- Installed Docker for local testing
- Opened a terminal and ran:
dotnet new -i Amazon.Lambda.Templates
dotnet new lambda.EmptyFunction -n ImageRekognition
- Wrote my Lambda logic in the
Function.csfile (more on that below) - Right-clicked the project in VS Code and selected Upload to AWS Lambda
- Chose my region and selected the ImageRekognition Lambda I created earlier
Updated Lambda Permissions
Before running the function, I needed to ensure it had the appropriate permissions. In the Lambda Console, I went to Configuration, then Permissions, and then clicked on the IAM role to open it in the IAM Console. There, I attached the AmazonS3ReadOnlyAccess and AmazonRekognitionReadOnlyAccess policies. This granted the function access to retrieve images from S3 and analyze them using Rekognition.
Wrote the Lambda Code
In Function.cs, I wrote a function that does three things using Amazon Rekognition:
- Detects faces and logs attributes like bounding boxes, age range, and facial landmarks
- Detects text within the image
- Detects objects and labels
Here’s a trimmed-down version of the final function (full version in the repo):
public async Task<string> FunctionHandler(InputData input, ILambdaContext context)
{
var rekognitionClient = new AmazonRekognitionClient();
var photo = input.Photo ?? "detectionPhoto.jpg";
var bucket = input.Bucket ?? "image-rek-pics";
// Face detection
var facesResponse = await rekognitionClient.DetectFacesAsync(new DetectFacesRequest
{
Image = new Image { S3Object = new S3Object { Name = photo, Bucket = bucket } },
Attributes = new List<string> { "ALL" }
});
// Text detection
var textResponse = await rekognitionClient.DetectTextAsync(new DetectTextRequest
{
Image = new Image { S3Object = new S3Object { Name = photo, Bucket = bucket } }
});
// Label (object) detection
var labelsResponse = await rekognitionClient.DetectLabelsAsync(new DetectLabelsRequest
{
Image = new Image { S3Object = new S3Object { Name = photo, Bucket = bucket } },
MaxLabels = 10,
MinConfidence = 75F
});
// Log results...
return "Processing complete";
}
Some Problems that I Ran Into
This was my first time using C# with AWS Lambda, so I learned a few things the hard way. I ran into runtime errors when trying to use .NET 6 and .NET 8 in the console editor only to realize that it was not the version that was causing the issue, it was that the editor doesn’t support C# inline at all. I learned that you cannot edit C# Lambda code directly in the AWS console, so you have to build and deploy it usings the AWS toolkit or CLI. I ran into some issues and realized that my IAM permissions weren’t configured for my region, so I had to create an AccessAnalyser to debug access issues which was key to resolving S3 access problems.
The Final Result
Once everything was deployed and the permissions were properly configured, I tested the Lambda function directly from the AWS Console. The results included a detailed breakdown of the image: estimated age range with confidence scores, facial expressions, any detected text such as signs or labels, and recognized objects like furniture, animals, or scenery. It was fast, accurate, and honestly pretty fun to watch in action.
This project taught me a lot about AWS Lambda, C# in the cloud, and working with Amazon Rekognition. Despite a few hiccups, I came out the other side with a solid understanding of how to build and deploy a .NET-based Lambda function that can analyze images using multiple Rekognition features. I have to say that I find using Python much easier since you can write code directly in your Lambda function. Of course, it is good to know how to use C# for those projects that may require them. Here is my advice, if you’re new to Rekognition or Lambda in C#, don’t be intimidated. Just take it one step at a time and lean on tools like the AWS Toolkit and SAM CLI to make life easier.

