Class ALambdaApiGatewayFunction
ALambda
Implements
Inherited Members
Namespace: LambdaSharp.ApiGateway
Assembly: LambdaSharp.ApiGateway.dll
Syntax
public abstract class ALambdaApiGatewayFunction : ALambdaFunction, ILambdaSharpLogger
Remarks
If the Lambda function was configured for REST API or WebSocket routes with method invocations, then the
Lambda function will act as a controller and route the incoming requests to the specified methods. Alternatively,
a derived class can override Process
Constructors
ALambdaApiGatewayFunction(ILambdaJsonSerializer)
Initializes a new ALambda
Declaration
protected ALambdaApiGatewayFunction(ILambdaJsonSerializer serializer)
Parameters
Type | Name | Description |
---|---|---|
ILambda |
serializer | Custom implementation of ILambda |
ALambdaApiGatewayFunction(ILambdaJsonSerializer, ILambdaFunctionDependencyProvider)
Initializes a new ALambda
Declaration
protected ALambdaApiGatewayFunction(ILambdaJsonSerializer serializer, ILambdaFunctionDependencyProvider provider)
Parameters
Type | Name | Description |
---|---|---|
ILambda |
serializer | Custom implementation of ILambda |
ILambda |
provider | Custom implementation of ILambda |
Properties
CurrentRequest
Retrieve the current Amazon.
Declaration
protected APIGatewayProxyRequest CurrentRequest { get; }
Property Value
Type | Description |
---|---|
Amazon. |
The Amazon. |
Remarks
This property is only set during the invocation of Processnull
.
LambdaSerializer
An instance of ILambda
Declaration
protected ILambdaJsonSerializer LambdaSerializer { get; }
Property Value
Type | Description |
---|---|
ILambda |
The ILambda |
Methods
Abort(APIGatewayProxyResponse)
The Abort(APIGateway
Declaration
protected virtual Exception Abort(APIGatewayProxyResponse response)
Parameters
Type | Name | Description |
---|---|---|
Amazon. |
response | The Amazon. |
Returns
Type | Description |
---|---|
System. |
Nothing. See remarks. |
Remarks
This method never returns as the abort exception is thrown immediately. The System.
Examples
throw Abort(new APIGatewayProxyResponse {
StatusCode = 404,
Body = "item not found"
});
AbortBadRequest(String)
The Abort400 - Bad Request
response.
Declaration
protected virtual Exception AbortBadRequest(string message)
Parameters
Type | Name | Description |
---|---|---|
System. |
message | The response message. |
Returns
Type | Description |
---|---|
System. |
Nothing. See remarks. |
Remarks
This method never returns as the abort exception is thrown immediately. The System.
Examples
throw AbortBadRequest("invalid selection");
AbortForbidden(String)
The Abort403 - Forbidden
response.
Declaration
protected virtual Exception AbortForbidden(string message)
Parameters
Type | Name | Description |
---|---|---|
System. |
message | The response message. |
Returns
Type | Description |
---|---|
System. |
Nothing. See remarks. |
Remarks
This method never returns as the abort exception is thrown immediately. The System.
Examples
throw AbortForbidden("you are not authorized");
AbortNotFound(String)
The Abort404 - Not Found
response.
Declaration
protected virtual Exception AbortNotFound(string message)
Parameters
Type | Name | Description |
---|---|---|
System. |
message | The response message. |
Returns
Type | Description |
---|---|
System. |
Nothing. See remarks. |
Remarks
This method never returns as the abort exception is thrown immediately. The System.
Examples
throw AbortNotFound("item not found");
CreateBadParameterResponse(APIGatewayProxyRequest, String, String)
The Create400 - Bad Request
error, because
a request parameter was invalid or missing.
Declaration
protected virtual APIGatewayProxyResponse CreateBadParameterResponse(APIGatewayProxyRequest request, string parameterName, string message)
Parameters
Type | Name | Description |
---|---|---|
Amazon. |
request | The Amazon. |
System. |
parameterName | The name of the parameter. |
System. |
message | The error message. |
Returns
Type | Description |
---|---|
Amazon. |
The Amazon. |
CreateInvocationExceptionResponse(APIGatewayProxyRequest, Exception)
The Create500 - Internal Server Error
error, because
an unhandled exception occurred during the request processing.
Declaration
protected virtual APIGatewayProxyResponse CreateInvocationExceptionResponse(APIGatewayProxyRequest request, Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Amazon. |
request | The Amazon. |
System. |
exception | The raised exception. |
Returns
Type | Description |
---|---|
Amazon. |
The Amazon. |
CreateInvocationTargetInstance(Type)
The Create
Declaration
public virtual object CreateInvocationTargetInstance(Type type)
Parameters
Type | Name | Description |
---|---|---|
System. |
type | The requested type to instantiate. |
Returns
Type | Description |
---|---|
System. |
The instance for the target method. |
Remarks
If the requested type is the type of the Lambda function, this method returns the Lambda function instance. Otherwise, it attempts to instantiate the requested type using that Lambda function instance as the sole the constructor parmeter. This pattern allows the Lambda function to be the Dependency Provider for the created instance.
CreateResponse(Int32, String)
The Create
Declaration
protected virtual APIGatewayProxyResponse CreateResponse(int statusCode, string message)
Parameters
Type | Name | Description |
---|---|---|
System. |
statusCode | The HTTP status code of the response. |
System. |
message | The response mesage. |
Returns
Type | Description |
---|---|
Amazon. |
The Amazon. |
Examples
For a REST API route, the response body looks as follows.
{
"message": "item not found",
"requestId": "123abc"
}
For a WebSocket route, the response body contains in addition the connection ID.
{
"message": "item not found",
"requestId": "123abc",
"connectionId": "456def"
}
CreateRouteNotFoundResponse(APIGatewayProxyRequest, String)
The Create404 - Not Found
error for the requested
REST API or WebSocket route.
Declaration
protected virtual APIGatewayProxyResponse CreateRouteNotFoundResponse(APIGatewayProxyRequest request, string route)
Parameters
Type | Name | Description |
---|---|---|
Amazon. |
request | The Amazon. |
System. |
route | The REST API or WebSocket route that could not be found. |
Returns
Type | Description |
---|---|
Amazon. |
The Amazon. |
InitializeEpilogueAsync()
The Initialize
Declaration
protected override async Task InitializeEpilogueAsync()
Returns
Type | Description |
---|---|
System. |
The task object representing the asynchronous operation. |
Overrides
InitializePrologueAsync(ILambdaConfigSource)
The Initialize
Declaration
protected override async Task InitializePrologueAsync(ILambdaConfigSource envSource)
Parameters
Type | Name | Description |
---|---|---|
ILambda |
envSource | The ILambda |
Returns
Type | Description |
---|---|
System. |
The task object representing the asynchronous operation. |
Overrides
ProcessMessageAsync(APIGatewayProxyRequest)
The Process
Declaration
public async Task<APIGatewayProxyResponse> ProcessMessageAsync(APIGatewayProxyRequest request)
Parameters
Type | Name | Description |
---|---|---|
Amazon. |
request | The Amazon. |
Returns
Type | Description |
---|---|
System. |
The task object representing the asynchronous operation. |
ProcessMessageStreamAsync(Stream)
The Process
Declaration
public sealed override async Task<Stream> ProcessMessageStreamAsync(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
System. |
stream | The stream with the request payload. |
Returns
Type | Description |
---|---|
System. |
The task object representing the asynchronous operation. |
Overrides
Remarks
This method is sealed
and cannot be overridden.
ProcessProxyRequestAsync(APIGatewayProxyRequest)
The Process
Declaration
public virtual Task<APIGatewayProxyResponse> ProcessProxyRequestAsync(APIGatewayProxyRequest request)
Parameters
Type | Name | Description |
---|---|---|
Amazon. |
request | The Amazon. |
Returns
Type | Description |
---|---|
System. |
The task object representing the asynchronous operation. |
Remarks
The default implementation response with a 404 error.