# AWS Lambda Function Using Top Level Statements This starter project consists of: * Function.cs - file contain C# top level statements that define the function to be called for each event and starts the Lambda runtime client. * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS You may also have a test project depending on the options selected. The generated function handler is a simple method accepting a string argument that returns the uppercase equivalent of the input string. Replace the body of this method, and parameters, to suit your needs. ## Executable Assembly .NET Lambda projects that use C# top level statements like this project must be deployed as an executable assembly instead of a class library. To indicate to Lambda that the .NET function is an executable assembly the Lambda function handler value is set to the .NET Assembly name. This is different then deploying as a class library where the function handler string includes the assembly, type and method name. To deploy as an executable assembly the Lambda runtime client must be started to listen for incoming events to process. To start the Lambda runtime client add the `Amazon.Lambda.RuntimeSupport` NuGet package and add the following code at the end of the of the file containing top-level statements to start the runtime. ```csharp await LambdaBootstrapBuilder.Create(handler, new DefaultLambdaJsonSerializer()) .Build() .RunAsync(); ``` Pass into the Lambda runtime client a function handler as either an `Action<>` or `Func<>` for the code that should be called for each event. If the handler takes in an input event besides `System.IO.Stream` then the JSON serializer must also be passed into the `Create` method. ## Here are some steps to follow from Visual Studio: To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. To view your deployed function open its Function View window by double-clicking the function name shown beneath the AWS Lambda node in the AWS Explorer tree. To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. To configure event sources for your deployed function, for example to have your function invoked when an object is created in an Amazon S3 bucket, use the Event Sources tab in the opened Function View window. To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. To view execution logs of invocations of your function use the Logs tab in the opened Function View window. ## Here are some steps to follow to get started from the command line: Once you have edited your template and code you can deploy your application using the [Amazon.Lambda.Tools Global Tool](https://github.com/aws/aws-extensions-for-dotnet-cli#aws-lambda-amazonlambdatools) from the command line. Install Amazon.Lambda.Tools Global Tools if not already installed. ``` dotnet tool install -g Amazon.Lambda.Tools ``` If already installed check if new version is available. ``` dotnet tool update -g Amazon.Lambda.Tools ``` Deploy function to AWS Lambda ``` cd "BlueprintBaseName.1/src/BlueprintBaseName.1" dotnet lambda deploy-function ```