The serverless sample out of the box from Amazon doesn't come with simple "press F5" way to run the code locally.
The easiest way to test your code locally is to create the sample with Unit Tests. These unit tests include everything you need to initialise Functions
class so that you can run it. You could move this code into a simple console app or create unit tests that cover all the scenarios you want to test locally.
Here is the sample Unit Test from the project:
public class FunctionTest : IDisposable
{
string TableName { get; }
IAmazonDynamoDB DDBClient { get; }
public FunctionTest()
{
this.TableName = "AWSServerless2-Blogs-" + DateTime.Now.Ticks;
this.DDBClient = new AmazonDynamoDBClient(RegionEndpoint.USWest2);
SetupTableAsync().Wait();
}
[Fact]
public async Task BlogTestAsync()
{
TestLambdaContext context;
APIGatewayProxyRequest request;
APIGatewayProxyResponse response;
Functions functions = new Functions(this.DDBClient, this.TableName);
// Add a new blog post
Blog myBlog = new Blog();
myBlog.Name = "The awesome post";
myBlog.Content = "Content for the awesome blog";
request = new APIGatewayProxyRequest
{
Body = JsonConvert.SerializeObject(myBlog)
};
context = new TestLambdaContext();
response = await functions.AddBlogAsync(request, context);
Assert.Equal(200, response.StatusCode);