Aws Lambda On Visual Studio For Mac

I'm working on an AWS Lambda function in Visual Studio that calls for fast image resizing. Originally, I was using ImageMagick to resize these images, but the entire process is is taking too long to process. The Widgets.Lambda project is published into AWS using CloudFormation and the AWS SDK inside Visual Studio. CloudFormation will create a stack definition based on the serverless.template file found inside the Widgets.Lambda project.

Active3 months ago

I've been reviewing Amazon's documentation for C# and Lambda. I've tried using their yeoman generator and Toolkit for Visual Studio. My goal is to simply have a project that holds multiple functions that I can debug on my local machine. The problem is that running the debugger gives me a message about not having an entry point into the project, which makes sense given it's created as a class library.

From what I'm seeing, it looks like the development process is to write your code, deploy and run the function on AWS. Debugging would be reviewing the output from that and going from there. Is there a way to actually use the built-in debugger for Visual Studio, though? Better yet, I'd like a workflow for local debugging on my Mac. For example, in NodeJS, I can use the Serverless framework and set my launch.json file in VS Code to the following:

This allows me to mock data and use breakpoints for debugging.

Jack MusickJack Musick

3 Answers

I haven't followed this guide, but it seems to talk about how to debug locally. It does go further into actually setting up on AWS if needed:

From the gist of it, it seems that you setup a Main entry point for your Lambda class that loads a test file from JSON. This is similar to how you would setup tests of your Lambda function on AWS.

jackofallcodejackofallcode
1,5301 gold badge9 silver badges10 bronze badges

This AWS lambda documentation begins the topic of testing by invoking the lambda via the AWS CLI. This article has links for using the AWS CLI in different OS and IDEs.

Example Invoke call:

JnJnBooJnJnBoo

With Visual Studio, you can install AWS's AWS .NET Mock Lambda Test Tool

Use the following command in the same directory as your Solution file:

Visual Studio automatically adds a Debug configuration so you can debug the project just like you would any other .NET app.

VS Code, Rider, and other instructions available in the Readme:https://github.com/aws/aws-lambda-dotnet/tree/master/Tools/LambdaTestTool

SMartDevSMartDev

Not the answer you're looking for? Browse other questions tagged c#amazon-web-servicesdebugginglambda.net-core or ask your own question.

A few years ago AWS announced a new SES feature: Incoming Emails. So far I have only used it once to receive domain verification emails to an S3 bucket but haven’t built a meaningful project. In this blog post my goal is to develop a sample project to demonstrate receiving emails with SES and processing those emails automatically by triggering Lambda functions.

As a demo project I will build a system that automatically responds to a sender with my latest CV as shown in the diagram below

Receiving Email with Amazon Simple Email Service

Amazon Simple Email Service (SES) is Amazon’s SMTP server. It’s core functionality has been sending emails but Amazon kept adding more features such as using templates and receiving emails.

Step 1: Verify a New Domain

First, we need a verified domain to receive emails. If you already have one you ca skip this step.

  • Step 1.1: In the SES console, click Domains –> Verify a New Domain
  • Step 1.2: Enter the domain name to verify and click Verify This Domain
  • Step 1.3: In the new dialog click Use Route 53

(This is assuming your domain is in Route53. If not you have to verify it by other means)

  • Step 1.4: Make sure you check Email Receiving Record checkbox and proceed
  • Step 1.5 Confirm verification status

Go back to Domains page in SES console and make sure the verification has been completed successfully

In my example, it only took about 2 minutes.

Step 2: Create a Lambda function to send the CV

In the next step we will continue to configure SES to specify what to do with the received email. But first we need the actual Lambda function to do the work. Then we will connect this to SES so that it runs everytime when we receive an email to a specific email.

  • Step 2.1: Create a Lambda function from scratch
  • Step 2.2: Create an SNS topic

SES will publish emails to this topic. We will do the plumbing and give necessary permissions later.

  • Step 2.3: Create subscription for the Lambda function to SNS topic

Now we tie the topic to our Lambda by creating a subscription

  • Step 2.4: Attach necessary permissions to the new role

In my example, I store my CV in an S3 bucket. So the policy would need to receive SNS notifications, read access to S3 bucket and permissions to send emails.

By default a new Lambda role comes with AWSLambdaBasicExecutionRole attached to it

First add this to have read-only access to a single bucket:

Then this to be able to send emails

I like to keep these small, modular policies so that I can reuse then in other projects.

After adding the policies you should be able to see these in your Lambda function’s access list when you refresh the function’s page:

Step 3: Develop the Lambda function

In this exmample I’m going to use a .NET Core and C# 2.0 to create the Lambda function.

  • Step 3.1: Install Lambda templates

In Windows, AWS Lambda function templates come with AWS Visual Studio extension but in Mac we have to install them via command line.

  • Step 3.2: Create Lambda function
Aws
  • Step 3.3:

Now it’s time for the actual implementation. I’m not going to paste the whole code here. Best place to get it is its GitHub repository

  • Step 3.4 Deploy the function

Create an IAM user with access to Lambda deployment and create a profile locally named deploy-lambda-profile.

Step 4: Create a Receipt Rule

Now that we have a verified domain, we need a rule to receive emails.

In my example project, I’m going to use an email address that will send my latest CV to a provided email adress.

  • Step 4.1: In the Email Receiving section click on Rule Sets –> Create a Receipt Rule

  • Step 4.2: Add a recipient

  • Step 4.3: Add an Action

Now we choose what to do when an email is received. In this example I want it to be published to an SNS topic that I created earlier. I could invoke the Lambda function directly but leveraging publish/subscribe gives me more flexibility as in I can change the subscriber in the future or add more stuff to do without affecting the rule configuration.

Since it supports multiple actions I could choose to invoke Lambda directly and add more actions here later on if need be but I’d like to use a standard approach which is all events are published to SNS and the interested parties subscribe to the topics.

I chose UTF-8 because I’m not expecting any data in the message body so it doesn’t matter too much in this example.

Aws Lambda Visual Studio 2017

  • Step 4.4 Give it a name and create the rule.

Step 4: Test end-to-end

Now that it’s all set up, it is time to test.

  • Step 4.1: Send a blank email to cv@vlkn.me (Or any other address if you’re setting up your own)
  • Step 4.2:

Aws Tools For Visual Studio

Then after a few seconds later, receive an email with the attachment:

The second email is optional. Basically, I creted an email subscriber too. So that whenever a blank email is received I get notified by SNS directly. This helps me to keep an eye on traffic if there is any.

Visual Studio For Mac Os

Resources