Creating an AWS Lambda function that uses S3 and Simple Email Service?

Hi all,

I’m really struggling with learning AWS Lambda yet I’m a reasonable .NET developer…

I can work with, upload and execute the following ‘template’ lambda function provided in Visual Studio, which responds to an S3 event. I am able to connect this Lambda function to my S3 bucket when an item is ‘PUT’ into the bucket, and it works and logs the event to CloudWatch. I’m struggling however to ‘go beyond’ this simple test.

For instance, I would like to trigger an email to be sent to me when the item is PUT into the bucket, using Amazon Simple Email Service. However, I can’t seem to get that to work. I can install the right library (e.g. AWSSDK.SimpleEmail) but can’t add it to ‘usings’ and none of my SES objects (e.g. AmazonSimpleEmailServiceClient) will resolve properly in code, so I’m not able to instantiate anything. What am I missing? What don’t I understand? If I add the SQS library however, I seem to be able to instantiate the SQS client fine (though I’ve not tried to actually use it within my function).

  public async Task<string> FunctionHandler(S3Event evnt, ILambdaContext context)
            var s3Event = evnt.Records?[0].S3;
            if(s3Event == null)
                return null;
                context.Logger.LogLine("Testing a log raised to CloudWatch for bucket: " + s3Event.Bucket.Name + " @ " + DateTime.Now.ToString());
I added the bits below, but they don't even resolve properly....Yet they work fine in my standard Simple Email Service library that I've created elsewhere.
              Amazon.SimpleEmail.AmazonSimpleEmailServiceConfig amConfig = new AmazonSimpleEmailServiceConfig();
                amConfig.RegionEndpoint = RegionEndpoint.USWest2;
                AmazonSimpleEmailServiceClient amzClient = new AmazonSimpleEmailServiceClient(Environment.GetEnvironmentVariable("AccessKey"),
                    Environment.GetEnvironmentVariable("SecretKey"), amConfig); 
                var response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key);
                return response.Headers.ContentType;
            catch(Exception e)
                context.Logger.LogLine($"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.");

I seem to suffer the same confusion/problem if I want to use some other library methods in my Lambda function - e.g. .NET SQL libraries for connecting to a SQL server and say - inserting a record - when the lambda event is triggered. It’s the same issue, I can’t seem to add the right libraries that I’d normally add to my project to allow me to work with these objects.

1 Like