-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
c3faea2
commit ceaefc5
Showing
21 changed files
with
808 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...s/Applications/AspNetCoreWebApiLambdaApplication/AspNetCoreWebApiLambdaApplication.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> | ||
<AWSProjectType>Lambda</AWSProjectType> | ||
<!-- This property makes the build directory similar to a publish directory and helps the AWS .NET Lambda Mock Test Tool find project dependencies. --> | ||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Amazon.Lambda.AspNetCoreServer" Version="9.0.0" /> | ||
<PackageReference Include="Amazon.Lambda.RuntimeSupport" Version="1.10.0" /> | ||
<PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.4.3" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\..\ApplicationHelperLibraries\ApplicationLifecycle\ApplicationLifecycle.csproj" /> | ||
</ItemGroup> | ||
</Project> |
48 changes: 48 additions & 0 deletions
48
...ationTests/Applications/AspNetCoreWebApiLambdaApplication/Controllers/ValuesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace AspNetCoreWebApiLambdaApplication.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ValuesController : ControllerBase | ||
{ | ||
public ValuesController() | ||
{ | ||
|
||
} | ||
|
||
// GET api/values | ||
[HttpGet] | ||
public IEnumerable<string> Get() | ||
{ | ||
return new string[] { "value1", "value2" }; | ||
} | ||
|
||
// GET api/values/5 | ||
[HttpGet("{id}")] | ||
public string Get(int id) | ||
{ | ||
return "value"; | ||
} | ||
|
||
// POST api/values | ||
[HttpPost] | ||
public void Post([FromBody] string value) | ||
{ | ||
} | ||
|
||
// PUT api/values/5 | ||
[HttpPut("{id}")] | ||
public void Put(int id, [FromBody] string value) | ||
{ | ||
} | ||
|
||
// DELETE api/values/5 | ||
[HttpDelete("{id}")] | ||
public void Delete(int id) | ||
{ | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...Agent/IntegrationTests/Applications/AspNetCoreWebApiLambdaApplication/LambdaEntryPoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
namespace AspNetCoreWebApiLambdaApplication | ||
{ | ||
public class APIGatewayProxyFunctionEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction | ||
{ | ||
protected override void Init(IWebHostBuilder builder) | ||
{ | ||
builder | ||
.UseStartup<Startup>(); | ||
} | ||
|
||
protected override void Init(IHostBuilder builder) | ||
{ | ||
} | ||
} | ||
|
||
public class ApplicationLoadBalancerFunctionEntryPoint :Amazon.Lambda.AspNetCoreServer.ApplicationLoadBalancerFunction | ||
{ | ||
protected override void Init(IWebHostBuilder builder) | ||
{ | ||
builder.UseStartup<Startup>(); | ||
} | ||
|
||
protected override void Init(IHostBuilder builder) | ||
{ | ||
} | ||
} | ||
|
||
public class APIGatewayHttpApiV2ProxyFunctionEntryPoint : Amazon.Lambda.AspNetCoreServer.APIGatewayHttpApiV2ProxyFunction | ||
{ | ||
protected override void Init(IWebHostBuilder builder) | ||
{ | ||
builder.UseStartup<Startup>(); | ||
} | ||
|
||
protected override void Init(IHostBuilder builder) | ||
{ | ||
} | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
tests/Agent/IntegrationTests/Applications/AspNetCoreWebApiLambdaApplication/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
using System.Diagnostics; | ||
using Amazon.Lambda.APIGatewayEvents; | ||
using Amazon.Lambda.ApplicationLoadBalancerEvents; | ||
using Amazon.Lambda.Core; | ||
using Amazon.Lambda.RuntimeSupport; | ||
using Amazon.Lambda.Serialization.SystemTextJson; | ||
using ApplicationLifecycle; | ||
using CommandLine; | ||
|
||
namespace AspNetCoreWebApiLambdaApplication | ||
{ | ||
internal class Program | ||
{ | ||
private class Options | ||
{ | ||
[Option("handler", Required = true, HelpText = "Handler function to use.")] | ||
public string Handler { get; set; } | ||
} | ||
|
||
private static string _port = ""; | ||
private static string _handlerToInvoke = ""; | ||
|
||
private static void Main(string[] args) | ||
{ | ||
_port = AppLifecycleManager.GetPortFromArgs(args); | ||
|
||
_handlerToInvoke = GetHandlerFromArgs(args); | ||
|
||
using var cancellationTokenSource = new CancellationTokenSource(); | ||
using var handlerWrapper = GetHandlerWrapper(); | ||
|
||
// Instantiate a LambdaBootstrap and run it. | ||
// It will wait for invocations from AWS Lambda and call the handler function for each one. | ||
using var bootstrap = new LambdaBootstrap(handlerWrapper); | ||
|
||
_ = bootstrap.RunAsync(cancellationTokenSource.Token); | ||
|
||
AppLifecycleManager.CreatePidFile(); | ||
|
||
AppLifecycleManager.WaitForTestCompletion(_port); | ||
|
||
cancellationTokenSource.Cancel(); | ||
} | ||
|
||
private static string GetHandlerFromArgs(string[] args) | ||
{ | ||
var handler = string.Empty; | ||
|
||
var commandLine = string.Join(" ", args); | ||
|
||
new Parser(with => { with.IgnoreUnknownArguments = true; }) | ||
.ParseArguments<Options>(args) | ||
.WithParsed(o => | ||
{ | ||
handler = o.Handler; | ||
}); | ||
|
||
if (string.IsNullOrEmpty(handler)) | ||
throw new Exception("--handler commandline argument could not be parsed."); | ||
|
||
return handler; | ||
} | ||
|
||
private static HandlerWrapper GetHandlerWrapper() | ||
{ | ||
var defaultLambdaJsonSerializer = new DefaultLambdaJsonSerializer(); | ||
|
||
switch (_handlerToInvoke) | ||
{ | ||
case "APIGatewayProxyFunctionEntryPoint": | ||
{ | ||
var entryPoint = new APIGatewayProxyFunctionEntryPoint(); | ||
Func<APIGatewayProxyRequest, ILambdaContext, Task<APIGatewayProxyResponse>> handlerFunc = entryPoint.FunctionHandlerAsync; | ||
|
||
return HandlerWrapper.GetHandlerWrapper(handlerFunc, defaultLambdaJsonSerializer); | ||
} | ||
case "ApplicationLoadBalancerFunctionEntryPoint": | ||
{ | ||
var entryPoint = new ApplicationLoadBalancerFunctionEntryPoint(); | ||
Func<ApplicationLoadBalancerRequest, ILambdaContext, Task<ApplicationLoadBalancerResponse>> handlerFunc = entryPoint.FunctionHandlerAsync; | ||
|
||
return HandlerWrapper.GetHandlerWrapper(handlerFunc, defaultLambdaJsonSerializer); | ||
} | ||
case "APIGatewayHttpApiV2ProxyFunctionEntryPoint": | ||
{ | ||
var entryPoint = new APIGatewayHttpApiV2ProxyFunctionEntryPoint(); | ||
Func<APIGatewayHttpApiV2ProxyRequest, ILambdaContext, Task<APIGatewayHttpApiV2ProxyResponse>> handlerFunc = entryPoint.FunctionHandlerAsync; | ||
|
||
return HandlerWrapper.GetHandlerWrapper(handlerFunc, defaultLambdaJsonSerializer); | ||
} | ||
default: | ||
throw new ArgumentException($"Handler not found: {_handlerToInvoke}"); | ||
} | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
tests/Agent/IntegrationTests/Applications/AspNetCoreWebApiLambdaApplication/Startup.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2020 New Relic, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
namespace AspNetCoreWebApiLambdaApplication | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
|
||
// This method gets called by the runtime. Use this method to add services to the container | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddControllers(); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline | ||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
|
||
//app.UseHttpsRedirection(); | ||
|
||
app.UseRouting(); | ||
|
||
//app.UseAuthorization(); | ||
|
||
app.UseEndpoints(endpoints => | ||
{ | ||
endpoints.MapControllers(); | ||
endpoints.MapGet("/", async context => | ||
{ | ||
await context.Response.WriteAsync("Welcome to running ASP.NET Core on AWS Lambda"); | ||
}); | ||
}); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...egrationTests/Applications/AspNetCoreWebApiLambdaApplication/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"AWS": { | ||
"Region": "" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/Agent/IntegrationTests/Applications/AspNetCoreWebApiLambdaApplication/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information" | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...rationTests/Applications/AspNetCoreWebApiLambdaApplication/aws-lambda-tools-defaults.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"Information": [ | ||
"This file provides default values for the deployment wizard inside Visual Studio and the AWS Lambda commands added to the .NET Core CLI.", | ||
"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.", | ||
"dotnet lambda help", | ||
"All the command line options for the Lambda command can be specified in this file." | ||
], | ||
"profile": "", | ||
"region": "", | ||
"configuration": "Release", | ||
"s3-prefix": "AspNetCoreWebApiLambdaApplication/", | ||
"template": "serverless.template", | ||
"template-parameters": "" | ||
} |
47 changes: 47 additions & 0 deletions
47
...Agent/IntegrationTests/Applications/AspNetCoreWebApiLambdaApplication/serverless.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Transform": "AWS::Serverless-2016-10-31", | ||
"Description": "An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.", | ||
"Parameters": {}, | ||
"Conditions": {}, | ||
"Resources": { | ||
"AspNetCoreFunction": { | ||
"Type": "AWS::Serverless::Function", | ||
"Properties": { | ||
"Handler": "AspNetCoreWebApiLambdaApplication::AspNetCoreWebApiLambdaApplication.APIGatewayHttpApiV2ProxyFunctionEntryPoint::FunctionHandlerAsync", | ||
"Runtime": "dotnet8", | ||
"CodeUri": "", | ||
"MemorySize": 512, | ||
"Timeout": 30, | ||
"Role": null, | ||
"Policies": [ | ||
"AWSLambda_FullAccess" | ||
], | ||
"Events": { | ||
"ProxyResource": { | ||
"Type": "Api", | ||
"Properties": { | ||
"Path": "/{proxy+}", | ||
"Method": "ANY" | ||
} | ||
}, | ||
"RootResource": { | ||
"Type": "Api", | ||
"Properties": { | ||
"Path": "/", | ||
"Method": "ANY" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"Outputs": { | ||
"ApiURL": { | ||
"Description": "API endpoint URL for Prod environment", | ||
"Value": { | ||
"Fn::Sub": "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.