├── Libraries ├── test │ ├── TestFunction │ │ ├── aws-lambda-tools-defaults.json │ │ ├── Function.cs │ │ ├── project.json │ │ ├── ValidateHandlerFunctionSignatures.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── TestFunction.xproj │ ├── TestWebApp │ │ ├── appsettings.json │ │ ├── LambdaFunction.cs │ │ ├── Controllers │ │ │ ├── QueryStringController.cs │ │ │ └── ResourcePathController.cs │ │ ├── web.config │ │ ├── Program.cs │ │ ├── TestWebApp.xproj │ │ ├── project.json │ │ └── Startup.cs │ ├── Amazon.Lambda.Logging.AspNetCore.Tests │ │ ├── appsettings.json │ │ ├── project.json │ │ ├── TestLoggerFactory.cs │ │ └── Amazon.Lambda.Logging.AspNetCore.Tests.xproj │ ├── Amazon.Lambda.AspNetCoreServer.Test │ │ ├── project.json │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── values-get-all-apigatway-request.json │ │ ├── values-get-single-apigatway-request.json │ │ ├── values-get-querystring-apigatway-request.json │ │ ├── Amazon.Lambda.AspNetCoreServer.Test.xproj │ │ └── TestCallingWebAPI.cs │ ├── Amazon.Lambda.Tools.Test │ │ ├── project.json │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── LambdaToolsDefaultsReaderTest.cs │ │ ├── Amazon.Lambda.Tools.Test.xproj │ │ └── ValidateHandlerTests.cs │ ├── Amazon.Lambda.Core.Tests │ │ ├── project.json │ │ ├── CoreTests.cs │ │ └── Amazon.Lambda.Core.Tests.xproj │ └── EventsTests │ │ ├── project.json │ │ └── EventsTests.xproj ├── global.json └── src │ ├── Amazon.Lambda.S3Events │ ├── S3Event.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── project.json │ ├── Amazon.Lambda.S3Events.xproj │ └── README.md │ ├── Amazon.Lambda.Core │ ├── ICognitoIdentity.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── IClientContext.cs │ ├── project.json │ ├── ILambdaLogger.cs │ ├── IClientApplication.cs │ ├── LambdaLogger.cs │ ├── Amazon.Lambda.Core.xproj │ ├── ILambdaSerializer.cs │ └── LambdaSerializerAttribute.cs │ ├── Amazon.Lambda.Tools │ ├── Commands │ │ ├── ICommand.cs │ │ └── ListFunctionCommand.cs │ ├── IToolLogger.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Exceptions.cs │ ├── Constants.cs │ ├── Amazon.Lambda.Tools.xproj │ ├── Options │ │ ├── CommandOptionValue.cs │ │ ├── CommandOption.cs │ │ └── CommandOptions.cs │ └── project.json │ ├── Amazon.Lambda.SNSEvents │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── project.json │ ├── README.md │ └── Amazon.Lambda.SNSEvents.xproj │ ├── Amazon.Lambda.APIGatewayEvents │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── project.json │ ├── APIGatewayProxyResponse.cs │ ├── Amazon.Lambda.APIGatewayEvents.xproj │ └── README.md │ ├── Amazon.Lambda.ConfigEvents │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ ├── project.json │ └── Amazon.Lambda.ConfigEvents.xproj │ ├── Amazon.Lambda.CognitoEvents │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── project.json │ ├── README.md │ ├── Amazon.Lambda.CognitoEvents.xproj │ └── CognitoEvent.cs │ ├── Amazon.Lambda.DynamoDBEvents │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── project.json │ ├── DynamoDBEvent.cs │ ├── Amazon.Lambda.DynamoDBEvents.xproj │ └── README.md │ ├── Amazon.Lambda.KinesisEvents │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── project.json │ ├── Amazon.Lambda.KinesisEvents.xproj │ ├── README.md │ └── KinesisEvent.cs │ ├── Amazon.Lambda.Logging.AspNetCore │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── LambdaILoggerProvider.cs │ ├── project.json │ ├── Amazon.Lambda.Logging.AspNetCore.xproj │ ├── IConfigurationExtensions.cs │ ├── README.md │ └── LambdaILogger.cs │ ├── Amazon.Lambda.Serialization.Json │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ ├── project.json │ ├── Amazon.Lambda.Serialization.Json.xproj │ ├── KinesisEventRecordDataConverter.cs │ ├── JsonSerializer.cs │ └── AwsResolver.cs │ ├── Amazon.Lambda.TestUtilities │ ├── TestCognitoIdentity.cs │ ├── project.json │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── README.md │ ├── TestClientContext.cs │ ├── Amazon.Lambda.TestUtilities.xproj │ ├── TestClientApplication.cs │ ├── TestLambdaLogger.cs │ └── TestLambdaContext.cs │ └── Amazon.Lambda.AspNetCoreServer │ ├── Properties │ └── AssemblyInfo.cs │ ├── project.json │ ├── Amazon.Lambda.AspNetCoreServer.xproj │ ├── Internal │ └── ApiGatewayServer.cs │ ├── README.md │ └── WebHostBuilderExtensions.cs ├── Blueprints ├── YeomanGenerator │ └── generator-aws-lambda-dotnet │ │ ├── _global.json │ │ ├── package.json │ │ └── README.md ├── NuGet.Config ├── BlueprintDefinitions │ ├── SimpleS3Function │ │ ├── blueprint-manifest.json │ │ ├── test │ │ │ ├── project.json │ │ │ └── FunctionTest.cs │ │ └── src │ │ │ ├── project.json │ │ │ ├── aws-lambda-tools-defaults.json │ │ │ ├── Readme.md │ │ │ └── Function.cs │ ├── EmptyFunction │ │ ├── blueprint-manifest.json │ │ ├── test │ │ │ ├── project.json │ │ │ └── FunctionTest.cs │ │ └── src │ │ │ ├── project.json │ │ │ ├── aws-lambda-tools-defaults.json │ │ │ ├── Function.cs │ │ │ └── Readme.md │ ├── DynamoDBBlogAPI │ │ ├── blueprint-manifest.json │ │ ├── src │ │ │ ├── Blog.cs │ │ │ ├── aws-lambda-tools-defaults.json │ │ │ ├── project.json │ │ │ └── Readme.md │ │ └── test │ │ │ └── project.json │ ├── EmptyServerless │ │ ├── blueprint-manifest.json │ │ ├── test │ │ │ ├── project.json │ │ │ └── FunctionTest.cs │ │ └── src │ │ │ ├── project.json │ │ │ ├── aws-lambda-tools-defaults.json │ │ │ ├── serverless.template │ │ │ ├── Function.cs │ │ │ └── Readme.md │ ├── SimpleKinesisFunction │ │ ├── blueprint-manifest.json │ │ ├── test │ │ │ ├── project.json │ │ │ └── FunctionTest.cs │ │ └── src │ │ │ ├── project.json │ │ │ ├── aws-lambda-tools-defaults.json │ │ │ ├── Function.cs │ │ │ └── Readme.md │ └── SimpleDynamoDBFunction │ │ ├── blueprint-manifest.json │ │ ├── test │ │ ├── project.json │ │ └── FunctionTest.cs │ │ └── src │ │ ├── project.json │ │ ├── aws-lambda-tools-defaults.json │ │ ├── Function.cs │ │ └── Readme.md ├── BlueprintPackager │ ├── .vscode │ │ ├── tasks.json │ │ └── launch.json │ ├── project.json │ ├── BaseBlueprintPackager.cs │ ├── BlueprintManifest.cs │ ├── BlueprintPackager.xproj │ └── Program.cs └── README.md ├── .gitignore └── README.md /Libraries/test/TestFunction/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "region" : "us-east-2" 3 | } 4 | -------------------------------------------------------------------------------- /Libraries/global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ 3 | "src", 4 | "test" 5 | ], 6 | "sdk": { 7 | "version": "1.0.0-preview2-003131" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Blueprints/YeomanGenerator/generator-aws-lambda-dotnet/_global.json: -------------------------------------------------------------------------------- 1 | { 2 | "projects": [ "src", "test" ], 3 | "sdk": { 4 | "version": "1.0.0-preview2-003131" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Blueprints/NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Logging.AspNetCore.Tests/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Lambda.Logging": { 3 | "IncludeCategory": false, 4 | "IncludeLogLevel": false, 5 | "IncludeNewline": false, 6 | "LogLevel": { 7 | "Default": "Debug", 8 | "Microsoft": "Information" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleS3Function/blueprint-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "display-name":"Simple S3 Function", 3 | "system-name":"SimpleS3Function", 4 | "description": "A project for responding to S3 Event notifications", 5 | "sort-order" : 101, 6 | "hidden-tags" : ["C#","LambdaProject"], 7 | "tags":["S3"] 8 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyFunction/blueprint-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "display-name":"Empty Function", 3 | "system-name":"EmptyFunction", 4 | "description": "Setup the project and test project to create a Lambda function from scratch.", 5 | "sort-order" : 100, 6 | "hidden-tags" : ["C#","LambdaProject"], 7 | "tags":["Custom"] 8 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/DynamoDBBlogAPI/blueprint-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "display-name":"Blog API using DynamoDB", 3 | "system-name":"DynamoDBBlogAPI", 4 | "description": "An AWS Serverless application example Blogging API using Amazon DynamoDB.", 5 | "sort-order" : 201, 6 | "hidden-tags" : ["C#","ServerlessProject"], 7 | "tags":["DynamoDB"] 8 | } -------------------------------------------------------------------------------- /Libraries/test/TestFunction/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace TestFunction 7 | { 8 | public class Function 9 | { 10 | public string ToUpper(string input) 11 | { 12 | return input?.ToUpper(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyServerless/blueprint-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "display-name":"Empty Serverless Application", 3 | "system-name":"EmptyServerless", 4 | "description": "Setup the project and test project to create a Serverless application from scratch.", 5 | "sort-order" : 200, 6 | "hidden-tags" : ["C#","ServerlessProject"], 7 | "tags":["Custom"] 8 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleKinesisFunction/blueprint-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "display-name":"Simple Kinesis Function", 3 | "system-name":"SimpleKinesisFunction", 4 | "description": "A skeleton Lambda function to get started responding to Amazon Kinesis events", 5 | "sort-order" : 101, 6 | "hidden-tags" : ["C#","LambdaProject"], 7 | "tags":["Kinesis", "Simple"] 8 | } -------------------------------------------------------------------------------- /Libraries/test/TestFunction/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | "emitEntryPoint": false 5 | }, 6 | 7 | "dependencies": { 8 | "Microsoft.NETCore.App": { 9 | "type": "platform", 10 | "version": "1.0.1" 11 | } 12 | }, 13 | 14 | "frameworks": { 15 | "netcoreapp1.0": { 16 | "imports": "dnxcore50" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleDynamoDBFunction/blueprint-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "display-name":"Simple DynamoDB Function", 3 | "system-name":"SimpleDynamoDBFunction", 4 | "description": "A skeleton Lambda function to get started responding to Amazon DynamoDB stream events", 5 | "sort-order" : 101, 6 | "hidden-tags" : ["C#","LambdaProject"], 7 | "tags":["DynamoDB", "Simple"] 8 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.S3Events/S3Event.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.S3Events 2 | { 3 | using Amazon.S3.Util; 4 | 5 | /// 6 | /// AWS S3 event 7 | /// http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html 8 | /// http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-s3-put 9 | /// 10 | public class S3Event : S3EventNotification { } 11 | } 12 | -------------------------------------------------------------------------------- /Blueprints/BlueprintPackager/.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.1.0", 3 | "command": "dotnet", 4 | "isShellCommand": true, 5 | "args": [], 6 | "tasks": [ 7 | { 8 | "taskName": "build", 9 | "args": [ 10 | "${workspaceRoot}\\project.json" 11 | ], 12 | "isBuildCommand": true, 13 | "problemMatcher": "$msCompile" 14 | } 15 | ] 16 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/DynamoDBBlogAPI/src/Blog.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace BLUEPRINT_BASE_NAME 7 | { 8 | public class Blog 9 | { 10 | public string Id { get; set; } 11 | public string Name { get; set; } 12 | public string Content { get; set; } 13 | public DateTime CreatedTimestamp { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/LambdaFunction.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | using Amazon.Lambda.AspNetCoreServer; 4 | using Microsoft.AspNetCore.Hosting; 5 | 6 | namespace TestWebApp 7 | { 8 | public class LambdaFunction : APIGatewayProxyFunction 9 | { 10 | protected override void Init(IWebHostBuilder builder) 11 | { 12 | builder 13 | .UseApiGateway() 14 | .UseContentRoot(Directory.GetCurrentDirectory()) 15 | .UseStartup(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/ICognitoIdentity.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.Core 2 | { 3 | /// 4 | /// Information related to Amazon Congnito identities. 5 | /// 6 | public interface ICognitoIdentity 7 | { 8 | /// 9 | /// The Amazon Cognito identity ID. 10 | /// 11 | string IdentityId { get; } 12 | 13 | /// 14 | /// The Amazon Cognito identity pool ID. 15 | /// 16 | string IdentityPoolId { get; } 17 | } 18 | } -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/Controllers/QueryStringController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace TestWebApp.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class QueryStringController : Controller 11 | { 12 | 13 | [HttpGet] 14 | public string Get([FromQuery] string firstName, [FromQuery] string lastName) 15 | { 16 | return $"{firstName}, {lastName}"; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | "emitEntryPoint": false 5 | }, 6 | 7 | "dependencies": { 8 | "Microsoft.NETCore.App": { 9 | "type": "platform", 10 | "version": "1.0.1" 11 | }, 12 | 13 | "TestWebApp": { "target": "project" }, 14 | 15 | "xunit": "2.1.0-*", 16 | "dotnet-test-xunit": "2.2.0-*" 17 | }, 18 | "testRunner": "xunit", 19 | 20 | "frameworks": { 21 | "netcoreapp1.0": { 22 | "imports": "dnxcore50" 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Blueprints/BlueprintPackager/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | "debugType": "portable", 5 | "emitEntryPoint": true 6 | }, 7 | "dependencies": {}, 8 | "frameworks": { 9 | "netcoreapp1.0": { 10 | "dependencies": { 11 | "Microsoft.NETCore.App": { 12 | "type": "platform", 13 | "version": "1.0.1" 14 | }, 15 | "Newtonsoft.Json": "9.0.1", 16 | "System.IO.Compression": "4.1.0", 17 | "System.IO.Compression.ZipFile": "4.0.1" 18 | }, 19 | "imports": "dnxcore50" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Tools.Test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | "emitEntryPoint": false 5 | }, 6 | 7 | "dependencies": { 8 | "Microsoft.NETCore.App": { 9 | "type": "platform", 10 | "version": "1.0.1" 11 | }, 12 | 13 | "Amazon.Lambda.Tools": { "target": "project" }, 14 | "xunit": "2.1.0-*", 15 | "dotnet-test-xunit": "2.2.0-*", 16 | "TestFunction": { "target": "project" } 17 | }, 18 | "testRunner": "xunit", 19 | "frameworks": { 20 | "netcoreapp1.0": { 21 | "imports": "dnxcore50" 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Commands/ICommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Amazon.Lambda.Tools.Commands 7 | { 8 | /// 9 | /// Interface for commands to implement. 10 | /// 11 | public interface ICommand 12 | { 13 | /// 14 | /// If enabled the tool will prompt for required fields if they are not already given. 15 | /// 16 | bool EnableInteractive { get; set; } 17 | 18 | Task ExecuteAsync(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Core.Tests/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "frameworks": { 4 | "netcoreapp1.0": { 5 | "dependencies": { 6 | "Microsoft.NETCore.App": "1.0.0" 7 | } 8 | } 9 | }, 10 | "testRunner": "xunit", 11 | "dependencies": { 12 | "System.Runtime": "4.1.0", 13 | "Amazon.Lambda.Core": { "target": "project" }, 14 | "AWSSDK.Core": "3.3.0.2", 15 | "dotnet-test-xunit": "2.2.0-preview2-build1029", 16 | "xunit": "2.2.0-beta2-build3300" 17 | }, 18 | "runtimes": { 19 | "win7-x64": {}, 20 | "win7-x86": {} 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ###################################### 2 | # Visual Studio per-user settings data 3 | ###################################### 4 | *.suo 5 | *.user 6 | 7 | #################### 8 | # Build/Test folders 9 | #################### 10 | **/.vs/ 11 | **/bin/ 12 | **/obj/ 13 | **/TestResults/ 14 | **/Temp/ 15 | **/NuGet.exe 16 | **/buildlogs/ 17 | **/Deployment/ 18 | **/packages 19 | **/launchSettings.json 20 | 21 | **/project.lock.json 22 | 23 | 24 | **/node_modules/ 25 | **/TestGenerations/ 26 | /Blueprints/YeomanGenerator/generator-aws-lambda-dotnet/Blueprints/** 27 | /Blueprints/YeomanGenerator/generator-aws-lambda-dotnet/app/manifest.js 28 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyFunction/test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "Amazon.Lambda.Core": "1.0.0*", 13 | "Amazon.Lambda.TestUtilities": "1.0.0*", 14 | 15 | 16 | 17 | "BLUEPRINT_BASE_NAME": "1.0.0", 18 | 19 | "xunit": "2.1.0-*", 20 | "dotnet-test-xunit": "2.2.0-*" 21 | }, 22 | 23 | 24 | 25 | 26 | "testRunner": "xunit", 27 | 28 | "frameworks": { 29 | "netcoreapp1.0": { 30 | "imports": "dnxcore50" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyFunction/src/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "Amazon.Lambda.Core": "1.0.0*", 13 | "Amazon.Lambda.Serialization.Json": "1.0.0", 14 | 15 | "Amazon.Lambda.Tools" : { 16 | "type" :"build", 17 | "version":"1.0.0-preview1" 18 | } 19 | }, 20 | 21 | "tools": { 22 | "Amazon.Lambda.Tools" : "1.0.0-preview1" 23 | }, 24 | 25 | "frameworks": { 26 | "netcoreapp1.0": { 27 | "imports": "dnxcore50" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleKinesisFunction/test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "Amazon.Lambda.Core": "1.0.0*", 13 | "Amazon.Lambda.TestUtilities": "1.0.0*", 14 | "Amazon.Lambda.KinesisEvents": "1.0.0", 15 | 16 | "BLUEPRINT_BASE_NAME": "1.0.0", 17 | 18 | "xunit": "2.1.0-*", 19 | "dotnet-test-xunit": "2.2.0-*" 20 | }, 21 | 22 | "testRunner": "xunit", 23 | 24 | "frameworks": { 25 | "netcoreapp1.0": { 26 | "imports": "dnxcore50" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.Core")] 6 | [assembly: AssemblyDescription("Core interfaces for Lambda.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleS3Function/test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "AWSSDK.S3": "3.3.4", 13 | "Amazon.Lambda.Core": "1.0.0*", 14 | "Amazon.Lambda.TestUtilities": "1.0.0*", 15 | "Amazon.Lambda.S3Events": "1.0.0", 16 | 17 | "BLUEPRINT_BASE_NAME": "1.0.0", 18 | 19 | "xunit": "2.1.0-*", 20 | "dotnet-test-xunit": "2.2.0-*" 21 | }, 22 | 23 | "testRunner": "xunit", 24 | 25 | "frameworks": { 26 | "netcoreapp1.0": { 27 | "imports": "dnxcore50" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyServerless/test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "Amazon.Lambda.Core": "1.0.0*", 13 | "Amazon.Lambda.APIGatewayEvents": "1.0.0", 14 | "Amazon.Lambda.TestUtilities": "1.0.0*", 15 | 16 | 17 | 18 | "BLUEPRINT_BASE_NAME": "1.0.0", 19 | 20 | "xunit": "2.1.0-*", 21 | "dotnet-test-xunit": "2.2.0-*" 22 | }, 23 | 24 | 25 | 26 | 27 | "testRunner": "xunit", 28 | 29 | "frameworks": { 30 | "netcoreapp1.0": { 31 | "imports": "dnxcore50" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Builder; 8 | 9 | namespace TestWebApp 10 | { 11 | public class Program 12 | { 13 | public static void Main(string[] args) 14 | { 15 | var host = new WebHostBuilder() 16 | .UseKestrel() 17 | .UseContentRoot(Directory.GetCurrentDirectory()) 18 | .UseIISIntegration() 19 | .UseStartup() 20 | .Build(); 21 | 22 | host.Run(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.S3Events/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.S3Events")] 6 | [assembly: AssemblyDescription("Lambda event interfaces for S3 event source.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.SNSEvents/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.SNSEvents")] 6 | [assembly: AssemblyDescription("Lambda event interfaces for SNS event source.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleDynamoDBFunction/test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "Amazon.Lambda.Core": "1.0.0*", 13 | "Amazon.Lambda.TestUtilities": "1.0.0*", 14 | "Amazon.Lambda.DynamoDBEvents": "1.0.0", 15 | "AWSSDK.DynamoDBv2": "3.3.1", 16 | 17 | "BLUEPRINT_BASE_NAME": "1.0.0", 18 | 19 | "xunit": "2.1.0-*", 20 | "dotnet-test-xunit": "2.2.0-*" 21 | }, 22 | 23 | "testRunner": "xunit", 24 | 25 | "frameworks": { 26 | "netcoreapp1.0": { 27 | "imports": "dnxcore50" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.APIGatewayEvents/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.APIGatewayEvents")] 6 | [assembly: AssemblyDescription("Lambda event interfaces for API Gateway event source.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.ConfigEvents/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.ConfigEvents")] 6 | [assembly: AssemblyDescription("Lambda event interfaces for Config event source.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/Controllers/ResourcePathController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | 7 | namespace TestWebApp.Controllers 8 | { 9 | [Route("api/[controller]")] 10 | public class ResourcePathController : Controller 11 | { 12 | // GET api/values 13 | [HttpGet] 14 | public IEnumerable Get() 15 | { 16 | return new string[] { "value1", "value2" }; 17 | } 18 | 19 | // GET api/values/5 20 | [HttpGet("{id}")] 21 | public string Get(int id) 22 | { 23 | return "value=" + id; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/DynamoDBBlogAPI/test/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.1" 10 | }, 11 | "Amazon.Lambda.Core": "1.0.0*", 12 | "Amazon.Lambda.TestUtilities": "1.0.0*", 13 | 14 | "BLUEPRINT_BASE_NAME": "1.0.0", 15 | 16 | "xunit": "2.1.0-*", 17 | "dotnet-test-xunit": "2.2.0-*" 18 | }, 19 | 20 | "publishOptions": { 21 | "include": [ 22 | "appsettings.json" 23 | ] 24 | }, 25 | 26 | "testRunner": "xunit", 27 | 28 | "frameworks": { 29 | "netcoreapp1.0": { 30 | "imports": "dnxcore50" 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleKinesisFunction/src/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "Amazon.Lambda.Core": "1.0.0*", 13 | "Amazon.Lambda.Serialization.Json": "1.0.0", 14 | "Amazon.Lambda.KinesisEvents": "1.0.0", 15 | 16 | "Amazon.Lambda.Tools" : { 17 | "type" :"build", 18 | "version":"1.0.0-preview1" 19 | } 20 | }, 21 | 22 | "tools": { 23 | "Amazon.Lambda.Tools" : "1.0.0-preview1" 24 | }, 25 | 26 | 27 | "frameworks": { 28 | "netcoreapp1.0": { 29 | "imports": "dnxcore50" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.CognitoEvents/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.CognitoEvents")] 6 | [assembly: AssemblyDescription("Lambda event interfaces for Cognito event source.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.DynamoDBEvents/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.DynamoDBEvents")] 6 | [assembly: AssemblyDescription("Lambda event interfaces for DynamoDB event source.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.KinesisEvents/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.KinesisEvents")] 6 | [assembly: AssemblyDescription("Lambda event interfaces for Kinesis event source.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Logging.AspNetCore/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.Logging.AspNetCore")] 6 | [assembly: AssemblyDescription("ASP.NET Core logging support for Lambda.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Serialization.Json/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("Amazon.Lambda.Serialization.Json")] 6 | [assembly: AssemblyDescription("Default serializer implementation for Lambda event sources.")] 7 | [assembly: AssemblyProduct("Amazon Web Services Lambda Interface for .NET")] 8 | [assembly: AssemblyCompany("Amazon.com, Inc")] 9 | [assembly: AssemblyCopyright("Copyright 2009-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.")] 10 | [assembly: ComVisible(false)] 11 | [assembly: System.CLSCompliant(true)] 12 | [assembly: AssemblyVersion("1.0")] 13 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyServerless/src/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | "emitEntryPoint": false 5 | }, 6 | 7 | "dependencies": { 8 | "Microsoft.NETCore.App": { 9 | "type": "platform", 10 | "version": "1.0.0" 11 | }, 12 | 13 | "Amazon.Lambda.Core": "1.0.0", 14 | "Amazon.Lambda.APIGatewayEvents": "1.0.0", 15 | "Amazon.Lambda.Serialization.Json": "1.0.0", 16 | 17 | "Amazon.Lambda.Tools": { 18 | "type": "build", 19 | "version": "1.0.0-preview1" 20 | } 21 | }, 22 | 23 | "tools": { 24 | "Amazon.Lambda.Tools" : "1.0.0-preview1" 25 | }, 26 | 27 | "frameworks": { 28 | "netcoreapp1.0": { 29 | "imports": "dnxcore50" 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleS3Function/src/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "Amazon.Lambda.Core": "1.0.0*", 13 | "Amazon.Lambda.Serialization.Json": "1.0.0", 14 | "Amazon.Lambda.S3Events": "1.0.0", 15 | 16 | "AWSSDK.S3": "3.3.4", 17 | 18 | "Amazon.Lambda.Tools" : { 19 | "type" :"build", 20 | "version":"1.0.0-preview1" 21 | } 22 | }, 23 | 24 | "tools": { 25 | "Amazon.Lambda.Tools" : "1.0.0-preview1" 26 | }, 27 | 28 | 29 | "frameworks": { 30 | "netcoreapp1.0": { 31 | "imports": "dnxcore50" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/DynamoDBBlogAPI/src/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information" : [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", 5 | 6 | "dotnet lambda help", 7 | 8 | "All the command line options for the Lambda command can be specified in this file." 9 | ], 10 | 11 | "profile": "", 12 | "region": "", 13 | "configuration": "Release", 14 | "framework": "netcoreapp1.0", 15 | "s3-prefix": "BLUEPRINT_BASE_NAME/", 16 | "template": "serverless.template", 17 | "template-parameters": "" 18 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyServerless/src/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information" : [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", 5 | 6 | "dotnet lambda help", 7 | 8 | "All the command line options for the Lambda command can be specified in this file." 9 | ], 10 | 11 | "profile": "", 12 | "region": "", 13 | "configuration": "Release", 14 | "framework": "netcoreapp1.0", 15 | "s3-prefix": "BLUEPRINT_BASE_NAME/", 16 | "template": "serverless.template", 17 | "template-parameters": "" 18 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintPackager/BaseBlueprintPackager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.IO; 5 | using System.IO.Compression; 6 | 7 | using System.Text; 8 | using System.Xml; 9 | 10 | using Newtonsoft.Json; 11 | 12 | namespace Packager 13 | { 14 | public abstract class BaseBlueprintPackager 15 | { 16 | protected string _blueprintRoot; 17 | 18 | public BaseBlueprintPackager(string blueprintRoot) 19 | { 20 | this._blueprintRoot = blueprintRoot; 21 | } 22 | 23 | protected IList SearchForblueprintManifests() 24 | { 25 | return Directory.GetFiles(_blueprintRoot, "blueprint-manifest.json", SearchOption.AllDirectories).ToList(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintPackager/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Blueprint Packager", 6 | "type": "coreclr", 7 | "request": "launch", 8 | "preLaunchTask": "build", 9 | "program": "${workspaceRoot}\\bin\\Debug\\netcoreapp1.0\\BlueprintPackager.dll", 10 | "args": [], 11 | "cwd": "${workspaceRoot}", 12 | "externalConsole": false, 13 | "stopAtEntry": false, 14 | "internalConsoleOptions": "openOnSessionStart" 15 | }, 16 | { 17 | "name": ".NET Core Attach", 18 | "type": "coreclr", 19 | "request": "attach", 20 | "processId": "${command.pickProcess}" 21 | } 22 | ] 23 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleDynamoDBFunction/src/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | }, 5 | 6 | "dependencies": { 7 | "Microsoft.NETCore.App": { 8 | "type": "platform", 9 | "version": "1.0.0" 10 | }, 11 | 12 | "Newtonsoft.Json": "9.0.1", 13 | 14 | "Amazon.Lambda.Core": "1.0.0*", 15 | "Amazon.Lambda.Serialization.Json": "1.0.0", 16 | "Amazon.Lambda.DynamoDBEvents": "1.0.0", 17 | "AWSSDK.DynamoDBv2": "3.3.1", 18 | 19 | "Amazon.Lambda.Tools" : { 20 | "type" :"build", 21 | "version":"1.0.0-preview1" 22 | } 23 | }, 24 | 25 | "tools": { 26 | "Amazon.Lambda.Tools" : "1.0.0-preview1" 27 | }, 28 | 29 | 30 | "frameworks": { 31 | "netcoreapp1.0": { 32 | "imports": "dnxcore50" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/TestCognitoIdentity.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | 8 | namespace Amazon.Lambda.TestUtilities 9 | { 10 | /// 11 | /// A test implementation of the ICognitoIdentity interface used for writing local tests of Lambda Functions. 12 | /// 13 | public class TestCognitoIdentity : ICognitoIdentity 14 | { 15 | /// 16 | /// The Amazon Cognito identity ID. 17 | /// 18 | public string IdentityId { get; set; } 19 | 20 | /// 21 | /// The Amazon Cognito identity pool ID. 22 | /// 23 | public string IdentityPoolId { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Blueprints/BlueprintPackager/BlueprintManifest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Newtonsoft.Json; 7 | 8 | namespace Packager 9 | { 10 | public class BlueprintManifest 11 | { 12 | [JsonProperty(PropertyName = "display-name")] 13 | public string DisplayName { get; set; } 14 | [JsonProperty(PropertyName = "system-name")] 15 | public string SystemName { get; set; } 16 | public string Description { get; set; } 17 | 18 | [JsonProperty(PropertyName = "sort-order")] 19 | public int SortOrder { get; set; } 20 | public List Tags { get; set; } 21 | 22 | [JsonProperty(PropertyName = "hidden-tags")] 23 | public List HiddenTags { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/DynamoDBBlogAPI/src/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "buildOptions": { 4 | "emitEntryPoint": false 5 | }, 6 | 7 | "dependencies": { 8 | "Microsoft.NETCore.App": { 9 | "type": "platform", 10 | "version": "1.0.1" 11 | }, 12 | 13 | "Newtonsoft.Json": "9.0.1", 14 | 15 | "Amazon.Lambda.Core": "1.0.0", 16 | "Amazon.Lambda.APIGatewayEvents": "1.0.0", 17 | "Amazon.Lambda.Serialization.Json": "1.0.0", 18 | 19 | "Amazon.Lambda.Tools": { 20 | "version": "1.0.0-preview1", 21 | "type": "build" 22 | }, 23 | 24 | "AWSSDK.DynamoDBv2": "3.3.1" 25 | }, 26 | 27 | "tools": { 28 | "Amazon.Lambda.Tools": "1.0.0-preview1" 29 | }, 30 | 31 | "frameworks": { 32 | "netcoreapp1.0": { 33 | "imports": "dnxcore50" 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyFunction/test/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Xunit; 7 | using Amazon.Lambda.Core; 8 | using Amazon.Lambda.TestUtilities; 9 | 10 | using BLUEPRINT_BASE_NAME; 11 | 12 | namespace BLUEPRINT_BASE_NAME.Tests 13 | { 14 | public class FunctionTest 15 | { 16 | [Fact] 17 | public void TestToUpperFunction() 18 | { 19 | 20 | // Invoke the lambda function and confirm the string was upper cased. 21 | var function = new Function(); 22 | var context = new TestLambdaContext(); 23 | var upperCase = function.FunctionHandler("hello world", context); 24 | 25 | Assert.Equal("HELLO WORLD", upperCase); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/IClientContext.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.Core 2 | { 3 | using System.Collections.Generic; 4 | 5 | /// 6 | /// Information about client configuration and execution environment. 7 | /// 8 | public interface IClientContext 9 | { 10 | /// 11 | /// Environment information provided by mobile SDK. 12 | /// 13 | IDictionary Environment { get; } 14 | 15 | /// 16 | /// The client information provided by the AWS Mobile SDK. 17 | /// 18 | IClientApplication Client { get; } 19 | 20 | /// 21 | /// Custom values set by the client application. 22 | /// 23 | IDictionary Custom { get; } 24 | } 25 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyFunction/src/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information" : [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", 5 | 6 | "dotnet lambda help", 7 | 8 | "All the command line options for the Lambda command can be specified in this file." 9 | ], 10 | 11 | "profile":"", 12 | "region" : "", 13 | "configuration" : "Release", 14 | "framework" : "netcoreapp1.0", 15 | "function-runtime":"dotnetcore1.0", 16 | "function-memory-size" : 256, 17 | "function-timeout" : 30, 18 | "function-handler" : "BLUEPRINT_BASE_NAME::BLUEPRINT_BASE_NAME.Function::FunctionHandler" 19 | } 20 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleS3Function/src/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information" : [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", 5 | 6 | "dotnet lambda help", 7 | 8 | "All the command line options for the Lambda command can be specified in this file." 9 | ], 10 | 11 | "profile":"", 12 | "region" : "", 13 | "configuration" : "Release", 14 | "framework" : "netcoreapp1.0", 15 | "function-runtime":"dotnetcore1.0", 16 | "function-memory-size" : 256, 17 | "function-timeout" : 30, 18 | "function-handler" : "BLUEPRINT_BASE_NAME::BLUEPRINT_BASE_NAME.Function::FunctionHandler" 19 | } 20 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.ConfigEvents/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.ConfigEvents 2 | 3 | This package contains classes that can be used as input types for Lambda functions that process AWS Config events. 4 | 5 | # Sample Function 6 | 7 | The following is a sample class and Lambda function that receives Amazon Cognito event record data as an input and writes the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) 8 | 9 | ``` 10 | public class Function 11 | { 12 | public void Handler(ConfigEvent configEvent) 13 | { 14 | Console.WriteLine($"AWS Config rule - {configEvent.ConfigRuleName}"); 15 | Console.WriteLine($"Invoking event JSON - {configEvent.InvokingEvent}"); 16 | Console.WriteLine($"Event version - {configEvent.Version}"); 17 | } 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleKinesisFunction/src/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information" : [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", 5 | 6 | "dotnet lambda help", 7 | 8 | "All the command line options for the Lambda command can be specified in this file." 9 | ], 10 | 11 | "profile":"", 12 | "region" : "", 13 | "configuration" : "Release", 14 | "framework" : "netcoreapp1.0", 15 | "function-runtime":"dotnetcore1.0", 16 | "function-memory-size" : 256, 17 | "function-timeout" : 30, 18 | "function-handler" : "BLUEPRINT_BASE_NAME::BLUEPRINT_BASE_NAME.Function::FunctionHandler" 19 | } 20 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleDynamoDBFunction/src/aws-lambda-tools-defaults.json: -------------------------------------------------------------------------------- 1 | { 2 | "Information" : [ 3 | "This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", 4 | "To learn more about the Lambda commands with the .NET Core CLI execute the following command at the command line in the project root directory.", 5 | 6 | "dotnet lambda help", 7 | 8 | "All the command line options for the Lambda command can be specified in this file." 9 | ], 10 | 11 | "profile":"", 12 | "region" : "", 13 | "configuration" : "Release", 14 | "framework" : "netcoreapp1.0", 15 | "function-runtime":"dotnetcore1.0", 16 | "function-memory-size" : 256, 17 | "function-timeout" : 30, 18 | "function-handler" : "BLUEPRINT_BASE_NAME::BLUEPRINT_BASE_NAME.Function::FunctionHandler" 19 | } 20 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Serialization.Json/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.Serialization.Json 2 | 3 | This package contains a custom `Amazon.Lambda.Core.ILambdaSerializer` implementation which uses Newtonsoft.Json 9.0.1 to serialize/deserialize .NET types in Lambda functions. 4 | 5 | This serializer can be present on the assembly or on the handler method. If you specify both, the method attribute takes priority. 6 | 7 | Here is an example of setting this attribute on the assembly. 8 | ``` 9 | [assembly: Amazon.Lambda.Core.LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 10 | ``` 11 | 12 | And this is how the method can be applied to the handler method. 13 | ``` 14 | [Amazon.Lambda.Core.LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 15 | public Response CustomSerializerMethod(Request input) 16 | { 17 | ... 18 | } 19 | ``` 20 | -------------------------------------------------------------------------------- /Libraries/test/TestFunction/ValidateHandlerFunctionSignatures.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace TestFunction 7 | { 8 | public class ValidateHandlerFunctionSignatures : BaseValidateHandlerFunctionSignatures 9 | { 10 | public string NoParameters() 11 | { 12 | return null; 13 | } 14 | 15 | public string OneStringParameters(string one) 16 | { 17 | return null; 18 | } 19 | 20 | public string TooManyParameters(string one, string two, string three) 21 | { 22 | return null; 23 | } 24 | } 25 | 26 | public class BaseValidateHandlerFunctionSignatures 27 | { 28 | public string InheritedMethod(string input) 29 | { 30 | return null; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/IToolLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Amazon.Lambda.Tools 7 | { 8 | /// 9 | /// The logger is used to write all status messages. When executing CLI commands they are written to the console. 10 | /// When the Visual Studio Toolkit calls the commands it passes its logger to redirect the output 11 | /// to the VS windows. 12 | /// 13 | public interface IToolLogger 14 | { 15 | void WriteLine(string message); 16 | } 17 | 18 | /// 19 | /// Default console implementation 20 | /// 21 | public class ConsoleToolLogger : IToolLogger 22 | { 23 | public void WriteLine(string message) 24 | { 25 | Console.WriteLine(message); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.ConfigEvents/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.ConfigEvents", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.ConfigEvents", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "packOptions": { 9 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 10 | "projectUrl": "https://aws.amazon.com/lambda/", 11 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 12 | "tags": [ "AWS", "Amazon", "Lambda" ] 13 | }, 14 | "description": "Amazon Lambda .NET Core support - ConfigEvents package.", 15 | "buildOptions": { 16 | "emitEntryPoint": false, 17 | "xmlDoc": true, 18 | "warningsAsErrors": true 19 | }, 20 | "dependencies": { 21 | "System.Runtime": "4.1.0" 22 | }, 23 | "frameworks": { 24 | "netstandard1.3": { 25 | "imports": "dnxcore50" 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.CognitoEvents/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.CognitoEvents", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.CognitoEvents", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "packOptions": { 9 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 10 | "projectUrl": "https://aws.amazon.com/lambda/", 11 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 12 | "tags": [ "AWS", "Amazon", "Lambda" ], 13 | }, 14 | "description": "Amazon Lambda .NET Core support - CognitoEvents package.", 15 | "buildOptions": { 16 | "emitEntryPoint": false, 17 | "xmlDoc": true, 18 | "warningsAsErrors": true 19 | }, 20 | "dependencies": { 21 | "System.Runtime": "4.1.0" 22 | }, 23 | 24 | "frameworks": { 25 | "netstandard1.3": { 26 | "imports": "dnxcore50" 27 | } 28 | }, 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Libraries/test/TestFunction/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("TestFunction")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("11a53c8d-a49b-4477-bfd9-e00c77d1291c")] 20 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.TestUtilities", 3 | "title": "Amazon.Lambda.TestUtilities", 4 | "description": "Amazon.Lambda.TestUtilties includes stub implementations of interfaces defined in Amazon.Lambda.Core and helper methods.", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "version": "1.0.0", 9 | 10 | "buildOptions": { 11 | "xmlDoc": true 12 | }, 13 | 14 | "dependencies": { 15 | "NETStandard.Library": "1.6.0", 16 | "Amazon.Lambda.Core": "[1.0.0, 1.1)" 17 | }, 18 | 19 | "frameworks": { 20 | "netstandard1.3": { 21 | "imports": "dnxcore50" 22 | } 23 | }, 24 | "packOptions": { 25 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 26 | "projectUrl": "https://aws.amazon.com/lambda/", 27 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 28 | "tags": [ "AWS", "Amazon", "Lambda" ] 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyServerless/src/serverless.template: -------------------------------------------------------------------------------- 1 | { 2 | "AWSTemplateFormatVersion" : "2010-09-09", 3 | "Transform" : "AWS::Serverless-2016-10-31", 4 | "Description" : "An AWS Serverless Application.", 5 | 6 | "Resources" : { 7 | 8 | "Get" : { 9 | "Type" : "AWS::Serverless::Function", 10 | "Properties": { 11 | "Handler": "BLUEPRINT_BASE_NAME::BLUEPRINT_BASE_NAME.Functions::Get", 12 | "Runtime": "dotnetcore1.0", 13 | "CodeUri": "", 14 | "MemorySize": 256, 15 | "Timeout": 30, 16 | "Role": null, 17 | "Policies": [ "AWSLambdaBasicExecutionRole" ], 18 | "Events": { 19 | "PutResource": { 20 | "Type": "Api", 21 | "Properties": { 22 | "Path": "/", 23 | "Method": "GET" 24 | } 25 | } 26 | } 27 | } 28 | } 29 | 30 | }, 31 | 32 | "Outputs" : { 33 | } 34 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.Core", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.Core", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "description": "Amazon Lambda .NET Core support - Core package.", 9 | "buildOptions": { 10 | "emitEntryPoint": false, 11 | "xmlDoc": true, 12 | "warningsAsErrors": true 13 | }, 14 | "dependencies": { 15 | "System.IO": "4.1.0", 16 | "System.Runtime": "4.1.0", 17 | "System.Console": "4.0.0" 18 | }, 19 | 20 | "frameworks": { 21 | "netstandard1.3": { 22 | "imports": "dnxcore50" 23 | } 24 | }, 25 | "packOptions": { 26 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 27 | "projectUrl": "https://aws.amazon.com/lambda/", 28 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 29 | "tags": [ "AWS", "Amazon", "Lambda" ] 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.SNSEvents/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.SNSEvents", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.SNSEvents", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "packOptions": { 9 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 10 | "projectUrl": "https://aws.amazon.com/lambda/", 11 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 12 | "tags": [ 13 | "AWS", 14 | "Amazon", 15 | "Lambda" 16 | ] 17 | }, 18 | "description": "Amazon Lambda .NET Core support - SNSEvents package.", 19 | "buildOptions": { 20 | "emitEntryPoint": false, 21 | "xmlDoc": true, 22 | "warningsAsErrors": true 23 | }, 24 | "dependencies": { 25 | "System.Runtime": "4.1.0" 26 | }, 27 | "frameworks": { 28 | "netstandard1.3": { 29 | "imports": "dnxcore50" 30 | } 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AWS.Lambda.Tools")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("95294eba-f227-4fe7-ad93-8beab8e1cc70")] 20 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Logging.AspNetCore/LambdaILoggerProvider.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using System; 3 | 4 | namespace Microsoft.Extensions.Logging 5 | { 6 | internal class LambdaILoggerProvider : ILoggerProvider 7 | { 8 | // Private fields 9 | private readonly LambdaLoggerOptions _options; 10 | 11 | // Constructor 12 | public LambdaILoggerProvider(LambdaLoggerOptions options) 13 | { 14 | if (options == null) 15 | { 16 | throw new ArgumentNullException(nameof(options)); 17 | } 18 | 19 | _options = options; 20 | } 21 | 22 | // Interface methods 23 | public ILogger CreateLogger(string categoryName) 24 | { 25 | return new LambdaILogger(categoryName, _options); 26 | } 27 | public void Dispose() 28 | { 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.SNSEvents/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.S3Events 2 | 3 | This package contains classes that can be used as input types for Lambda functions that process Amazon Simple Notification Service (Amazon SNS) events. 4 | 5 | # Sample Function 6 | 7 | Below is a sample class and Lambda function that illustrates how an SNSEvent can be used. The function logs a summary of the events it received, including the event source, the timestamp, and the message of each event. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) 8 | 9 | ``` 10 | public class Function 11 | { 12 | public string Handler(SNSEvent snsEvent) 13 | { 14 | foreach (var record in snsEvent.Records) 15 | { 16 | var snsRecord = record.Sns; 17 | Console.WriteLine($"[{record.EventSource} {snsRecord.Timestamp}] Message = {snsRecord.Message}"); 18 | } 19 | } 20 | } 21 | ``` -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Tools.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AWS.Lambda.Tools.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("06804ae7-14e9-494d-a1f7-258ea6432c09")] 20 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.APIGatewayEvents/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.APIGatewayEvents", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.APIGatewayEvents", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "packOptions": { 9 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 10 | "projectUrl": "https://aws.amazon.com/lambda/", 11 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 12 | "tags": [ "AWS", "Amazon", "Lambda" ] 13 | }, 14 | "description": "Amazon Lambda .NET Core support - API Gateway package.", 15 | "buildOptions": { 16 | "emitEntryPoint": false, 17 | "xmlDoc": true, 18 | "warningsAsErrors": true 19 | }, 20 | "dependencies": { 21 | "System.Runtime": "4.1.0", 22 | "System.Runtime.Serialization.Primitives": "4.1.1" 23 | }, 24 | 25 | "frameworks": { 26 | "netstandard1.3": { 27 | "imports": "dnxcore50" 28 | } 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyFunction/src/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | using Amazon.Lambda.Serialization; 8 | 9 | // Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. 10 | [assembly: LambdaSerializerAttribute(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 11 | 12 | namespace BLUEPRINT_BASE_NAME 13 | { 14 | public class Function 15 | { 16 | 17 | /// 18 | /// A simple function that takes a string and does a ToUpper 19 | /// 20 | /// 21 | /// 22 | /// 23 | public string FunctionHandler(string input, ILambdaContext context) 24 | { 25 | return input?.ToUpper(); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.AspNetCoreServer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AWS.Lambda.AspNetCoreServer")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("25813aac-f0b3-4591-aa99-67983394623b")] 20 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("Amazon.Lambda.TestUtilities")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("0083b713-6399-479d-aa06-58d3e87f167d")] 20 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.S3Events/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.S3Events", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.S3Events", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "packOptions": { 9 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 10 | "projectUrl": "https://aws.amazon.com/lambda/", 11 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 12 | "tags": [ 13 | "AWS", 14 | "Amazon", 15 | "Lambda" 16 | ] 17 | }, 18 | "description": "Amazon Lambda .NET Core support - S3Events package.", 19 | "buildOptions": { 20 | "emitEntryPoint": false, 21 | "xmlDoc": true, 22 | "warningsAsErrors": true 23 | }, 24 | "dependencies": { 25 | "System.Runtime": "4.1.0", 26 | "AWSSDK.S3": "[3.3.4, 3.4)" 27 | }, 28 | "frameworks": { 29 | "netstandard1.3": { 30 | "imports": "dnxcore50" 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("AWS.Lambda.AspNetCoreServer.Test")] 11 | [assembly: AssemblyTrademark("")] 12 | 13 | // Setting ComVisible to false makes the types in this assembly not visible 14 | // to COM components. If you need to access a type in this assembly from 15 | // COM, set the ComVisible attribute to true on that type. 16 | [assembly: ComVisible(false)] 17 | 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("5b48aea8-5702-45a8-9d89-ceb986e6dbc1")] 20 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/ILambdaLogger.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.Core 2 | { 3 | /// 4 | /// Lambda runtime logger. 5 | /// 6 | public interface ILambdaLogger 7 | { 8 | /// 9 | /// Logs a message to AWS CloudWatch Logs. 10 | /// 11 | /// Logging will not be done: 12 | /// If the role provided to the function does not have sufficient permissions. 13 | /// 14 | /// 15 | void Log(string message); 16 | 17 | /// 18 | /// Logs a message, followed by the current line terminator, to AWS CloudWatch Logs. 19 | /// 20 | /// Logging will not be done: 21 | /// If the role provided to the function does not have sufficient permissions. 22 | /// 23 | /// 24 | void LogLine(string message); 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Exceptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Amazon.Lambda.Tools 7 | { 8 | /// 9 | /// The deploy tool exception. This is used to throw back an error to the user but is considerd a known error 10 | /// so the stack trace will not be displayed. 11 | /// 12 | public class LambdaToolsException : Exception 13 | { 14 | public LambdaToolsException(string message) : base(message) { } 15 | } 16 | 17 | public class ValidateHandlerException : LambdaToolsException 18 | { 19 | public string ProjectLocation { get; } 20 | public string Handler { get; } 21 | public ValidateHandlerException(string projectLocation, string handler, string message) : base(message) 22 | { 23 | this.ProjectLocation = projectLocation; 24 | this.Handler = handler; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.CognitoEvents/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.CognitoEvents 2 | 3 | This package contains classes that can be used as input types for Lambda functions that process Amazon Cognito events. 4 | 5 | # Sample Function 6 | 7 | The following is a sample class and Lambda function that receives Amazon Cognito event record data as an input and writes the record data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) 8 | 9 | ``` 10 | public class Function 11 | { 12 | public void Handler(CognitoEvent cognitoEvent) 13 | { 14 | foreach(var datasetKVP in cognitoEvent.DatasetRecords) 15 | { 16 | var datasetName = datasetKVP.Key; 17 | var datasetRecord = datasetKVP.Value; 18 | 19 | Console.WriteLine($"[{cognitoEvent.EventType}-{datasetName}] {datasetRecord.OldValue} -> {datasetRecord.Op} -> {datasetRecord.NewValue}"); 20 | } 21 | } 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.KinesisEvents/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.KinesisEvents", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.KinesisEvents", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "packOptions": { 9 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 10 | "projectUrl": "https://aws.amazon.com/lambda/", 11 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 12 | "tags": [ 13 | "AWS", 14 | "Amazon", 15 | "Lambda" 16 | ] 17 | }, 18 | "description": "Amazon Lambda .NET Core support - KinesisEvents package.", 19 | "buildOptions": { 20 | "emitEntryPoint": false, 21 | "xmlDoc": true, 22 | "warningsAsErrors": true 23 | }, 24 | "dependencies": { 25 | "System.Runtime": "4.1.0", 26 | "AWSSDK.Kinesis": "[3.3.1, 3.4.0)" 27 | }, 28 | "frameworks": { 29 | "netstandard1.3": { 30 | "imports": "dnxcore50" 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.DynamoDBEvents/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.DynamoDBEvents", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.DynamoDBEvents", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "packOptions": { 9 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 10 | "projectUrl": "https://aws.amazon.com/lambda/", 11 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 12 | "tags": [ 13 | "AWS", 14 | "Amazon", 15 | "Lambda" 16 | ] 17 | }, 18 | "description": "Amazon Lambda .NET Core support - DynamoDBEvents package.", 19 | "buildOptions": { 20 | "emitEntryPoint": false, 21 | "xmlDoc": true, 22 | "warningsAsErrors": true 23 | }, 24 | "dependencies": { 25 | "AWSSDK.DynamoDBv2": "[3.3.1, 3.4)", 26 | "System.Runtime": "4.1.0" 27 | }, 28 | "frameworks": { 29 | "netstandard1.3": { 30 | "imports": "dnxcore50" 31 | } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/IClientApplication.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.Core 2 | { 3 | /// 4 | /// Information about the client application that invoked the Lambda function. 5 | /// 6 | public interface IClientApplication 7 | { 8 | /// 9 | /// The application's package name. 10 | /// 11 | string AppPackageName { get; } 12 | 13 | /// 14 | /// The application's title. 15 | /// 16 | string AppTitle { get; } 17 | 18 | /// 19 | /// The application's version code. 20 | /// 21 | string AppVersionCode { get; } 22 | 23 | /// 24 | /// The application's version. 25 | /// 26 | string AppVersionName { get; } 27 | 28 | /// 29 | /// The application's installation id. 30 | /// 31 | string InstallationId { get; } 32 | } 33 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.TestUtilities 2 | 3 | Package includes test implementation of the interfaces from Amazon.Lambda.Core and helper methods to help in locally testing. 4 | 5 | 6 | ## Example xUnit test case using Amazon.Lambda.TestUtilities 7 | 8 | The test case creates an instance of [TestLambdaContext](src/Amazon.Lambda.TestUtilities/TestLambdaContext.cs) for the function to use. 9 | By default all properties except for the Logger property are set to null. The default Logger will write to the console. Any properties that your function uses will need to be set 10 | on the TestLambdaContext. 11 | ``` 12 | [Fact] 13 | public void TestToUpperFunction() 14 | { 15 | 16 | // Invoke the lambda function and confirm the string was upper cased. 17 | var function = new Function(); 18 | var context = new TestLambdaContext() 19 | { 20 | FunctionName = "ToUpper" 21 | }; 22 | var upperCase = function.FunctionHandler("hello world", context); 23 | 24 | Assert.Equal("HELLO WORLD", upperCase); 25 | } 26 | ``` -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Serialization.Json/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.Serialization.Json", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.Serialization.Json", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "packOptions": { 9 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 10 | "projectUrl": "https://aws.amazon.com/lambda/", 11 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 12 | "tags": [ 13 | "AWS", 14 | "Amazon", 15 | "Lambda" 16 | ] 17 | }, 18 | "description": "Amazon Lambda .NET Core support - Serialization.Json package.", 19 | "buildOptions": { 20 | "emitEntryPoint": false, 21 | "xmlDoc": true, 22 | "warningsAsErrors": true 23 | }, 24 | "dependencies": { 25 | "System.Runtime": "4.1.0", 26 | "System.Reflection": "4.1.0", 27 | "Newtonsoft.Json": "9.0.1", 28 | "Amazon.Lambda.Core": "[1.0.0, 1.1)" 29 | }, 30 | "frameworks": { 31 | "netstandard1.3": { 32 | "imports": "dnxcore50" 33 | } 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyServerless/test/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Xunit; 7 | using Amazon.Lambda.Core; 8 | using Amazon.Lambda.TestUtilities; 9 | using Amazon.Lambda.APIGatewayEvents; 10 | 11 | using BLUEPRINT_BASE_NAME; 12 | 13 | namespace BLUEPRINT_BASE_NAME.Tests 14 | { 15 | public class FunctionTest 16 | { 17 | public FunctionTest() 18 | { 19 | } 20 | 21 | [Fact] 22 | public void TetGetMethod() 23 | { 24 | TestLambdaContext context; 25 | APIGatewayProxyRequest request; 26 | APIGatewayProxyResponse response; 27 | 28 | Functions functions = new Functions(); 29 | 30 | 31 | request = new APIGatewayProxyRequest(); 32 | context = new TestLambdaContext(); 33 | response = functions.Get(request, context); 34 | Assert.Equal(200, response.StatusCode); 35 | Assert.Equal("Hello AWS Serverless", response.Body); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Constants.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Amazon.Lambda.Tools 7 | { 8 | public static class Constants 9 | { 10 | public const string IAM_ARN_PREFIX = "arn:aws:iam::"; 11 | public const string AWS_MANAGED_POLICY_ARN_PREFIX = "arn:aws:iam::aws:policy"; 12 | 13 | public const string SERVERLESS_TAG_NAME = "AWSServerlessAppNETCore"; 14 | 15 | /// 16 | /// The assume role policy that gives Lambda permission to assume the role. This is used 17 | /// when the deploy tool creates a new role for a function. 18 | /// 19 | public static readonly string LAMBDA_ASSUME_ROLE_POLICY = 20 | @" 21 | { 22 | ""Version"": ""2012-10-17"", 23 | ""Statement"": [ 24 | { 25 | ""Sid"": """", 26 | ""Effect"": ""Allow"", 27 | ""Principal"": { 28 | ""Service"": ""lambda.amazonaws.com"" 29 | }, 30 | ""Action"": ""sts:AssumeRole"" 31 | } 32 | ] 33 | } 34 | ".Trim(); 35 | 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Libraries/test/EventsTests/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "frameworks": { 4 | "netcoreapp1.0": { 5 | "dependencies": { 6 | "Microsoft.NETCore.App": "1.0.0" 7 | } 8 | } 9 | }, 10 | "testRunner": "xunit", 11 | "dependencies": { 12 | "System.Runtime": "4.1.0", 13 | "Amazon.Lambda.Core": { "target": "project" }, 14 | "Amazon.Lambda.Serialization.Json": { "target": "project" }, 15 | "Amazon.Lambda.CognitoEvents": { "target": "project" }, 16 | "Amazon.Lambda.ConfigEvents": { "target": "project" }, 17 | "Amazon.Lambda.DynamoDBEvents": { "target": "project" }, 18 | "Amazon.Lambda.KinesisEvents": { "target": "project" }, 19 | "Amazon.Lambda.S3Events": { "target": "project" }, 20 | "Amazon.Lambda.SNSEvents": { "target": "project" }, 21 | "Amazon.Lambda.APIGatewayEvents": { "target": "project" }, 22 | "xunit": "2.2.0-beta2-build3300", 23 | "dotnet-test-xunit": "2.2.0-preview2-build1029", 24 | "AWSSDK.Core": "3.3.5" 25 | }, 26 | "runtimes": { 27 | "win7-x64": {}, 28 | "win7-x86": {} 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Blueprints/YeomanGenerator/generator-aws-lambda-dotnet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "generator-aws-lambda-dotnet", 3 | "version": "1.0.2", 4 | "description": "A collection of Yeoman generators for writing .NET Core AWS Lambda functions and AWS Serverless Applications", 5 | "main": "app/index.js", 6 | "homepage": "https://github.com/aws/aws-lambda-dotnet/tree/master/Blueprints", 7 | "repository": { 8 | "type": "git", 9 | "url": "https://github.com/aws/aws-lambda-dotnet.git" 10 | }, 11 | "contributors": [ 12 | "Norm Johanson " 13 | ], 14 | "bugs": { 15 | "url": "http://github.com/aws/aws-lambda-dotnet/issues", 16 | "mail": "" 17 | }, 18 | "engines": { 19 | "node": ">=0.10.0" 20 | }, 21 | "keywords": [ 22 | "yeoman-generator", 23 | "AWS", 24 | "Lambda", 25 | "Serverless", 26 | ".NET" 27 | ], 28 | "dependencies": { 29 | "chalk": "^1.1.3", 30 | "uuid": "^2.0.1", 31 | "vs_projectname": "^1.0.0", 32 | "yeoman-generator": "^0.19.2", 33 | "yosay": "^1.2.0" 34 | }, 35 | "author": "Amazon Web Services", 36 | "license": "Apache-2.0" 37 | } 38 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/TestClientContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | 8 | namespace Amazon.Lambda.TestUtilities 9 | { 10 | /// 11 | /// A test implementation of the IClientContext interface used for writing local tests of Lambda Functions. 12 | /// 13 | public class TestClientContext : IClientContext 14 | { 15 | /// 16 | /// The client information provided by the AWS Mobile SDK. 17 | /// 18 | public IClientApplication Client { get; set; } 19 | 20 | /// 21 | /// Custom values set by the client application. 22 | /// 23 | public IDictionary Custom { get; set; } = new Dictionary(); 24 | 25 | /// 26 | /// Environment information provided by mobile SDK. 27 | /// 28 | public IDictionary Environment { get; set; } = new Dictionary(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Logging.AspNetCore.Tests/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0.0-*", 3 | "frameworks": { 4 | "netcoreapp1.0": { 5 | "dependencies": { 6 | "Microsoft.NETCore.App": "1.0.0" 7 | } 8 | } 9 | }, 10 | "buildOptions": { 11 | "copyToOutput": { 12 | "includeFiles": [ 13 | "appsettings.json" 14 | ] 15 | } 16 | }, 17 | "testRunner": "xunit", 18 | "dependencies": { 19 | "System.Runtime": "4.1.0", 20 | "Microsoft.Extensions.Configuration": "1.0.0", 21 | "Microsoft.Extensions.Configuration.Abstractions": "1.0.0", 22 | "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", 23 | "Microsoft.Extensions.Logging.Abstractions": "1.0.0", 24 | "Microsoft.Extensions.Configuration.Json": "1.0.0", 25 | 26 | "Amazon.Lambda.Core": "1.0.0", 27 | "Amazon.Lambda.Logging.AspNetCore": { "target": "project" }, 28 | 29 | "xunit": "2.2.0-beta2-build3300", 30 | "dotnet-test-xunit": "2.2.0-preview2-build1029" 31 | }, 32 | "runtimes": { 33 | "win7-x64": {}, 34 | "win7-x86": {} 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.APIGatewayEvents/APIGatewayProxyResponse.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.APIGatewayEvents 2 | { 3 | using System.Collections.Generic; 4 | using System.Runtime.Serialization; 5 | 6 | /// 7 | /// The response object for Lambda functions handling request from from API Gateway proxy 8 | /// http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html 9 | /// 10 | [DataContract] 11 | public class APIGatewayProxyResponse 12 | { 13 | /// 14 | /// The HTTP status code for the request 15 | /// 16 | [DataMember(Name = "statusCode")] 17 | public int StatusCode { get; set; } 18 | 19 | /// 20 | /// The Http headers return in the response 21 | /// 22 | [DataMember(Name = "headers")] 23 | public IDictionary Headers { get; set; } 24 | 25 | /// 26 | /// The response body 27 | /// 28 | [DataMember(Name = "body")] 29 | public string Body { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/LambdaLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Amazon.Lambda.Core 4 | { 5 | /// 6 | /// Static class which sends a message to AWS CloudWatch Logs. 7 | /// When used outside of a Lambda environment, logs are written to 8 | /// Console.Out. 9 | /// 10 | public static class LambdaLogger 11 | { 12 | // Logging action, logs to Console by default 13 | private static Action _loggingAction = LogToConsole; 14 | 15 | // Logs message to console 16 | private static void LogToConsole(string message) 17 | { 18 | Console.WriteLine(message); 19 | } 20 | 21 | /// 22 | /// Logs a message to AWS CloudWatch Logs. 23 | /// 24 | /// Logging will not be done: 25 | /// If the role provided to the function does not have sufficient permissions. 26 | /// 27 | /// 28 | public static void Log(string message) 29 | { 30 | _loggingAction(message); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Logging.AspNetCore/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.Logging.AspNetCore", 3 | "version": "1.0.0-*", 4 | "title": "Amazon.Lambda.Logging.AspNetCore", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "description": "Amazon Lambda .NET Core support - Logging ASP.NET Core package.", 9 | "buildOptions": { 10 | "emitEntryPoint": false, 11 | "xmlDoc": true, 12 | "warningsAsErrors": true 13 | }, 14 | "dependencies": { 15 | "Microsoft.Extensions.Logging.Abstractions": "1.0.0", 16 | "Microsoft.Extensions.Configuration.Abstractions": "1.0.0", 17 | "System.IO": "4.1.0", 18 | "System.Runtime": "4.1.0", 19 | 20 | "Amazon.Lambda.Core": "[1.0.0, 1.1)" 21 | }, 22 | 23 | "frameworks": { 24 | "netstandard1.3": { 25 | "imports": "dnxcore50" 26 | } 27 | }, 28 | "packOptions": { 29 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 30 | "projectUrl": "https://aws.amazon.com/lambda/", 31 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 32 | "tags": [ "AWS", "Amazon", "Lambda", "Logging" ] 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/values-get-all-apigatway-request.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "/{proxy+}", 3 | "path": "/api/resourcepath", 4 | "httpMethod": "GET", 5 | "headers": null, 6 | "queryStringParameters": null, 7 | "pathParameters": { 8 | "proxy": "api/values" 9 | }, 10 | "stageVariables": null, 11 | "requestContext": { 12 | "accountId": "AAAAAAAAAAAA", 13 | "resourceId": "5agfss", 14 | "stage": "test-invoke-stage", 15 | "requestId": "test-invoke-request", 16 | "identity": { 17 | "cognitoIdentityPoolId": null, 18 | "accountId": "AAAAAAAAAAAA", 19 | "cognitoIdentityId": null, 20 | "caller": "BBBBBBBBBBBB", 21 | "apiKey": "test-invoke-api-key", 22 | "sourceIp": "test-invoke-source-ip", 23 | "cognitoAuthenticationType": null, 24 | "cognitoAuthenticationProvider": null, 25 | "userArn": "arn:aws:iam::AAAAAAAAAAAA:root", 26 | "userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_102)", 27 | "user": "AAAAAAAAAAAA" 28 | }, 29 | "resourcePath": "/{proxy+}", 30 | "httpMethod": "GET", 31 | "apiId": "t2yh6sjnmk" 32 | }, 33 | "body": null 34 | } -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Core.Tests/CoreTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Text; 5 | using Xunit; 6 | using System.Linq; 7 | 8 | using Amazon.Lambda; 9 | 10 | namespace Amazon.Lambda.Tests 11 | { 12 | public class CoreTest 13 | { 14 | [Fact] 15 | public void TestLambdaLogger() 16 | { 17 | // verify that LambdaLogger logs to Console 18 | 19 | var message = "This is a message that should appear in console! ?_?"; 20 | var oldWriter = Console.Out; 21 | try 22 | { 23 | using (var writer = new StringWriter()) 24 | { 25 | Console.SetOut(writer); 26 | 27 | Lambda.Core.LambdaLogger.Log(message); 28 | 29 | var consoleText = writer.ToString(); 30 | Assert.Contains(message, consoleText); 31 | } 32 | } 33 | finally 34 | { 35 | Console.SetOut(oldWriter); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/values-get-single-apigatway-request.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "/{proxy+}", 3 | "path": "/api/resourcepath/5", 4 | "httpMethod": "GET", 5 | "headers": null, 6 | "queryStringParameters": null, 7 | "pathParameters": { 8 | "proxy": "api/values" 9 | }, 10 | "stageVariables": null, 11 | "requestContext": { 12 | "accountId": "AAAAAAAAAAAA", 13 | "resourceId": "5agfss", 14 | "stage": "test-invoke-stage", 15 | "requestId": "test-invoke-request", 16 | "identity": { 17 | "cognitoIdentityPoolId": null, 18 | "accountId": "AAAAAAAAAAAA", 19 | "cognitoIdentityId": null, 20 | "caller": "BBBBBBBBBBBB", 21 | "apiKey": "test-invoke-api-key", 22 | "sourceIp": "test-invoke-source-ip", 23 | "cognitoAuthenticationType": null, 24 | "cognitoAuthenticationProvider": null, 25 | "userArn": "arn:aws:iam::AAAAAAAAAAAA:root", 26 | "userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_102)", 27 | "user": "AAAAAAAAAAAA" 28 | }, 29 | "resourcePath": "/{proxy+}", 30 | "httpMethod": "GET", 31 | "apiId": "t2yh6sjnmk" 32 | }, 33 | "body": null 34 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.DynamoDBEvents/DynamoDBEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.DynamoDBEvents 2 | { 3 | using Amazon.DynamoDBv2.Model; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | /// 8 | /// AWS DynamoDB event 9 | /// http://docs.aws.amazon.com/lambda/latest/dg/with-ddb.html 10 | /// http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-ddb-update 11 | /// 12 | public class DynamoDBEvent 13 | { 14 | /// 15 | /// List of DynamoDB event records. 16 | /// 17 | public IList Records { get; set; } 18 | 19 | /// 20 | /// DynamoDB stream record 21 | /// http://docs.aws.amazon.com/dynamodbstreams/latest/APIReference/API_StreamRecord.html 22 | /// 23 | public class DynamodbStreamRecord : Record 24 | { 25 | /// 26 | /// The event source arn of DynamoDB. 27 | /// 28 | public string EventSourceArn { get; set; } 29 | } 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Blueprints/BlueprintPackager/BlueprintPackager.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 44191608-f995-4c1b-8045-6b5e2f43174a 10 | BlueprintPackager 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/Amazon.Lambda.Core.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 51f5e824-cae2-4ef4-9131-13256bfd28b6 10 | Amazon.Lambda.Core 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.S3Events/Amazon.Lambda.S3Events.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | d4b8939e-9684-4237-861c-2288eb5dd4e8 10 | Amazon.Lambda.S3Events 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.SNSEvents/Amazon.Lambda.SNSEvents.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | d05bf033-da2c-463c-bb98-64d28e1a4a75 10 | Amazon.Lambda.SNSEvents 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.ConfigEvents/Amazon.Lambda.ConfigEvents.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 6bf4ec9f-fb9e-4898-81f7-b392bf83d2b0 10 | Amazon.Lambda.ConfigEvents 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.CognitoEvents/Amazon.Lambda.CognitoEvents.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 105b1bbb-4114-4d86-812e-effbb6e47ce5 10 | Amazon.Lambda.CognitoEvents 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.DynamoDBEvents/Amazon.Lambda.DynamoDBEvents.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | cb170908-f770-4554-a974-9653562f1042 10 | Amazon.Lambda.DynamoDBEvents 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.KinesisEvents/Amazon.Lambda.KinesisEvents.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 3ed92849-4103-4aef-b406-ff856c134c4b 10 | Amazon.Lambda.KinesisEvents 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.AspNetCoreServer/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.AspNetCoreServer", 3 | "title": "Amazon.Lambda.AspNetCoreServer", 4 | "description": "Amazon.Lambda.AspNetCoreServer makes it easy to run ASP.NET Core Web API applications as AWS Lambda functions.", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "version": "0.8.0-preview1", 9 | 10 | "buildOptions": { 11 | "xmlDoc": true 12 | }, 13 | 14 | "dependencies": { 15 | "NETStandard.Library": "1.6.0", 16 | "Microsoft.AspNetCore.Hosting": "1.0.0", 17 | "Newtonsoft.Json": "9.0.1", 18 | "System.Text.Encodings.Web": "4.0.0", 19 | 20 | "Amazon.Lambda.Core": "[1.0.0, 1.1)", 21 | "Amazon.Lambda.Serialization.Json": "[1.0.0, 1.1)", 22 | "Amazon.Lambda.APIGatewayEvents": "[1.0.0, 1.1)" 23 | }, 24 | 25 | "frameworks": { 26 | "netstandard1.3": { 27 | "imports": "dnxcore50" 28 | } 29 | }, 30 | "packOptions": { 31 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 32 | "projectUrl": "https://aws.amazon.com/lambda/", 33 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 34 | "tags": [ "AWS", "Amazon", "Lambda", "aspnetcore" ] 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/TestWebApp.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 101abe51-390d-41df-a70b-2bd3b08b2cc7 10 | TestWebApp 11 | .\obj 12 | .\bin\ 13 | v4.5.2 14 | 15 | 16 | 2.0 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/values-get-querystring-apigatway-request.json: -------------------------------------------------------------------------------- 1 | { 2 | "resource": "/{proxy+}", 3 | "path": "/api/querystring", 4 | "httpMethod": "GET", 5 | "headers": null, 6 | "queryStringParameters": { 7 | "firstName": "Lewis", 8 | "lastName": "Meriwether" 9 | }, 10 | "pathParameters": { 11 | "proxy": "api/values" 12 | }, 13 | "stageVariables": null, 14 | "requestContext": { 15 | "accountId": "AAAAAAAAAAAA", 16 | "resourceId": "5agfss", 17 | "stage": "test-invoke-stage", 18 | "requestId": "test-invoke-request", 19 | "identity": { 20 | "cognitoIdentityPoolId": null, 21 | "accountId": "AAAAAAAAAAAA", 22 | "cognitoIdentityId": null, 23 | "caller": "BBBBBBBBBBBB", 24 | "apiKey": "test-invoke-api-key", 25 | "sourceIp": "test-invoke-source-ip", 26 | "cognitoAuthenticationType": null, 27 | "cognitoAuthenticationProvider": null, 28 | "userArn": "arn:aws:iam::AAAAAAAAAAAA:root", 29 | "userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_102)", 30 | "user": "AAAAAAAAAAAA" 31 | }, 32 | "resourcePath": "/{proxy+}", 33 | "httpMethod": "GET", 34 | "apiId": "t2yh6sjnmk" 35 | }, 36 | "body": null 37 | } -------------------------------------------------------------------------------- /Libraries/test/TestFunction/TestFunction.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 11a53c8d-a49b-4477-bfd9-e00c77d1291c 11 | TestFunction 12 | .\obj 13 | .\bin\ 14 | v4.5.2 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Amazon.Lambda.Tools.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 95294eba-f227-4fe7-ad93-8beab8e1cc70 10 | Amazon.Lambda.Tools 11 | .\obj 12 | .\bin\ 13 | v4.5.2 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.DynamoDBEvents/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.DynamoDBEvents 2 | 3 | This package contains classes that can be used as input types for Lambda functions that process Amazon DynamoDB events. 4 | 5 | This package has a dependency on the [AWS SDK for .NET package DynamoDBv2](https://www.nuget.org/packages/AWSSDK.DynamoDBv2/) in order to use the `Amazon.DynamoDBv2.Model.Record` type. 6 | 7 | # Sample Function 8 | 9 | The following is a sample class and Lambda function that receives Amazon DynamoDB event record data as an input and writes some of the incoming event data to CloudWatch Logs. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) 10 | 11 | ``` 12 | public class Function 13 | { 14 | public void Handler(DynamoDBEvent ddbEvent) 15 | { 16 | foreach (var record in ddbEvent.Records) 17 | { 18 | var ddbRecord = record.Dynamodb; 19 | var keys = string.Join(", ", ddbRecord.Keys.Keys); 20 | Console.WriteLine($"{record.EventID} - Keys = [{keys}], Size = {ddbRecord.SizeBytes} bytes"); 21 | } 22 | Console.WriteLine($"Successfully processed {ddbEvent.Records.Count} records."); 23 | } 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Logging.AspNetCore/Amazon.Lambda.Logging.AspNetCore.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0.25420 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 201ac4eb-48d8-4e4a-a336-bb16dd630a19 10 | Amazon.Lambda.Logging.AspNetCore 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 16 | 2.0 17 | 18 | 19 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/Amazon.Lambda.TestUtilities.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 0083b713-6399-479d-aa06-58d3e87f167d 11 | Amazon.Lambda.TestUtilities 12 | .\obj 13 | .\bin\ 14 | v4.5.2 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Libraries/test/EventsTests/EventsTests.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | d96e1572-c079-413a-bfa0-235000700ddb 10 | Amazon.Lambda.Tests 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 2.0 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.APIGatewayEvents/Amazon.Lambda.APIGatewayEvents.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 480d89e0-4334-4903-82cd-1b8adf09d019 11 | Amazon.Lambda.APIGatewayEvents 12 | .\obj 13 | .\bin\ 14 | v4.5.2 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.AspNetCoreServer/Amazon.Lambda.AspNetCoreServer.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 10 | 25813aac-f0b3-4591-aa99-67983394623b 11 | Amazon.Lambda.AspNetCoreServer 12 | .\obj 13 | .\bin\ 14 | v4.5.2 15 | 16 | 17 | 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/TestClientApplication.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | 8 | namespace Amazon.Lambda.TestUtilities 9 | { 10 | /// 11 | /// A test implementation of the IClientApplication interface used for writing local tests of Lambda Functions. 12 | /// 13 | public class TestClientApplication : IClientApplication 14 | { 15 | /// 16 | /// The application's package name. 17 | /// 18 | public string AppPackageName { get; set; } 19 | 20 | /// 21 | /// The application's title. 22 | /// 23 | public string AppTitle { get; set; } 24 | 25 | /// 26 | /// The application's version code. 27 | /// 28 | public string AppVersionCode { get; set; } 29 | 30 | /// 31 | /// The application's version. 32 | /// 33 | public string AppVersionName { get; set; } 34 | 35 | /// 36 | /// The application's installation id. 37 | /// 38 | public string InstallationId { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Core.Tests/Amazon.Lambda.Core.Tests.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | c148726c-9555-4347-89b4-b9a514ebb02c 10 | Amazon.Lambda.Tests 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 2.0 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Tools.Test/LambdaToolsDefaultsReaderTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | using Xunit; 8 | 9 | using Amazon.Lambda; 10 | using Amazon.Lambda.Model; 11 | 12 | using Amazon.Lambda.Tools; 13 | using Amazon.Lambda.Tools.Commands; 14 | using Amazon.Lambda.Tools.Options; 15 | 16 | using ThirdParty.Json.LitJson; 17 | 18 | namespace Amazon.Lambda.Tools.Test 19 | { 20 | public class LambdaToolsDefaultsReaderTest 21 | { 22 | [Fact] 23 | public void LoadDefaultsDirectly() 24 | { 25 | var defaults = LambdaToolsDefaultsReader.LoadDefaults("../TestFunction"); 26 | 27 | Assert.Equal(defaults.Region, "us-east-2"); 28 | Assert.Equal(defaults["region"], "us-east-2"); 29 | } 30 | 31 | [Fact] 32 | public void CommandInferRegionFromDefaults() 33 | { 34 | var fullPath = Path.GetFullPath("../TestFunction"); 35 | var command = new DeployFunctionCommand(new ConsoleToolLogger(), fullPath, new string[0]); 36 | 37 | Assert.Equal("us-east-2", command.GetStringValueOrDefault(command.Region, DefinedCommandOptions.ARGUMENT_AWS_REGION, true)); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/TestLambdaLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | using Amazon.Lambda.Core; 8 | 9 | namespace Amazon.Lambda.TestUtilities 10 | { 11 | /// 12 | /// An implementation if ILambdaLogger that stores all the messages in a buffer and writes the messages to the console. 13 | /// 14 | public class TestLambdaLogger : ILambdaLogger 15 | { 16 | /// 17 | /// Buffer for all the log messages written to the logger. 18 | /// 19 | public StringBuilder Buffer { get; } = new StringBuilder(); 20 | 21 | /// 22 | /// Write log messages to the console. 23 | /// 24 | /// 25 | public void Log(string message) 26 | { 27 | LogLine(message); 28 | } 29 | 30 | /// 31 | /// Write log messages to the console. 32 | /// 33 | /// 34 | public void LogLine(string message) 35 | { 36 | Buffer.AppendLine(message); 37 | Console.WriteLine(message); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.AspNetCoreServer/Internal/ApiGatewayServer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Hosting.Server; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.AspNetCore.Http.Features; 9 | using Microsoft.AspNetCore.Hosting.Internal; 10 | 11 | namespace Amazon.Lambda.AspNetCoreServer.Internal 12 | { 13 | /// 14 | /// Implements the ASP.NET Core IServer interface and exposes the application object for the Lambda function 15 | /// to initiate a web request. 16 | /// 17 | internal class APIGatewayServer : IServer 18 | { 19 | /// 20 | /// The application is used by the Lambda function to initiate a web request through the ASP.NET Core framework. 21 | /// 22 | public IHttpApplication Application { get; set; } 23 | public IFeatureCollection Features { get; } = new FeatureCollection(); 24 | 25 | public void Dispose() 26 | { 27 | } 28 | 29 | public void Start(IHttpApplication application) 30 | { 31 | this.Application = application as IHttpApplication; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Logging.AspNetCore.Tests/TestLoggerFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace Amazon.Lambda.Logging.AspNetCore.Tests 8 | { 9 | public class TestLoggerFactory : ILoggerFactory 10 | { 11 | private ILoggerProvider _provider; 12 | 13 | public void AddProvider(ILoggerProvider provider) 14 | { 15 | if (provider == null) 16 | { 17 | throw new ArgumentNullException(nameof(provider)); 18 | } 19 | if (_provider != null) 20 | { 21 | throw new InvalidOperationException("Provider is already set, cannot add another."); 22 | } 23 | 24 | _provider = provider; 25 | } 26 | 27 | public ILogger CreateLogger(string categoryName) 28 | { 29 | return _provider.CreateLogger(categoryName); 30 | } 31 | 32 | public void Dispose() 33 | { 34 | var provider = _provider; 35 | _provider = null; 36 | if (provider != null) 37 | { 38 | provider.Dispose(); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Options/CommandOptionValue.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Amazon.Lambda.Tools.Options 7 | { 8 | /// 9 | /// Container class for the actual value of the CommandOption 10 | /// 11 | public class CommandOptionValue 12 | { 13 | /// 14 | /// This will be set if the CommandOption is of type string 15 | /// 16 | public string StringValue { get; set; } 17 | 18 | /// 19 | /// This will be set if the CommandOption is of type CommaDelimitedList 20 | /// 21 | public string[] StringValues { get; set; } 22 | 23 | /// 24 | /// This will be set if the CommandOption is of type KeyValuePairs 25 | /// 26 | public Dictionary KeyValuePairs { get;set; } 27 | 28 | /// 29 | /// This will be set if the CommandOption is of type bool 30 | /// 31 | public bool BoolValue { get; set; } 32 | 33 | /// 34 | /// This will be set if the CommandOption is of type int 35 | /// 36 | public int IntValue { get; set; } 37 | } 38 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintPackager/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | 4 | namespace Packager 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | var outputDirectory = Path.GetFullPath(@"../../Deployment/Blueprints"); 11 | var blueprintRoot = Path.GetFullPath(@"../BlueprintDefinitions"); 12 | try 13 | { 14 | Init(outputDirectory); 15 | 16 | var vsPackager = new VSBlueprintPackager(blueprintRoot, outputDirectory); 17 | vsPackager.Execute(); 18 | 19 | var yeomanPackager = new YeomanBlueprintPackager(blueprintRoot, outputDirectory); 20 | yeomanPackager.Execute(); 21 | } 22 | catch(Exception e) 23 | { 24 | Console.WriteLine($"Unknown error processing blueprints: {e.Message}"); 25 | Console.WriteLine(e.StackTrace); 26 | Environment.Exit(-1); 27 | } 28 | } 29 | 30 | private static void Init(string outputDirectory) 31 | { 32 | var di = new DirectoryInfo(outputDirectory); 33 | if (di.Exists) 34 | { 35 | di.Delete(true); 36 | } 37 | 38 | di.Create(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Tools.Test/Amazon.Lambda.Tools.Test.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 06804ae7-14e9-494d-a1f7-258ea6432c09 10 | Amazon.Lambda.Tools.Test 11 | .\obj 12 | .\bin\ 13 | v4.5.2 14 | 15 | 16 | 2.0 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Serialization.Json/Amazon.Lambda.Serialization.Json.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 13a0f4c9-69ec-4b8e-a00f-7bae23cc16e7 10 | Amazon.Lambda.Serialization.Json 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 2.0 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Logging.AspNetCore.Tests/Amazon.Lambda.Logging.AspNetCore.Tests.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0.25420 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | a612ec01-6595-4ea6-b0ef-ff00e4fb331d 10 | Amazon.Lambda.Logging.AspNetCore.Tests 11 | .\obj 12 | .\bin\ 13 | 14 | 15 | 2.0 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Amazon.Lambda.Tools", 3 | "title": "Amazon.Lambda.Tools", 4 | "description": "Amazon.Lambda.Tools adds commands to the dotnet cli to deploy AWS Lambda functions.", 5 | "authors": [ 6 | "Amazon Web Services" 7 | ], 8 | "version": "1.0.0-preview1", 9 | 10 | "buildOptions": { 11 | "outputName": "dotnet-lambda", 12 | "emitEntryPoint": true, 13 | "warningsAsErrors": true 14 | }, 15 | 16 | "dependencies": { 17 | "Microsoft.NETCore.App": { 18 | "type": "platform", 19 | "version": "1.0.0" 20 | }, 21 | 22 | "System.IO.Compression.ZipFile": "4.0.1", 23 | "System.Runtime.Loader": "4.0.0", 24 | 25 | "AWSSDK.CloudFormation": "[3.3.3, 3.4)", 26 | "AWSSDK.Lambda": "[3.3.1, 3.4)", 27 | "AWSSDK.IdentityManagement": "[3.3.0.3, 3.4)", 28 | "AWSSDK.S3": "[3.3.4, 3.4)" 29 | }, 30 | 31 | "frameworks": { 32 | "netcoreapp1.0": { 33 | "imports": "dnxcore50", 34 | "buildOptions": { 35 | "define": [ 36 | "NETCORE" 37 | ] 38 | } 39 | } 40 | }, 41 | "packOptions": { 42 | "licenseUrl": "http://aws.amazon.com/apache2.0/", 43 | "projectUrl": "https://aws.amazon.com/lambda/", 44 | "iconUrl": "http://media.amazonwebservices.com/aws_singlebox_01.png", 45 | "tags": [ "AWS", "Amazon", "Lambda" ] 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/Amazon.Lambda.AspNetCoreServer.Test.xproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14.0 5 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 6 | 7 | 8 | 9 | 5b48aea8-5702-45a8-9d89-ceb986e6dbc1 10 | Amazon.Lambda.AspNetCoreServer.Test 11 | .\obj 12 | .\bin\ 13 | v4.5.2 14 | 15 | 16 | 2.0 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/ILambdaSerializer.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.Core 2 | { 3 | using System.IO; 4 | 5 | /// 6 | /// Interface that must be implemented by custom serializers that 7 | /// may need to be called during execution. 8 | /// 9 | public interface ILambdaSerializer 10 | { 11 | /// 12 | /// This method is called to deserialize the request payload from Invoke API 13 | /// into the object that is passed to the Lambda function handler. 14 | /// 15 | /// Type of object to deserialize to. 16 | /// Stream to serialize. 17 | /// Deserialized object from stream. 18 | T Deserialize(Stream requestStream); 19 | 20 | /// 21 | /// This method is called to serialize the result returned from 22 | /// a Lambda function handler into the response payload 23 | /// that is returned by the Invoke API. 24 | /// 25 | /// Type of object to serialize. 26 | /// Object to serialize. 27 | /// Output stream. 28 | void Serialize(T response, Stream responseStream); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Core/LambdaSerializerAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.Core 2 | { 3 | using System; 4 | 5 | /// 6 | /// This attribute is required for serialization of input/output parameters of 7 | /// a Lambda function if your Lambda function uses types other than string or 8 | /// System.IO.Stream as input/output parameters. 9 | /// 10 | /// This attribute can be applied to a method (serializer used for method input 11 | /// and output), or to an assembly (serializer used for all methods). 12 | /// 13 | [AttributeUsage(AttributeTargets.Method | AttributeTargets.Assembly, AllowMultiple = false)] 14 | public sealed class LambdaSerializerAttribute : System.Attribute 15 | { 16 | /// 17 | /// Type of the serializer. 18 | /// The custom serializer must implement Amazon.Lambda.ILambdaSerializer 19 | /// interface, or an exception will be thrown. 20 | /// 21 | public Type SerializerType { get; set; } 22 | 23 | /// 24 | /// Constructs attribute with a specific serializer type. 25 | /// 26 | /// 27 | public LambdaSerializerAttribute(Type serializerType) 28 | { 29 | this.SerializerType = serializerType; 30 | } 31 | 32 | } 33 | } -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyServerless/src/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net; 5 | using System.Threading.Tasks; 6 | 7 | using Amazon.Lambda.Core; 8 | using Amazon.Lambda.APIGatewayEvents; 9 | 10 | // Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. 11 | [assembly: LambdaSerializerAttribute(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 12 | 13 | namespace BLUEPRINT_BASE_NAME 14 | { 15 | public class Functions 16 | { 17 | /// 18 | /// Default constructor that Lambda will invoke. 19 | /// 20 | public Functions() 21 | { 22 | } 23 | 24 | 25 | /// 26 | /// A Lambda function to respond to HTTP Get methods from API Gateway 27 | /// 28 | /// 29 | /// The list of blogs 30 | public APIGatewayProxyResponse Get(APIGatewayProxyRequest request, ILambdaContext context) 31 | { 32 | context.Logger.LogLine("Get Request\n"); 33 | 34 | var response = new APIGatewayProxyResponse 35 | { 36 | StatusCode = (int)HttpStatusCode.OK, 37 | Body = "Hello AWS Serverless", 38 | Headers = new Dictionary { { "Content-Type", "text/plain" } } 39 | }; 40 | 41 | return response; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleKinesisFunction/src/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | using Amazon.Lambda.Core; 6 | using Amazon.Lambda.KinesisEvents; 7 | 8 | // Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. 9 | [assembly: LambdaSerializerAttribute(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 10 | 11 | namespace BLUEPRINT_BASE_NAME 12 | { 13 | public class Function 14 | { 15 | 16 | public void FunctionHandler(KinesisEvent kinesisEvent, ILambdaContext context) 17 | { 18 | context.Logger.LogLine($"Beginning to process {kinesisEvent.Records.Count} records..."); 19 | 20 | foreach (var record in kinesisEvent.Records) 21 | { 22 | context.Logger.LogLine($"Event ID: {record.EventId}"); 23 | context.Logger.LogLine($"Event Name: {record.EventName}"); 24 | 25 | string recordData = GetRecordContents(record.Kinesis); 26 | context.Logger.LogLine($"Record Data:"); 27 | context.Logger.LogLine(recordData); 28 | } 29 | 30 | context.Logger.LogLine("Stream processing complete."); 31 | } 32 | 33 | private string GetRecordContents(KinesisEvent.Record streamRecord) 34 | { 35 | using (var reader = new StreamReader(streamRecord.Data, Encoding.ASCII)) 36 | { 37 | return reader.ReadToEnd(); 38 | } 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Options/CommandOption.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Amazon.Lambda.Tools.Options 7 | { 8 | /// 9 | /// The definitionn of an option for a command. 10 | /// 11 | public class CommandOption 12 | { 13 | /// 14 | /// An enum for the possible values for an option 15 | /// 16 | public enum CommandOptionValueType { NoValue, StringValue, BoolValue, IntValue, CommaDelimitedList, KeyValuePairs } 17 | 18 | /// 19 | /// The name of the option. 20 | /// 21 | public string Name { get; set; } 22 | 23 | /// 24 | /// The short form of the command line switch. This will start with just one dash e.g. -f for framework 25 | /// 26 | public string ShortSwitch { get; set; } 27 | 28 | /// 29 | /// The full form of the command line switch. This will start with two dashes e.g. --framework 30 | /// 31 | public string Switch { get; set; } 32 | 33 | /// 34 | /// The description of the option 35 | /// 36 | public string Description { get; set; } 37 | 38 | /// 39 | /// The type of value that is expected with this command option 40 | /// 41 | public CommandOptionValueType ValueType { get; set; } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Serialization.Json/KinesisEventRecordDataConverter.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.IO; 4 | using System.Reflection; 5 | using System.Text; 6 | using NewtonsoftJsonSerializer = Newtonsoft.Json.JsonSerializer; 7 | 8 | namespace Amazon.Lambda.Serialization.Json 9 | { 10 | /// 11 | /// Custom JSON converter for handling special event cases. 12 | /// 13 | internal class KinesisEventRecordDataConverter : JsonConverter 14 | { 15 | private static readonly TypeInfo MEMORYSTREAM_TYPEINFO = typeof(MemoryStream).GetTypeInfo(); 16 | 17 | public override bool CanRead { get { return true; } } 18 | public override bool CanWrite { get { return false; } } 19 | public override bool CanConvert(Type objectType) 20 | { 21 | return MEMORYSTREAM_TYPEINFO.IsAssignableFrom(objectType.GetTypeInfo()); 22 | } 23 | 24 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, NewtonsoftJsonSerializer serializer) 25 | { 26 | var dataBase64 = reader.Value as string; 27 | var dataBytes = Convert.FromBase64String(dataBase64); 28 | MemoryStream stream = new MemoryStream(dataBytes); 29 | return stream; 30 | } 31 | 32 | public override void WriteJson(JsonWriter writer, object value, NewtonsoftJsonSerializer serializer) 33 | { 34 | throw new NotSupportedException(); 35 | } 36 | } 37 | 38 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.APIGatewayEvents/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.APIGatewayEvents 2 | 3 | This package contains classes that can be used as input types for Lambda functions that process Amazon API Gateway events. 4 | 5 | API Gateway events consist of a request that was routed to a Lambda function by API Gateway. When this happens, API Gateway expects the result of the function to be the response that API Gateway should respond with. To see a more detailed example of this, take a look at the [Amazon.Lambda.AspNetCoreServer README.md file](Libraries/Amazon.Lambda.AspNetCoreServer/README.md). 6 | 7 | # Sample Function 8 | 9 | The following is a sample class and Lambda function that receives Amazon API Gateway event record data as an input, writes some of the record data to CloudWatch Logs, and responds with a 200 status and the same body as the request. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) 10 | 11 | ``` 12 | public class Function 13 | { 14 | public APIGatewayProxyResponse Handler(APIGatewayProxyRequest apigProxyEvent) 15 | { 16 | Console.WriteLine($"Processing request data for request {apigProxyEvent.RequestContext.RequestId}."); 17 | Console.WriteLine($"Body size = {apigProxyEvent.Body.Length}."); 18 | var headerNames = string.Join(", ", apigProxyEvent.Headers.Keys); 19 | Console.WriteLine($"Specified headers = {headerNames}."); 20 | 21 | return new APIGatewayProxyResponse 22 | { 23 | Body = apigProxyEvent.Body, 24 | StatusCode = 200, 25 | }; 26 | } 27 | } 28 | ``` 29 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleKinesisFunction/test/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | using Xunit; 9 | 10 | using Amazon; 11 | using Amazon.Lambda.Core; 12 | using Amazon.Lambda.KinesisEvents; 13 | using Amazon.Lambda.TestUtilities; 14 | 15 | using BLUEPRINT_BASE_NAME; 16 | 17 | namespace BLUEPRINT_BASE_NAME.Tests 18 | { 19 | public class FunctionTest 20 | { 21 | 22 | [Fact] 23 | public void TestFunction() 24 | { 25 | KinesisEvent evnt = new KinesisEvent 26 | { 27 | Records = new List 28 | { 29 | new KinesisEvent.KinesisEventRecord 30 | { 31 | AwsRegion = "us-west-2", 32 | Kinesis = new KinesisEvent.Record 33 | { 34 | ApproximateArrivalTimestamp = DateTime.Now, 35 | Data = new MemoryStream(Encoding.UTF8.GetBytes("Hello World Kinesis Record")) 36 | } 37 | } 38 | } 39 | }; 40 | 41 | 42 | var context = new TestLambdaContext(); 43 | var function = new Function(); 44 | 45 | function.FunctionHandler(evnt, context); 46 | 47 | var testLogger = context.Logger as TestLambdaLogger; 48 | Assert.True(testLogger.Buffer.ToString().Contains("Stream processing complete")); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleDynamoDBFunction/src/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Text; 4 | 5 | using Newtonsoft.Json; 6 | 7 | using Amazon.Lambda.Core; 8 | using Amazon.Lambda.DynamoDBEvents; 9 | using Amazon.DynamoDBv2.Model; 10 | 11 | // Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. 12 | [assembly: LambdaSerializerAttribute(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 13 | 14 | namespace BLUEPRINT_BASE_NAME 15 | { 16 | public class Function 17 | { 18 | private static readonly JsonSerializer _jsonSerializer = new JsonSerializer(); 19 | 20 | public void FunctionHandler(DynamoDBEvent dynamoEvent, ILambdaContext context) 21 | { 22 | context.Logger.LogLine($"Beginning to process {dynamoEvent.Records.Count} records..."); 23 | 24 | foreach (var record in dynamoEvent.Records) 25 | { 26 | context.Logger.LogLine($"Event ID: {record.EventID}"); 27 | context.Logger.LogLine($"Event Name: {record.EventName}"); 28 | 29 | string streamRecordJson = SerializeStreamRecord(record.Dynamodb); 30 | context.Logger.LogLine($"DynamoDB Record:"); 31 | context.Logger.LogLine(streamRecordJson ); 32 | } 33 | 34 | context.Logger.LogLine("Stream processing complete."); 35 | } 36 | 37 | private string SerializeStreamRecord(StreamRecord streamRecord) 38 | { 39 | using (var writer = new StringWriter()) 40 | { 41 | _jsonSerializer.Serialize(writer, streamRecord); 42 | return writer.ToString(); 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.S3Events/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.S3Events 2 | 3 | This package contains classes that can be used as input types for Lambda functions that process Amazon Simple Storage Service (Amazon S3) events. 4 | 5 | This package has a dependency on the [AWS SDK for .NET package AWSSDK.S3](https://www.nuget.org/packages/AWSSDK.S3/) in order to use the `Amazon.S3.Util.S3EventNotification` type. 6 | 7 | # Serialization 8 | 9 | If you are using this package with Amazon Lambda but are not also using `Amazon.Lambda.Serialization.Json`, be aware that two properties require custom serialization. These properties are both part of the `Amazon.S3.Util.S3EventNotification+ResponseElementsEntity` class. 10 | 1. `XAmzRequestId` should be treated as `x-amz-request-id` 11 | 2. `XAmzId2` should be treated as `x-amz-id-2` 12 | 13 | A Newtonsoft.Json `IContractResolver` implementation which handles this custom serialization is located in [Amazon.Lambda.Serialization.Json\AwsResolver.cs](Libraries/Amazon.Lambda.Serialization.Json/AwsResolver.cs), consult this source for more information. 14 | 15 | # Sample Function 16 | 17 | Below is a sample class and Lambda function that illustrates how an S3Event can be used. The function logs a summary of the events it received, including the type and time of event, bucket, and key. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) 18 | 19 | ``` 20 | public class Function 21 | { 22 | public string Handler(S3Event s3Event) 23 | { 24 | foreach(var record in s3Event.Records) 25 | { 26 | var s3 = record.S3; 27 | Console.WriteLine($"[{record.EventSource} - {record.EventTime}] Bucket = {s3.Bucket.Name}, Key = {s3.Object.Key}"); 28 | } 29 | } 30 | } 31 | ``` -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/project.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "Microsoft.NETCore.App": { 4 | "version": "1.0.1", 5 | "type": "platform" 6 | }, 7 | "Microsoft.ApplicationInsights.AspNetCore": "1.0.0", 8 | "Microsoft.AspNetCore.Mvc": "1.0.1", 9 | "Microsoft.AspNetCore.Routing": "1.0.1", 10 | "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 11 | "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", 12 | "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 13 | "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", 14 | "Microsoft.Extensions.Configuration.Json": "1.0.0", 15 | "Microsoft.Extensions.Logging": "1.0.0", 16 | "Microsoft.Extensions.Logging.Console": "1.0.0", 17 | "Microsoft.Extensions.Logging.Debug": "1.0.0", 18 | "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", 19 | 20 | "Amazon.Lambda.AspNetCoreServer": { "target": "project" } 21 | }, 22 | 23 | "tools": { 24 | "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" 25 | }, 26 | 27 | "frameworks": { 28 | "netcoreapp1.0": { 29 | "imports": [ 30 | "dotnet5.6", 31 | "portable-net45+win8" 32 | ] 33 | } 34 | }, 35 | 36 | "buildOptions": { 37 | "emitEntryPoint": true, 38 | "preserveCompilationContext": true 39 | }, 40 | 41 | "runtimeOptions": { 42 | "configProperties": { 43 | "System.GC.Server": true 44 | } 45 | }, 46 | 47 | "publishOptions": { 48 | "include": [ 49 | "wwwroot", 50 | "**/*.cshtml", 51 | "appsettings.json", 52 | "web.config" 53 | ] 54 | }, 55 | 56 | "scripts": { 57 | "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.AspNetCoreServer/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.AspNetCoreServer 2 | 3 | This package makes it easy to run ASP.NET Core Web API applications as a Lambda function with API Gateway. This allows .NET Core developers to 4 | create "serverless" applications using the ASP.NET Core Web API framework. 5 | 6 | The function takes expects a request from an [API Gateway Proxy](http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy.html) 7 | and converts that request into the classes the ASP.NET Core framework expects and then converts the response from the ASP.NET Core 8 | framework into the response body that API Gateway Proxy understands. 9 | 10 | ## Example Lambda Function 11 | 12 | In the ASP.NET Core application add a class that extends from [ApiGatewayFunction](src/Amazon.Lambda.AspNetCoreServer/APIGatewayProxyFunction.cs) 13 | and implement the Init method. 14 | 15 | Here is an example implementation of the Lamba function in an ASP.NET Core Web API application. 16 | ``` 17 | using System.IO; 18 | 19 | using AWS.Lambda.AspNetCoreServer; 20 | using Microsoft.AspNetCore.Hosting; 21 | 22 | namespace TestWebApp 23 | { 24 | public class LambdaFunction : ApiGatewayFunction 25 | { 26 | protected override void Init(IWebHostBuilder builder) 27 | { 28 | builder 29 | .UseApiGateway() 30 | .UseContentRoot(Directory.GetCurrentDirectory()) 31 | .UseStartup(); 32 | } 33 | } 34 | } 35 | ``` 36 | 37 | The function handler for the Lambda function will be **TestWebApp::TestWebApp.LambdaFunction::FunctionHandlerAsync**. 38 | 39 | Once the function is deployed configure API Gateway with a HTTP Proxy to call the Lambda Function. Refer to the API Gateway 40 | [developer guide](http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-create-api-as-simple-proxy.html) for more information. -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.AspNetCoreServer/WebHostBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.Extensions.DependencyInjection; 7 | 8 | using Amazon.Lambda.AspNetCoreServer.Internal; 9 | using Microsoft.AspNetCore.Hosting.Server; 10 | 11 | namespace Microsoft.AspNetCore.Hosting 12 | { 13 | /// 14 | /// This class is a container for extensions methods to the IWebHostBuilder 15 | /// 16 | public static class WebHostBuilderExtensions 17 | { 18 | /// 19 | /// Extension method for configuring API Gateway as the server for an ASP.NET Core application. 20 | /// This is called instead of UseKestrel. If UseKestrel was called before this it will remove 21 | /// the service description that was added to the IServiceCollection. 22 | /// 23 | /// 24 | /// 25 | public static IWebHostBuilder UseApiGateway(this IWebHostBuilder hostBuilder) 26 | { 27 | return hostBuilder.ConfigureServices(services => 28 | { 29 | var serviceDescription = services.FirstOrDefault(x => x.ServiceType == typeof(IServer)); 30 | if(serviceDescription != null) 31 | { 32 | // If Api Gateway server has already been added the skip out. 33 | if (serviceDescription.ImplementationType == typeof(APIGatewayServer)) 34 | return; 35 | // If there is already an IServer registeried then remove. This is mostly likely caused 36 | // by leaving the UseKestrel call. 37 | else 38 | services.Remove(serviceDescription); 39 | } 40 | 41 | services.AddSingleton(); 42 | }); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleDynamoDBFunction/test/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Xunit; 7 | 8 | using Amazon; 9 | using Amazon.Lambda.Core; 10 | using Amazon.Lambda.DynamoDBEvents; 11 | using Amazon.Lambda.TestUtilities; 12 | using Amazon.DynamoDBv2; 13 | using Amazon.DynamoDBv2.Model; 14 | 15 | using BLUEPRINT_BASE_NAME; 16 | 17 | namespace BLUEPRINT_BASE_NAME.Tests 18 | { 19 | public class FunctionTest 20 | { 21 | [Fact] 22 | public void TestFunction() 23 | { 24 | DynamoDBEvent evnt = new DynamoDBEvent 25 | { 26 | Records = new List 27 | { 28 | new DynamoDBEvent.DynamodbStreamRecord 29 | { 30 | AwsRegion = "us-west-2", 31 | Dynamodb = new StreamRecord 32 | { 33 | ApproximateCreationDateTime = DateTime.Now, 34 | Keys = new Dictionary { {"id", new AttributeValue { S = "MyId" } } }, 35 | NewImage = new Dictionary { { "field1", new AttributeValue { S = "NewValue" } }, { "field2", new AttributeValue { S = "AnotherNewValue" } } }, 36 | OldImage = new Dictionary { { "field1", new AttributeValue { S = "OldValue" } }, { "field2", new AttributeValue { S = "AnotherOldValue" } } }, 37 | StreamViewType = StreamViewType.NEW_AND_OLD_IMAGES 38 | } 39 | } 40 | } 41 | }; 42 | 43 | 44 | var context = new TestLambdaContext(); 45 | var function = new Function(); 46 | 47 | function.FunctionHandler(evnt, context); 48 | 49 | var testLogger = context.Logger as TestLambdaLogger; 50 | Assert.True(testLogger.Buffer.ToString().Contains("Stream processing complete")); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Serialization.Json/JsonSerializer.cs: -------------------------------------------------------------------------------- 1 | using Amazon.Lambda.Core; 2 | using Newtonsoft.Json; 3 | using System.IO; 4 | 5 | namespace Amazon.Lambda.Serialization.Json 6 | { 7 | /// 8 | /// Custom ILambdaSerializer implementation which uses Newtonsoft.Json 9.0.1 9 | /// for serialization. 10 | /// 11 | public class JsonSerializer : ILambdaSerializer 12 | { 13 | private Newtonsoft.Json.JsonSerializer serializer; 14 | 15 | /// 16 | /// Constructs instance of serializer. 17 | /// 18 | public JsonSerializer() 19 | { 20 | JsonSerializerSettings settings = new JsonSerializerSettings(); 21 | settings.ContractResolver = new AwsResolver(); 22 | serializer = Newtonsoft.Json.JsonSerializer.Create(settings); 23 | } 24 | 25 | /// 26 | /// Serializes a particular object to a stream. 27 | /// 28 | /// Type of object to serialize. 29 | /// Object to serialize. 30 | /// Output stream. 31 | public void Serialize(T response, Stream responseStream) 32 | { 33 | StreamWriter writer = new StreamWriter(responseStream); 34 | serializer.Serialize(writer, response); 35 | writer.Flush(); 36 | } 37 | 38 | /// 39 | /// Deserializes a stream to a particular type. 40 | /// 41 | /// Type of object to deserialize to. 42 | /// Stream to serialize. 43 | /// Deserialized object from stream. 44 | public T Deserialize(Stream requestStream) 45 | { 46 | StreamReader reader = new StreamReader(requestStream); 47 | JsonReader jsonReader = new JsonTextReader(reader); 48 | return serializer.Deserialize(jsonReader); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyServerless/src/Readme.md: -------------------------------------------------------------------------------- 1 | # Empty AWS Serverless Application Project 2 | 3 | This starter project consists of: 4 | * serverless.template - an AWS CloudFormation Serverless Application Model template file for declaring your Serverless functions and other AWS resources 5 | * Function.cs - class file containing the C# method mapped to the single function declared in the template file 6 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 7 | * project.json - .NET Core project file with build and tool declarations for the Amazon.Lambda.Tools Nuget package 8 | 9 | You may also have a test project depending on the options selected. 10 | 11 | The generated project contains a Serverless template declaration for a single AWS Lambda function that will be exposed through Amazon API Gateway as a HTTP *Get* operation. Edit the template to customize the function or add more functions and other resources needed by your application, and edit the function code in Function.cs. You can then deploy your Serverless application. 12 | 13 | ## Here are some steps to follow from Visual Studio: 14 | 15 | To deploy your Serverless application, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 16 | 17 | To view your deployed application open the Stack View window by double-clicking the stack name shown beneath the AWS CloudFormation node in the AWS Explorer tree. The Stack View also displays the root URL to your published application. 18 | 19 | ## Here are some steps to follow to get started from the command line: 20 | 21 | Once you have edited your template and code you can use the following command lines to deploy your application from the command line (these examples assume the project name is *EmptyServerless*): 22 | 23 | Restore dependencies 24 | ``` 25 | cd "EmptyServerless" 26 | dotnet restore 27 | ``` 28 | 29 | Execute unit tests 30 | ``` 31 | cd "EmptyServerless/test/EmptyServerless.Tests" 32 | dotnet test 33 | ``` 34 | 35 | Deploy application 36 | ``` 37 | cd "EmptyServerless/src/EmptyServerless" 38 | dotnet lambda deploy-serverless 39 | ``` 40 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Serialization.Json/AwsResolver.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using Newtonsoft.Json.Serialization; 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | namespace Amazon.Lambda.Serialization.Json 7 | { 8 | /// 9 | /// Custom contract resolver for handling special event cases. 10 | /// 11 | internal class AwsResolver : DefaultContractResolver 12 | { 13 | protected override IList CreateProperties(Type type, MemberSerialization memberSerialization) 14 | { 15 | IList properties = base.CreateProperties(type, memberSerialization); 16 | // S3 events use non-standard key formatting for request IDs and need to be mapped to the correct properties 17 | if (type.FullName.Equals("Amazon.S3.Util.S3EventNotification+ResponseElementsEntity", StringComparison.Ordinal)) 18 | { 19 | foreach (JsonProperty property in properties) 20 | { 21 | if (property.PropertyName.Equals("XAmzRequestId", StringComparison.Ordinal)) 22 | { 23 | property.PropertyName = "x-amz-request-id"; 24 | } 25 | else if (property.PropertyName.Equals("XAmzId2", StringComparison.Ordinal)) 26 | { 27 | property.PropertyName = "x-amz-id-2"; 28 | } 29 | } 30 | } 31 | // Kinesis events need a custom converter to deserialize the data MemoryStream 32 | else if (type.FullName.Equals("Amazon.Lambda.KinesisEvents.KinesisEvent+Record", StringComparison.Ordinal)) 33 | { 34 | foreach (JsonProperty property in properties) 35 | { 36 | if (property.PropertyName.Equals("Data", StringComparison.Ordinal)) 37 | { 38 | property.MemberConverter = new KinesisEventRecordDataConverter(); 39 | } 40 | } 41 | } 42 | 43 | return properties; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Libraries/test/TestWebApp/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace TestWebApp 12 | { 13 | public class Startup 14 | { 15 | public Startup(IHostingEnvironment env) 16 | { 17 | var builder = new ConfigurationBuilder() 18 | .SetBasePath(env.ContentRootPath) 19 | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) 20 | .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); 21 | 22 | if (env.IsEnvironment("Development")) 23 | { 24 | // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately. 25 | builder.AddApplicationInsightsSettings(developerMode: true); 26 | } 27 | 28 | builder.AddEnvironmentVariables(); 29 | Configuration = builder.Build(); 30 | } 31 | 32 | public IConfigurationRoot Configuration { get; } 33 | 34 | // This method gets called by the runtime. Use this method to add services to the container 35 | public void ConfigureServices(IServiceCollection services) 36 | { 37 | // Add framework services. 38 | services.AddApplicationInsightsTelemetry(Configuration); 39 | 40 | services.AddMvc(); 41 | } 42 | 43 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline 44 | public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) 45 | { 46 | loggerFactory.AddConsole(Configuration.GetSection("Logging")); 47 | loggerFactory.AddDebug(); 48 | 49 | app.UseApplicationInsightsRequestTelemetry(); 50 | 51 | app.UseApplicationInsightsExceptionTelemetry(); 52 | 53 | app.UseMvc(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Options/CommandOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace Amazon.Lambda.Tools.Options 7 | { 8 | 9 | /// 10 | /// Container for all the command options 11 | /// 12 | public class CommandOptions 13 | { 14 | Dictionary _values = new Dictionary(); 15 | 16 | public int Count 17 | { 18 | get { return this._values.Count; } 19 | } 20 | 21 | /// 22 | /// Gets the list of command line arguments that are not associated with a command option. Currently 23 | /// the only valid value for this is function name. 24 | /// 25 | public IList Arguments { get; } = new List(); 26 | 27 | /// 28 | /// Adds a CommandOption along with its value 29 | /// 30 | /// 31 | /// 32 | public void AddOption(CommandOption option, CommandOptionValue value) 33 | { 34 | _values[option] = value; 35 | } 36 | 37 | /// 38 | /// Gets the command option along with its value. The argument is searched for using both the short switch and the full switch. 39 | /// 40 | /// 41 | /// 42 | public Tuple FindCommandOption(string argument) 43 | { 44 | var option = _values.Keys.FirstOrDefault(x => 45 | { 46 | if (string.Equals(argument, x.ShortSwitch, StringComparison.OrdinalIgnoreCase) || 47 | string.Equals(argument, x.Switch, StringComparison.OrdinalIgnoreCase)) 48 | return true; 49 | 50 | return false; 51 | }); 52 | 53 | if (option == null) 54 | return null; 55 | 56 | return new Tuple(option, _values[option]); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.KinesisEvents/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.KinesisEvents 2 | 3 | This package contains classes that can be used as input types for Lambda functions that process Amazon Kinesis events. 4 | 5 | This package has a dependency on the [AWS SDK for .NET package AWSSDK.Kinesis](https://www.nuget.org/packages/AWSSDK.Kinesis/) in order to use the `Amazon.Kinesis.Model.Record` type. 6 | 7 | # Serialization 8 | 9 | If you are using this package with Amazon Lambda but are not also using `Amazon.Lambda.Serialization.Json`, be aware that one property requires custom serialization. 10 | 11 | This property is `Data` on the type `Amazon.Lambda.KinesisEvents.KinesisEvent+Record`. This is a `MemoryStream` object that should be populated by converting the JSON string from base64 to an array of bytes, then constructing a `MemoryStream` object from these bytes. Here is a code sample showing this deserialization logic. 12 | ``` 13 | string dataBase64 = GetJsonString(); 14 | byte[] dataBytes = Convert.FromBase64String(dataBase64); 15 | MemoryStream stream = new MemoryStream(dataBytes); 16 | ``` 17 | 18 | A Newtonsoft.Json `IContractResolver` implementation which handles this custom serialization is located in [Amazon.Lambda.Serialization.Json\AwsResolver.cs](Libraries/Amazon.Lambda.Serialization.Json/AwsResolver.cs) and [Amazon.Lambda.Serialization.Json\KinesisEventRecordDataConverter.cs](Libraries/Amazon.Lambda.Serialization.Json/KinesisEventRecordDataConverter.cs), consult this source for more information. 19 | 20 | # Sample Function 21 | 22 | The following is a sample class and Lambda function that receives Amazon Kinesis event record data as an input and logs some of the incoming event data. (Note that by default anything written to Console will be logged as CloudWatch Logs events.) 23 | 24 | ``` 25 | public class Function 26 | { 27 | public string Handler(KinesisEvent kinesisEvent) 28 | { 29 | foreach (var record in kinesisEvent.Records) 30 | { 31 | var kinesisRecord = record.Kinesis; 32 | var dataBytes = kinesisRecord.Data.ToArray(); 33 | var dataText = Encoding.UTF8.GetString(dataBytes); 34 | Console.WriteLine($"[{record.EventName}] Data = '{dataText}'."); 35 | } 36 | } 37 | } 38 | ``` 39 | -------------------------------------------------------------------------------- /Blueprints/README.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda .NET Blueprints 2 | 3 | Blueprints are used for setting up new .NET Core projects for AWS Lambda. They are defined in a generic form 4 | so that they can be exposed through Visual Studio or [Yeoman](http://yeoman.io/). 5 | 6 | ## Definitions 7 | 8 | The blueprints are defined in sub directories under the BlueprintDefinitions directory. For each blueprint there 9 | is a blueprint-manifest.json file containing the metadata for the blueprint and a src and test directory. 10 | It is required that each blueprint must contain a test project. 11 | 12 | ## Packaging 13 | 14 | The .NET Core console application BlueprintPackager is used to package up the blueprints for both Visual Studio and Yeoman. 15 | The console application can be run by executing `dotnet run` in the project directory. 16 | 17 | ## Visual Studio 18 | 19 | The BlueprintPackager will write the blueprints to the ../Deployment/Blueprints/VisualStudioBlueprints directory. You can test 20 | how your blueprints work in Visual Studio by copying the directory to C:\Program Files (x86)\AWS Tools\HostedFiles\LambdaSampleFunctions\NETCore\v1 21 | and then point AWS Toolkit for Visual Studio to C:\Program Files (x86)\AWS Tools\HostedFiles to get its metadata. To update 22 | the toolkit open Visual Studio's Options dialog from the Tools menu, select AWS Toolkit and select "Use local file system location". 23 | 24 | ## Yeoman 25 | 26 | To use the blueprints with Yeoman you must first install [npm](https://nodejs.org/en/) which is part of the Node.js 27 | install. Once npm is installed you can install Yeoman by running the following command. 28 | 29 | ``` 30 | npm install -g yo 31 | ``` 32 | 33 | To install the current distributed version of the AWS Lambda .NET Core blueprints run the following command. 34 | 35 | ``` 36 | npm install -g generator-aws-lambda-dotnet 37 | ``` 38 | 39 | When the BlueprintPackager runs it will copy the Yeoman generator to ../Deployment/Blueprints/generator-aws-lambda-dotnet. 40 | To use these blueprints instead of the distributed version execute the command `npm link` in the directory. To switch 41 | back to the distributed version execute the command `npm unlink`. 42 | 43 | To run the Yeoman generator which will allow you to pick a blueprint run the following command. 44 | ``` 45 | yo aws-lambda-dotnet 46 | ``` -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/EmptyFunction/src/Readme.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda Empty Function Project 2 | 3 | This starter project consists of: 4 | * Function.cs - class file containing a class with a single function handler method 5 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 6 | * project.json - .NET Core project file with build and tool declarations for the Amazon.Lambda.Tools Nuget package 7 | 8 | You may also have a test project depending on the options selected. 9 | 10 | 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. 11 | 12 | ## Here are some steps to follow from Visual Studio: 13 | 14 | To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 15 | 16 | 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. 17 | 18 | To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. 19 | 20 | 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. 21 | 22 | To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. 23 | 24 | To view execution logs of invocations of your function use the Logs tab in the opened Function View window. 25 | 26 | ## Here are some steps to follow to get started from the command line: 27 | 28 | Once you have edited your function you can use the following command lines to build, test and deploy your function to AWS Lambda from the command line (these examples assume the project name is *EmptyFunction*): 29 | 30 | Restore dependencies 31 | ``` 32 | cd "EmptyFunction" 33 | dotnet restore 34 | ``` 35 | 36 | Execute unit tests 37 | ``` 38 | cd "EmptyFunction/test/EmptyFunction.Tests" 39 | dotnet test 40 | ``` 41 | 42 | Deploy function to AWS Lambda 43 | ``` 44 | cd "EmptyFunction/src/EmptyFunction" 45 | dotnet lambda deploy-function 46 | ``` 47 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Logging.AspNetCore/IConfigurationExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Logging; 2 | using System; 3 | 4 | // Same namespace as IConfiguration, to make these extensions appear 5 | // without the user needing to including our namespace first. 6 | namespace Microsoft.Extensions.Configuration 7 | { 8 | /// 9 | /// IConfiguration extensions 10 | /// 11 | public static class IConfigurationExtensions 12 | { 13 | /// 14 | /// Creates LambdaLoggerOptions instance from "Lambda.Logging" section of the 15 | /// specified configuration. 16 | /// 17 | /// Configuration to get settings from. 18 | /// 19 | [CLSCompliant(false)] // https://github.com/aspnet/Logging/issues/500 20 | public static LambdaLoggerOptions GetLambdaLoggerOptions(this IConfiguration configuration) 21 | { 22 | if (configuration == null) 23 | { 24 | throw new ArgumentNullException(nameof(configuration)); 25 | } 26 | 27 | return new LambdaLoggerOptions(configuration); 28 | } 29 | 30 | /// 31 | /// Creates LambdaLoggerOptions instance from the specified subsection of the 32 | /// configuration section. 33 | /// 34 | /// Configuration to get settings from. 35 | /// Name of section from which to get configuration data. 36 | /// 37 | [CLSCompliant(false)] // https://github.com/aspnet/Logging/issues/500 38 | public static LambdaLoggerOptions GetLambdaLoggerOptions(this IConfiguration configuration, string loggingSectionName) 39 | { 40 | if (configuration == null) 41 | { 42 | throw new ArgumentNullException(nameof(configuration)); 43 | } 44 | if (string.IsNullOrEmpty(loggingSectionName)) 45 | { 46 | throw new ArgumentNullException(nameof(loggingSectionName)); 47 | } 48 | 49 | return new LambdaLoggerOptions(configuration, loggingSectionName); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Blueprints/YeomanGenerator/generator-aws-lambda-dotnet/README.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda .NET Blueprints 2 | 3 | Blueprints are used for setting up new .NET Core projects for AWS Lambda. They are defined in a generic form 4 | so that they can be exposed through Visual Studio or [Yeoman](http://yeoman.io/). 5 | 6 | ## Definitions 7 | 8 | The blueprints are defined in sub directories under the BlueprintDefinitions directory. For each blueprint there 9 | is a blueprint-manifest.json file containing the metadata for the blueprint and a src and test directory. 10 | It is required that each blueprint must contain a test project. 11 | 12 | ## Packaging 13 | 14 | The .NET Core console application BlueprintPackager is used to package up the blueprints for both Visual Studio and Yeoman. 15 | The console application can be run by executing `dotnet run` in the project directory. 16 | 17 | ## Visual Studio 18 | 19 | The BlueprintPackager will write the blueprints to the ../Deployment/Blueprints/VisualStudioBlueprints directory. You can test 20 | how your blueprints work in Visual Studio by copying the directory to C:\Program Files (x86)\AWS Tools\HostedFiles\LambdaSampleFunctions\NETCore\v1 21 | and then point AWS Toolkit for Visual Studio to C:\Program Files (x86)\AWS Tools\HostedFiles to get its metadata. To update 22 | the toolkit open Visual Studio's Options dialog from the Tools menu, select AWS Toolkit and select "Use local file system location". 23 | 24 | ## Yeoman 25 | 26 | To use the blueprints with Yeoman you must first install [npm](https://nodejs.org/en/) which is part of the Node.js 27 | install. Once npm is installed you can install Yeoman by running the following command. 28 | 29 | ``` 30 | npm install -g yo 31 | ``` 32 | 33 | To install the current distributed version of the AWS Lambda .NET Core blueprints run the following command. 34 | 35 | ``` 36 | npm install -g generator-aws-lambda-dotnet 37 | ``` 38 | 39 | When the BlueprintPackager runs it will copy the Yeoman generator to ../Deployment/Blueprints/generator-aws-lambda-dotnet. 40 | To use these blueprints instead of the distributed version execute the command `npm link` in the directory. To switch 41 | back to the distributed version execute the command `npm unlink`. 42 | 43 | To run the Yeoman generator which will allow you to pick a blueprint run the following command. 44 | ``` 45 | yo aws-lambda-dotnet 46 | ``` -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/DynamoDBBlogAPI/src/Readme.md: -------------------------------------------------------------------------------- 1 | # Amazon DynamoDB Blog API Serverless Application Project 2 | 3 | This starter project consists of: 4 | * serverless.template - an AWS CloudFormation Serverless Application Model template file for declaring your Serverless functions and other AWS resources 5 | * Function.cs - class file containing the C# methods mapped to the Serverless functions declared in the template file 6 | * Blog.cs - file containing a C# class representing a blog entry in the DynamoDB table 7 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 8 | * project.json - .NET Core project file with build and tool declarations for the Amazon.Lambda.Tools Nuget package 9 | 10 | You may also have a test project depending on the options selected. 11 | 12 | The generated project contains a Serverless template declaration for a simple web API for blogging with the blog data stored in a DynamoDB table. The blogging API functions are hosted as a set of AWS Lambda functions that will be exposed through Amazon API Gateway as HTTP operations. Edit the template to customize the functions or add more functions and other resources needed by your application, and edit the function code in Function.cs/Blog.cs. You can then deploy your Serverless application. 13 | 14 | ## Here are some steps to follow from Visual Studio: 15 | 16 | To deploy your Serverless application, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 17 | 18 | To view your deployed application open the Stack View window by double-clicking the stack name shown beneath the AWS CloudFormation node in the AWS Explorer tree. The Stack View also displays the root URL to your published application. 19 | 20 | ## Here are some steps to follow to get started from the command line: 21 | 22 | Once you have edited your template and code you can use the following command lines to deploy your application from the command line (these examples assume the project name is *EmptyServerless*): 23 | 24 | Restore dependencies 25 | ``` 26 | cd "EmptyServerless" 27 | dotnet restore 28 | ``` 29 | 30 | Execute unit tests 31 | ``` 32 | cd "EmptyServerless/test/EmptyServerless.Tests" 33 | dotnet test 34 | ``` 35 | 36 | Deploy application 37 | ``` 38 | cd "EmptyServerless/src/EmptyServerless" 39 | dotnet lambda deploy-serverless 40 | ``` 41 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.CognitoEvents/CognitoEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.CognitoEvents 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | /// 7 | /// AWS Cognito event 8 | /// http://docs.aws.amazon.com/cognito/latest/developerguide/cognito-events.html 9 | /// http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-cognito-sync-trigger 10 | /// 11 | public class CognitoEvent 12 | { 13 | /// 14 | /// The data set name of the event. 15 | /// 16 | public string DatasetName { get; set; } 17 | 18 | /// 19 | /// The map of data set records for the event. 20 | /// 21 | public IDictionary DatasetRecords { get; set; } 22 | 23 | /// 24 | /// The event type. 25 | /// 26 | public string EventType { get; set; } 27 | 28 | /// 29 | /// The identity pool ID associated with the data set. 30 | /// 31 | public string IdentityId { get; set; } 32 | 33 | /// 34 | /// The identity pool ID associated with the data set. 35 | /// 36 | public string IdentityPoolId { get; set; } 37 | 38 | /// 39 | /// The region in which data set resides. 40 | /// 41 | public string Region { get; set; } 42 | 43 | /// 44 | /// The event version. 45 | /// 46 | public int Version { get; set; } 47 | 48 | /// 49 | /// Data set records for the event. 50 | /// 51 | public class DatasetRecord 52 | { 53 | /// 54 | /// The record's new value. 55 | /// 56 | public string NewValue { get; set; } 57 | 58 | /// 59 | /// The record's old value. 60 | /// 61 | public string OldValue { get; set; } 62 | 63 | /// 64 | /// The operation associated with the record. 65 | /// For a new record or any updates to existing record it is set to "replace". 66 | /// For deleting a record it is set to "remove". 67 | /// 68 | public string Op { get; set; } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.AspNetCoreServer.Test/TestCallingWebAPI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | using Amazon.Lambda.APIGatewayEvents; 8 | using TestWebApp; 9 | using Xunit; 10 | 11 | using Newtonsoft.Json; 12 | 13 | namespace Amazon.Lambda.AspNetCoreServer.Test 14 | { 15 | public class TestCallingWebAPI 16 | { 17 | public TestCallingWebAPI() 18 | { 19 | } 20 | 21 | [Fact] 22 | public async Task TestGetAllValues() 23 | { 24 | var lambdaFunction = new LambdaFunction(); 25 | 26 | var requestStr = File.ReadAllText("values-get-all-apigatway-request.json"); 27 | var request = JsonConvert.DeserializeObject(requestStr); 28 | var response = await lambdaFunction.FunctionHandlerAsync(request, null); 29 | 30 | Assert.Equal("[\"value1\",\"value2\"]", response.Body); 31 | Assert.True(response.Headers.ContainsKey("Content-Type")); 32 | Assert.Equal("application/json; charset=utf-8", response.Headers["Content-Type"]); 33 | } 34 | 35 | [Fact] 36 | public async Task TestGetSingleValue() 37 | { 38 | var lambdaFunction = new LambdaFunction(); 39 | 40 | var requestStr = File.ReadAllText("values-get-single-apigatway-request.json"); 41 | var request = JsonConvert.DeserializeObject(requestStr); 42 | var response = await lambdaFunction.FunctionHandlerAsync(request, null); 43 | 44 | Assert.Equal("value=5", response.Body); 45 | Assert.True(response.Headers.ContainsKey("Content-Type")); 46 | Assert.Equal("text/plain; charset=utf-8", response.Headers["Content-Type"]); 47 | } 48 | 49 | [Fact] 50 | public async Task TestGetQueryStringValue() 51 | { 52 | var lambdaFunction = new LambdaFunction(); 53 | 54 | var requestStr = File.ReadAllText("values-get-querystring-apigatway-request.json"); 55 | var request = JsonConvert.DeserializeObject(requestStr); 56 | var response = await lambdaFunction.FunctionHandlerAsync(request, null); 57 | 58 | Assert.Equal("Lewis, Meriwether", response.Body); 59 | Assert.True(response.Headers.ContainsKey("Content-Type")); 60 | Assert.Equal("text/plain; charset=utf-8", response.Headers["Content-Type"]); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleS3Function/src/Readme.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda Simple S3 Function Project 2 | 3 | This starter project consists of: 4 | * Function.cs - class file containing a class with a single function handler method 5 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 6 | * project.json - .NET Core project file with build and tool declarations for the Amazon.Lambda.Tools Nuget package 7 | 8 | You may also have a test project depending on the options selected. 9 | 10 | The generated function handler responds to events on an Amazon S3 bucket. The handler receives the buckey and object key details in a S3Event instance and returns the content type of the object as the function output. Replace the body of this method, and parameters, to suit your needs. 11 | 12 | After deploying your function you must configure an Amazon S3 bucket as an event source to trigger your Lambda function. 13 | 14 | ## Here are some steps to follow from Visual Studio: 15 | 16 | To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 17 | 18 | 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. 19 | 20 | To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. 21 | 22 | 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. 23 | 24 | To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. 25 | 26 | To view execution logs of invocations of your function use the Logs tab in the opened Function View window. 27 | 28 | ## Here are some steps to follow to get started from the command line: 29 | 30 | Once you have edited your function you can use the following command lines to build, test and deploy your function to AWS Lambda from the command line (these examples assume the project name is *SimpleS3Function*): 31 | 32 | Restore dependencies 33 | ``` 34 | cd "SimpleS3Function" 35 | dotnet restore 36 | ``` 37 | 38 | Execute unit tests 39 | ``` 40 | cd "SimpleS3Function/test/SimpleS3Function.Tests" 41 | dotnet test 42 | ``` 43 | 44 | Deploy function to AWS Lambda 45 | ``` 46 | cd "SimpleS3Function/src/SimpleS3Function" 47 | dotnet lambda deploy-function 48 | ``` 49 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleKinesisFunction/src/Readme.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda Simple Kinesis Function Project 2 | 3 | This starter project consists of: 4 | * Function.cs - class file containing a class with a single function handler method 5 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 6 | * project.json - .NET Core project file with build and tool declarations for the Amazon.Lambda.Tools Nuget package 7 | 8 | You may also have a test project depending on the options selected. 9 | 10 | The generated function handler responds to events on an Amazon Kinesis stream and serializes the record data to a string which is then written to the function's execution log. Replace the body of this method, and parameters, to suit your needs. 11 | 12 | After deploying your function you must configure an Amazon Kinesis stream as an event source to trigger your Lambda function. 13 | 14 | ## Here are some steps to follow from Visual Studio: 15 | 16 | To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 17 | 18 | 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. 19 | 20 | To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. 21 | 22 | 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. 23 | 24 | To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. 25 | 26 | To view execution logs of invocations of your function use the Logs tab in the opened Function View window. 27 | 28 | ## Here are some steps to follow to get started from the command line: 29 | 30 | Once you have edited your function you can use the following command lines to build, test and deploy your function to AWS Lambda from the command line (these examples assume the project name is *SimpleKinesisFunction*): 31 | 32 | Restore dependencies 33 | ``` 34 | cd "SimpleKinesisFunction" 35 | dotnet restore 36 | ``` 37 | 38 | Execute unit tests 39 | ``` 40 | cd "SimpleKinesisFunction/test/SimpleKinesisFunction.Tests" 41 | dotnet test 42 | ``` 43 | 44 | Deploy function to AWS Lambda 45 | ``` 46 | cd "SimpleKinesisFunction/src/SimpleKinesisFunction" 47 | dotnet lambda deploy-function 48 | ``` 49 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleDynamoDBFunction/src/Readme.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda Simple DynamoDB Function Project 2 | 3 | This starter project consists of: 4 | * Function.cs - class file containing a class with a single function handler method 5 | * aws-lambda-tools-defaults.json - default argument settings for use with Visual Studio and command line deployment tools for AWS 6 | * project.json - .NET Core project file with build and tool declarations for the Amazon.Lambda.Tools Nuget package 7 | 8 | You may also have a test project depending on the options selected. 9 | 10 | The generated function handler responds to events on an Amazon DynamoDB stream and serializes the records to a JSON string which are written to the function's execution log. Replace the body of this method, and parameters, to suit your needs. 11 | 12 | After deploying your function you must configure an Amazon DynamoDB stream as an event source to trigger your Lambda function. 13 | 14 | ## Here are some steps to follow from Visual Studio: 15 | 16 | To deploy your function to AWS Lambda, right click the project in Solution Explorer and select *Publish to AWS Lambda*. 17 | 18 | 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. 19 | 20 | To perform testing against your deployed function use the Test Invoke tab in the opened Function View window. 21 | 22 | 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. 23 | 24 | To update the runtime configuration of your deployed function use the Configuration tab in the opened Function View window. 25 | 26 | To view execution logs of invocations of your function use the Logs tab in the opened Function View window. 27 | 28 | ## Here are some steps to follow to get started from the command line: 29 | 30 | Once you have edited your function you can use the following command lines to build, test and deploy your function to AWS Lambda from the command line (these examples assume the project name is *SimpleDynamoDBFunction*): 31 | 32 | Restore dependencies 33 | ``` 34 | cd "SimpleDynamoDBFunction" 35 | dotnet restore 36 | ``` 37 | 38 | Execute unit tests 39 | ``` 40 | cd "SimpleDynamoDBFunction/test/SimpleDynamoDBFunction.Tests" 41 | dotnet test 42 | ``` 43 | 44 | Deploy function to AWS Lambda 45 | ``` 46 | cd "SimpleDynamoDBFunction/src/SimpleDynamoDBFunction" 47 | dotnet lambda deploy-function 48 | ``` 49 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Logging.AspNetCore/README.md: -------------------------------------------------------------------------------- 1 | # Amazon.Lambda.Logging.AspNetCore 2 | 3 | This package contains an implementation of ASP.NET Core's ILogger class, allowing an application to use the standard ASP.NET Core logging functionality to write CloudWatch Log events. 4 | 5 | # Configuration 6 | 7 | Lambda logging can be configured through code or using a file configuration loaded through the `IConfiguration` interface. 8 | The two below examples set the same logging options, but do it either through code or a JSON config file. 9 | 10 | ## Configuration through code 11 | 12 | ``` 13 | public void Configure(ILoggerFactory loggerFactory) 14 | { 15 | // Create and populate LambdaLoggerOptions object 16 | var loggerOptions = new LambdaLoggerOptions(); 17 | loggerOptions.IncludeCategory = false; 18 | loggerOptions.IncludeLogLevel = false; 19 | loggerOptions.IncludeNewline = true; 20 | 21 | // Configure Filter to only log some 22 | loggerOptions.Filter = (category, logLevel) => 23 | { 24 | // For some categories, only log events with minimum LogLevel 25 | if (string.Equals(category, "Default", StringComparison.Ordinal)) 26 | { 27 | return (logLevel >= LogLevel.Debug); 28 | } 29 | if (string.Equals(category, "Microsoft", StringComparison.Ordinal)) 30 | { 31 | return (logLevel >= LogLevel.Information); 32 | } 33 | 34 | // Log everything else 35 | return true; 36 | }; 37 | 38 | // Configure Lambda logging 39 | loggerFactory 40 | .AddLambdaLogger(loggerOptions); 41 | } 42 | ``` 43 | 44 | ## Configuration through IConfiguration 45 | 46 | Configuration file, `appsettings.json`: 47 | ``` 48 | { 49 | "Lambda.Logging": { 50 | "IncludeCategory": false, 51 | "IncludeLogLevel": false, 52 | "IncludeNewline": true, 53 | "LogLevel": { 54 | "Default": "Debug", 55 | "Microsoft": "Information" 56 | } 57 | } 58 | } 59 | ``` 60 | 61 | Creating `LambdaLoggerOptions` from the configuration file: 62 | ``` 63 | public void Configure(ILoggerFactory loggerFactory) 64 | { 65 | var configuration = new ConfigurationBuilder() 66 | .AddJsonFile(APPSETTINGS_PATH) 67 | .Build(); 68 | 69 | var loggerOptions = new LambdaLoggerOptions(configuration); 70 | var loggerfactory = new TestLoggerFactory() 71 | .AddLambdaLogger(loggerOptions); 72 | 73 | // Configure Lambda logging 74 | loggerFactory 75 | .AddLambdaLogger(loggerOptions); 76 | } 77 | ``` 78 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleS3Function/test/FunctionTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Xunit; 7 | using Amazon.Lambda; 8 | using Amazon.Lambda.Core; 9 | using Amazon.Lambda.TestUtilities; 10 | using Amazon.Lambda.S3Events; 11 | 12 | using Amazon; 13 | using Amazon.S3; 14 | using Amazon.S3.Model; 15 | using Amazon.S3.Util; 16 | 17 | using BLUEPRINT_BASE_NAME; 18 | 19 | namespace BLUEPRINT_BASE_NAME.Tests 20 | { 21 | public class FunctionTest 22 | { 23 | [Fact] 24 | public async Task TestS3EventLambdaFunction() 25 | { 26 | IAmazonS3 s3Client = new AmazonS3Client(RegionEndpoint.USWest2); 27 | 28 | var bucketName = "lambda-BLUEPRINT_BASE_NAME-".ToLower() + DateTime.Now.Ticks; 29 | var key = "text.txt"; 30 | 31 | // Create a bucket an object to setup a test data. 32 | await s3Client.PutBucketAsync(bucketName); 33 | try 34 | { 35 | await s3Client.PutObjectAsync(new PutObjectRequest 36 | { 37 | BucketName = bucketName, 38 | Key = key, 39 | ContentBody = "sample data" 40 | }); 41 | 42 | // Setup the S3 event object that S3 notifications would create with the fields used by the Lambda function. 43 | var s3Event = new S3Event 44 | { 45 | Records = new List 46 | { 47 | new S3EventNotification.S3EventNotificationRecord 48 | { 49 | S3 = new S3EventNotification.S3Entity 50 | { 51 | Bucket = new S3EventNotification.S3BucketEntity {Name = bucketName }, 52 | Object = new S3EventNotification.S3ObjectEntity {Key = key } 53 | } 54 | } 55 | } 56 | }; 57 | 58 | // Invoke the lambda function and confirm the content type was returned. 59 | var function = new Function(s3Client); 60 | var contentType = await function.FunctionHandler(s3Event, null); 61 | 62 | Assert.Equal("text/plain", contentType); 63 | 64 | } 65 | finally 66 | { 67 | // Clean up the test data 68 | await AmazonS3Util.DeleteS3BucketWithObjectsAsync(s3Client, bucketName); 69 | } 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Tools/Commands/ListFunctionCommand.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda; 7 | using Amazon.Lambda.Model; 8 | 9 | using Amazon.Lambda.Tools.Options; 10 | 11 | namespace Amazon.Lambda.Tools.Commands 12 | { 13 | /// 14 | /// List all the functions currently deployed to Lambda 15 | /// 16 | public class ListFunctionCommand : BaseCommand 17 | { 18 | public const string COMMAND_NAME = "list-functions"; 19 | public const string COMMAND_DESCRIPTION = "Command to list all your Lambda functions"; 20 | 21 | 22 | public static readonly IList ListCommandOptions = BuildLineOptions(new List 23 | { 24 | }); 25 | 26 | public ListFunctionCommand(IToolLogger logger, string workingDirectory, string[] args) 27 | : base(logger, workingDirectory, ListCommandOptions, args) 28 | { 29 | } 30 | 31 | public override async Task ExecuteAsync() 32 | { 33 | try 34 | { 35 | ListFunctionsRequest request = new ListFunctionsRequest(); 36 | ListFunctionsResponse response = null; 37 | do 38 | { 39 | if (response != null) 40 | request.Marker = response.NextMarker; 41 | 42 | try 43 | { 44 | response = await this.LamdbaClient.ListFunctionsAsync(request); 45 | } 46 | catch (Exception e) 47 | { 48 | throw new LambdaToolsException("Error listing Lambda functions: " + e.Message); 49 | } 50 | 51 | foreach (var function in response.Functions) 52 | { 53 | this.Logger.WriteLine((function.FunctionName.PadRight(40) + " (" + function.Runtime + ")").PadRight(10) + "\t" + function.Description); 54 | } 55 | 56 | } while (!string.IsNullOrEmpty(response.NextMarker)); 57 | } 58 | catch (LambdaToolsException e) 59 | { 60 | this.Logger.WriteLine(e.Message); 61 | return false; 62 | } 63 | catch (Exception e) 64 | { 65 | this.Logger.WriteLine($"Unknown error listing Lambda functions: {e.Message}"); 66 | this.Logger.WriteLine(e.StackTrace); 67 | return false; 68 | } 69 | 70 | return true; 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.KinesisEvents/KinesisEvent.cs: -------------------------------------------------------------------------------- 1 | namespace Amazon.Lambda.KinesisEvents 2 | { 3 | using System; 4 | using System.Collections.Generic; 5 | 6 | /// 7 | /// AWS Kinesis stream event 8 | /// http://docs.aws.amazon.com/lambda/latest/dg/with-kinesis.html 9 | /// http://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-kinesis-streams 10 | /// 11 | public class KinesisEvent 12 | { 13 | /// 14 | /// List of Kinesis event records. 15 | /// 16 | public IList Records { get; set; } 17 | 18 | /// 19 | /// AWS Kinesis stream record 20 | /// http://docs.aws.amazon.com/kinesis/latest/APIReference/API_Record.html 21 | /// 22 | public class Record : Amazon.Kinesis.Model.Record 23 | { 24 | /// 25 | /// The schema version for the record. 26 | /// 27 | public string KinesisSchemaVersion { get; set; } 28 | } 29 | 30 | /// 31 | /// Kinesis event record. 32 | /// 33 | public class KinesisEventRecord 34 | { 35 | /// 36 | /// The AWS region where the event originated. 37 | /// 38 | public string AwsRegion { get; set; } 39 | 40 | /// 41 | /// The event id. 42 | /// 43 | public string EventId { get; set; } 44 | 45 | /// 46 | /// The name of the event. 47 | /// 48 | public string EventName { get; set; } 49 | 50 | /// 51 | /// The source of the event. 52 | /// 53 | public string EventSource { get; set; } 54 | 55 | /// 56 | /// The ARN of the event source. 57 | /// 58 | public string EventSourceARN { get; set; } 59 | 60 | /// 61 | /// The event version. 62 | /// 63 | public string EventVersion { get; set; } 64 | 65 | /// 66 | /// The ARN for the identity used to invoke the Lambda Function. 67 | /// 68 | public string InvokeIdentityArn { get; set; } 69 | 70 | /// 71 | /// The underlying Kinesis record associated with the event. 72 | /// 73 | public Record Kinesis { get; set; } 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Blueprints/BlueprintDefinitions/SimpleS3Function/src/Function.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | using Amazon.Lambda.S3Events; 8 | using Amazon.S3; 9 | using Amazon.S3.Util; 10 | 11 | // Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class. 12 | [assembly: LambdaSerializerAttribute(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))] 13 | 14 | namespace BLUEPRINT_BASE_NAME 15 | { 16 | public class Function 17 | { 18 | IAmazonS3 S3Client { get; set; } 19 | 20 | /// 21 | /// Default constructor. This constructor is used by Lambda to construct the instance. When invoked in a Lambda environment 22 | /// the AWS credentials will come from the IAM role associated with the function and the AWS region will be set to the 23 | /// region the Lambda function is executed in. 24 | /// 25 | public Function() 26 | { 27 | S3Client = new AmazonS3Client(); 28 | } 29 | 30 | /// 31 | /// Constructs an instance with a preconfigured S3 client. This can be used for testing the outside of the Lambda environment. 32 | /// 33 | /// 34 | public Function(IAmazonS3 s3Client) 35 | { 36 | this.S3Client = s3Client; 37 | } 38 | 39 | /// 40 | /// This method is called for every Lambda invocation. This method takes in an S3 event object and can be used 41 | /// to respond to S3 notifications. 42 | /// 43 | /// 44 | /// 45 | /// 46 | public async Task FunctionHandler(S3Event evnt, ILambdaContext context) 47 | { 48 | var s3Event = evnt.Records?[0].S3; 49 | if(s3Event == null) 50 | { 51 | return null; 52 | } 53 | 54 | try 55 | { 56 | var response = await this.S3Client.GetObjectMetadataAsync(s3Event.Bucket.Name, s3Event.Object.Key); 57 | return response.Headers.ContentType; 58 | } 59 | catch(Exception e) 60 | { 61 | context.Logger.LogLine($"Error getting object {s3Event.Bucket.Name} from bucket {s3Event.Object.Key}. Make sure they exist and your bucket is in the same region as this function."); 62 | context.Logger.LogLine(e.Message); 63 | context.Logger.LogLine(e.StackTrace); 64 | throw; 65 | } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.TestUtilities/TestLambdaContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Amazon.Lambda.Core; 7 | 8 | namespace Amazon.Lambda.TestUtilities 9 | { 10 | /// 11 | /// A test implementation of the ILambdaContext interface used for writing local tests of Lambda Functions. 12 | /// 13 | public class TestLambdaContext : ILambdaContext 14 | { 15 | /// 16 | /// The AWS request ID associated with the request. 17 | /// 18 | public string AwsRequestId { get; set; } 19 | 20 | /// 21 | /// Information about the client application and device when invoked 22 | /// through the AWS Mobile SDK. 23 | /// 24 | public IClientContext ClientContext { get; set; } 25 | 26 | /// 27 | /// Name of the Lambda function that is running. 28 | /// 29 | public string FunctionName { get; set; } 30 | 31 | /// 32 | /// The Lambda function version that is executing. 33 | /// If an alias is used to invoke the function, then this will be 34 | /// the version the alias points to. 35 | /// 36 | public string FunctionVersion { get; set; } 37 | 38 | /// 39 | /// Information about the Amazon Cognito identity provider when 40 | /// invoked through the AWS Mobile SDK. 41 | /// 42 | public ICognitoIdentity Identity { get; set; } 43 | 44 | /// 45 | /// The ARN used to invoke this function. 46 | /// 47 | public string InvokedFunctionArn { get; set; } 48 | 49 | /// 50 | /// Lambda logger associated with the Context object. For the TestLambdaContext this is default to the TestLambdaLogger. 51 | /// 52 | public ILambdaLogger Logger { get; set; } = new TestLambdaLogger(); 53 | 54 | /// 55 | /// The CloudWatch log group name associated with the invoked function. 56 | /// 57 | public string LogGroupName { get; set; } 58 | 59 | /// 60 | /// The CloudWatch log stream name for this function execution. 61 | /// 62 | public string LogStreamName { get; set; } 63 | 64 | /// 65 | /// Memory limit, in MB, you configured for the Lambda function. 66 | /// 67 | public int MemoryLimitInMB { get; set; } 68 | 69 | /// 70 | /// Remaining execution time till the function will be terminated. 71 | /// 72 | public TimeSpan RemainingTime { get; set; } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /Libraries/src/Amazon.Lambda.Logging.AspNetCore/LambdaILogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Microsoft.Extensions.Logging 5 | { 6 | internal class LambdaILogger : ILogger 7 | { 8 | // Private fields 9 | private readonly string _categoryName; 10 | private readonly LambdaLoggerOptions _options; 11 | 12 | // Constants 13 | private const string DEFAULT_CATEGORY_NAME = "Default"; 14 | 15 | // Constructor 16 | public LambdaILogger(string categoryName, LambdaLoggerOptions options) 17 | { 18 | _categoryName = string.IsNullOrEmpty(categoryName) ? DEFAULT_CATEGORY_NAME : categoryName; 19 | _options = options; 20 | } 21 | 22 | // ILogger methods 23 | public IDisposable BeginScope(TState state) 24 | { 25 | // No support for scopes at this point 26 | // https://docs.asp.net/en/latest/fundamentals/logging.html#scopes 27 | return new NoOpDisposable(); 28 | } 29 | public bool IsEnabled(LogLevel logLevel) 30 | { 31 | return ( 32 | _options.Filter == null || 33 | _options.Filter(_categoryName, logLevel)); 34 | } 35 | public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) 36 | { 37 | if (formatter == null) 38 | { 39 | throw new ArgumentNullException(nameof(formatter)); 40 | } 41 | 42 | if (!IsEnabled(logLevel)) 43 | { 44 | return; 45 | } 46 | 47 | // Format of the logged text, optional components are in {} 48 | // {[LogLevel] }{Category: }MessageText{\n} 49 | 50 | var components = new List(4); 51 | if (_options.IncludeLogLevel) 52 | { 53 | components.Add($"[{logLevel}]"); 54 | } 55 | if (_options.IncludeCategory) 56 | { 57 | components.Add($"{_categoryName}:"); 58 | } 59 | 60 | var text = formatter.Invoke(state, exception); 61 | components.Add(text); 62 | 63 | if (_options.IncludeNewline) 64 | { 65 | components.Add(Environment.NewLine); 66 | } 67 | 68 | var finalText = string.Join(" ", components); 69 | Amazon.Lambda.Core.LambdaLogger.Log(finalText); 70 | } 71 | 72 | // Private classes 73 | private class NoOpDisposable : IDisposable 74 | { 75 | public void Dispose() 76 | { 77 | } 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda for .NET Core 2 | 3 | Repository for the AWS NuGet packages and Blueprints to support writing AWS Lambda functions using .NET Core. 4 | 5 | ## NuGet Packages 6 | 7 | # Events 8 | 9 | This packages in this folder contains classes that can be used as input types for Lambda functions that process various AWS events. 10 | 11 | These are the packages and their README.md files: 12 | 13 | [Amazon.Lambda.APIGatewayEvents](Libraries/Amazon.Lambda.APIGatewayEvents) - [README.md](Libraries/Amazon.Lambda.APIGatewayEvents/README.md) 14 | [Amazon.Lambda.CognitoEvents](Libraries/Amazon.Lambda.CognitoEvents) - [README.md](Libraries/Amazon.Lambda.CognitoEvents/README.md) 15 | [Amazon.Lambda.ConfigEvents](Libraries/Amazon.Lambda.ConfigEvents) - [README.md](Libraries/Amazon.Lambda.ConfigEvents/README.md) 16 | [Amazon.Lambda.DynamoDBEvents](Libraries/Amazon.Lambda.DynamoDBEvents) - [README.md](Libraries/Amazon.Lambda.DynamoDBEvents/README.md) 17 | [Amazon.Lambda.KinesisEvents](Libraries/Amazon.Lambda.KinesisEvents) - [README.md](Libraries/Amazon.Lambda.KinesisEvents/README.md) 18 | [Amazon.Lambda.S3Events](Libraries/Amazon.Lambda.S3Events) - [README.md](Libraries/Amazon.Lambda.S3Events/README.md) 19 | [Amazon.Lambda.SNSEvents](Libraries/Amazon.Lambda.SNSEvents) - [README.md](Libraries/Amazon.Lambda.SNSEvents/README.md) 20 | 21 | ### Amazon.Lambda.Tools 22 | 23 | Package adds commands to the dotnet cli that can be used manage Lambda functions including deploying a function from the dotnet cli. 24 | For more information see the [README.md](Libraries/Amazon.Lambda.Tools/README.md) file for Amazon.Lambda.Tools. 25 | 26 | ### Amazon.Lambda.AspNetCoreServer 27 | 28 | Packages makes it easy to run ASP.NET Core Web API applications as Lambda functions. 29 | For more information see the [README.md](Libraries/Amazon.Lambda.AspNetCoreServer/README.md) file for Amazon.Lambda.AspNetCoreServer. 30 | 31 | ### Amazon.Lambda.TestUtilities 32 | 33 | Package includes test implementation of the interfaces from Amazon.Lambda.Core and helper methods to help in locally testing. 34 | For more information see the [README.md](Libraries/Amazon.Lambda.TestUtilities/README.md) file for Amazon.Lambda.TestUtilities. 35 | 36 | ## Blueprints 37 | 38 | Blueprints in this repository are .NET Core Lambda functions that can used to get started. In Visual Studio the Blueprints are avalible when creating a new project and selecting the AWS Lambda Project. 39 | 40 | ### Yeoman 41 | For developers not using Visual Studio the Blueprints can be used with a Yeoman generator. To use Yeoman, Node.js and npm must be installed which can be obtain from [nodejs.org](https://nodejs.org/en/download/) 42 | 43 | Once npm is installed the Yeoman generator can be installed using the following command. 44 | ``` 45 | npm install -g yo generator-aws-lambda-dotnet 46 | ``` 47 | 48 | To run the generator and select a Blueprint run the following command. 49 | ``` 50 | yo aws-lambda-dotnet 51 | ``` -------------------------------------------------------------------------------- /Libraries/test/Amazon.Lambda.Tools.Test/ValidateHandlerTests.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | using Xunit; 8 | 9 | using Amazon.Lambda.Tools; 10 | using Amazon.Lambda.Tools.Commands; 11 | 12 | namespace Amazon.Lambda.Tools.Test 13 | { 14 | public class ValidateHandlerTests 15 | { 16 | string _testFunctionProjectLocation; 17 | 18 | public ValidateHandlerTests() 19 | { 20 | var debugVersion = new FileInfo(Path.Combine(Path.GetFullPath("../TestFunction"), "bin/Debug/netcoreapp1.0/TestFunction.dll")); 21 | var releaseVersion = new FileInfo(Path.Combine(Path.GetFullPath("../TestFunction"), "bin/Release/netcoreapp1.0/TestFunction.dll")); 22 | 23 | if (!debugVersion.Exists && !releaseVersion.Exists) 24 | throw new Exception("TestFunction wasn't compiled succesfully"); 25 | 26 | if (debugVersion.Exists && !releaseVersion.Exists) 27 | _testFunctionProjectLocation = debugVersion.DirectoryName; 28 | else if (!debugVersion.Exists && releaseVersion.Exists) 29 | _testFunctionProjectLocation = releaseVersion.DirectoryName; 30 | else if (debugVersion.LastWriteTime < releaseVersion.LastWriteTime) 31 | _testFunctionProjectLocation = releaseVersion.DirectoryName; 32 | else 33 | _testFunctionProjectLocation = debugVersion.DirectoryName; 34 | 35 | 36 | } 37 | 38 | [Fact] 39 | public void NoParameters() 40 | { 41 | Utilities.ValidateHandler(_testFunctionProjectLocation, "TestFunction::TestFunction.ValidateHandlerFunctionSignatures::NoParameters"); 42 | } 43 | 44 | [Fact] 45 | public void OneStringParameters() 46 | { 47 | Utilities.ValidateHandler(_testFunctionProjectLocation, "TestFunction::TestFunction.ValidateHandlerFunctionSignatures::OneStringParameters"); 48 | } 49 | 50 | [Fact] 51 | public void MethodDoesntExist() 52 | { 53 | Assert.Throws(typeof(ValidateHandlerException), 54 | () => Utilities.ValidateHandler(_testFunctionProjectLocation, "TestFunction::TestFunction.ValidateHandlerFunctionSignatures::YouShallNotPass")); 55 | } 56 | 57 | [Fact] 58 | public void TooManyParameters() 59 | { 60 | Assert.Throws(typeof(ValidateHandlerException), 61 | () => Utilities.ValidateHandler(_testFunctionProjectLocation, "TestFunction::TestFunction.ValidateHandlerFunctionSignatures::TooManyParameters")); 62 | } 63 | 64 | [Fact] 65 | public void InheritedMethod() 66 | { 67 | Utilities.ValidateHandler(_testFunctionProjectLocation, "TestFunction::TestFunction.ValidateHandlerFunctionSignatures::InheritedMethod"); 68 | } 69 | } 70 | } 71 | --------------------------------------------------------------------------------