-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathLambdaRuntimeSupportServer.cs
More file actions
219 lines (202 loc) · 8.78 KB
/
LambdaRuntimeSupportServer.cs
File metadata and controls
219 lines (202 loc) · 8.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
using Amazon.Lambda.AspNetCoreServer.Internal;
using Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.Extensions.DependencyInjection;
namespace Amazon.Lambda.AspNetCoreServer.Hosting.Internal
{
/// <summary>
/// Subclass of Amazon.Lambda.AspNetCoreServer.LambdaServer that also starts
/// up Amazon.Lambda.RuntimeSupport as part of the IServer startup.
///
/// This is an abstract class with subclasses for each of the possible Lambda event sources.
/// </summary>
public abstract class LambdaRuntimeSupportServer : LambdaServer
{
IServiceProvider _serviceProvider;
internal ILambdaSerializer Serializer;
/// <summary>
/// Creates an instance on the LambdaRuntimeSupportServer
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public LambdaRuntimeSupportServer(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
Serializer = serviceProvider.GetRequiredService<ILambdaSerializer>();
}
/// <summary>
/// Start Amazon.Lambda.RuntimeSupport to listen for Lambda events to be processed.
/// </summary>
/// <typeparam name="TContext"></typeparam>
/// <param name="application"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override Task StartAsync<TContext>(IHttpApplication<TContext> application, CancellationToken cancellationToken)
{
base.StartAsync(application, cancellationToken);
var handlerWrapper = CreateHandlerWrapper(_serviceProvider);
var bootStrap = new LambdaBootstrap(handlerWrapper);
return bootStrap.RunAsync();
}
/// <summary>
/// Abstract method that creates the HandlerWrapper that will be invoked for each Lambda event.
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
protected abstract HandlerWrapper CreateHandlerWrapper(IServiceProvider serviceProvider);
}
/// <summary>
/// IServer for handlying Lambda events from an API Gateway HTTP API.
/// </summary>
public class APIGatewayHttpApiV2LambdaRuntimeSupportServer : LambdaRuntimeSupportServer
{
/// <summary>
/// Create instances
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public APIGatewayHttpApiV2LambdaRuntimeSupportServer(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
/// <summary>
/// Creates HandlerWrapper for processing events from API Gateway HTTP API
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
protected override HandlerWrapper CreateHandlerWrapper(IServiceProvider serviceProvider)
{
var handler = new APIGatewayHttpApiV2MinimalApi(serviceProvider).FunctionHandlerAsync;
return HandlerWrapper.GetHandlerWrapper(handler, this.Serializer);
}
/// <summary>
/// Create the APIGatewayHttpApiV2ProxyFunction passing in the ASP.NET Core application's IServiceProvider
/// </summary>
public class APIGatewayHttpApiV2MinimalApi : APIGatewayHttpApiV2ProxyFunction
{
/// <summary>
/// Create instances
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public APIGatewayHttpApiV2MinimalApi(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
}
}
/// <summary>
/// IServer for handlying Lambda events from an API Gateway REST API.
/// </summary>
public class APIGatewayRestApiLambdaRuntimeSupportServer : LambdaRuntimeSupportServer
{
/// <summary>
/// Create instances
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public APIGatewayRestApiLambdaRuntimeSupportServer(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
/// <summary>
/// Creates HandlerWrapper for processing events from API Gateway REST API
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
protected override HandlerWrapper CreateHandlerWrapper(IServiceProvider serviceProvider)
{
var handler = new APIGatewayRestApiMinimalApi(serviceProvider).FunctionHandlerAsync;
return HandlerWrapper.GetHandlerWrapper(handler, this.Serializer);
}
/// <summary>
/// Create the APIGatewayProxyFunction passing in the ASP.NET Core application's IServiceProvider
/// </summary>
public class APIGatewayRestApiMinimalApi : APIGatewayProxyFunction
{
/// <summary>
/// Create instances
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public APIGatewayRestApiMinimalApi(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
}
}
/// <summary>
/// IServer for handlying Lambda events from an Application Load Balancer.
/// </summary>
public class ApplicationLoadBalancerLambdaRuntimeSupportServer : LambdaRuntimeSupportServer
{
/// <summary>
/// Create instances
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public ApplicationLoadBalancerLambdaRuntimeSupportServer(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
/// <summary>
/// Creates HandlerWrapper for processing events from API Gateway REST API
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
protected override HandlerWrapper CreateHandlerWrapper(IServiceProvider serviceProvider)
{
var handler = new ApplicationLoadBalancerMinimalApi(serviceProvider).FunctionHandlerAsync;
return HandlerWrapper.GetHandlerWrapper(handler, this.Serializer);
}
/// <summary>
/// Create the ApplicationLoadBalancerFunction passing in the ASP.NET Core application's IServiceProvider
/// </summary>
public class ApplicationLoadBalancerMinimalApi : ApplicationLoadBalancerFunction
{
/// <summary>
/// Create instances
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public ApplicationLoadBalancerMinimalApi(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
}
}
/// <summary>
/// IServer for handling Lambda events from Amazon Bedrock Agent API.
/// </summary>
public class BedrockAgentApiLambdaRuntimeSupportServer : LambdaRuntimeSupportServer
{
/// <summary>
/// Create instances
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public BedrockAgentApiLambdaRuntimeSupportServer(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
/// <summary>
/// Creates HandlerWrapper for processing events from Bedrock Agent API
/// </summary>
/// <param name="serviceProvider"></param>
/// <returns></returns>
protected override HandlerWrapper CreateHandlerWrapper(IServiceProvider serviceProvider)
{
var handler = new BedrockAgentApiMinimalApi(serviceProvider).FunctionHandlerAsync;
return HandlerWrapper.GetHandlerWrapper(handler, this.Serializer);
}
/// <summary>
/// Create the BedrockAgentApiFunction passing in the ASP.NET Core application's IServiceProvider
/// </summary>
public class BedrockAgentApiMinimalApi : BedrockAgentApiFunction
{
/// <summary>
/// Create instances
/// </summary>
/// <param name="serviceProvider">The IServiceProvider created for the ASP.NET Core application</param>
public BedrockAgentApiMinimalApi(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
}
}
}