@page "/runtime" @using Amazon.Lambda.TestTool.BlazorTester.Services @using Amazon.Lambda.TestTool.SampleRequests; @using Microsoft.AspNetCore.Http; @inject IHttpContextAccessor httpContextAccessor; @inject LocalLambdaOptions LambdaOptions @inject IRuntimeApiDataStore RuntimeApiModel @inject IModalService Modal

Test Executable Assembly

For Lambda functions written as executable assemblies, i.e. custom runtimes functions and top level statement functions, this page can be used for testing the functions locally. Set the AWS_LAMBDA_RUNTIME_API environment variable to @httpContextAccessor.HttpContext.Request.Host while debugging executable assembly Lambda function. More information can be found in the documentation.

Queue Event:

Active Event:

@if (RuntimeApiModel.ActiveEvent == null) {

No active event

} else {
@((MarkupString)REBOOT_ICON)

Request ID: @RuntimeApiModel.ActiveEvent.AwsRequestId

Status: @RuntimeApiModel.ActiveEvent.EventStatus

Last Updated: @RuntimeApiModel.ActiveEvent.LastUpdated

Event JSON:@CreateSnippet(RuntimeApiModel.ActiveEvent.EventJson)

@if (RuntimeApiModel.ActiveEvent.EventStatus == IEventContainer.Status.Failure) {

Error Type: @RuntimeApiModel.ActiveEvent.ErrorType

Error Response:

@RuntimeApiModel.ActiveEvent.ErrorResponse

} else {

Response:

@Amazon.Lambda.TestTool.Utils.TryPrettyPrintJson(RuntimeApiModel.ActiveEvent.Response)

}
}

Queued Events:

@foreach (var evnt in @RuntimeApiModel.QueuedEvents) {
Request ID:
@evnt.AwsRequestId
Last Updated:
@evnt.LastUpdated
@((MarkupString)CLOSE_ICON)
Event JSON:
@CreateSnippet(evnt.EventJson)
}

Executed Events:

@foreach (var evnt in @RuntimeApiModel.ExecutedEvents.OrderByDescending(x => x.LastUpdated)) {
@((MarkupString)REBOOT_ICON)
Request ID:
@evnt.AwsRequestId
Status:
@evnt.EventStatus
Last Updated:
@evnt.LastUpdated
@((MarkupString)CLOSE_ICON)
Event JSON:
@CreateSnippet(evnt.EventJson)
@if(evnt.EventStatus == IEventContainer.Status.Success) {
Response:
@CreateSnippet(evnt.Response)
} else if(evnt.EventStatus == IEventContainer.Status.Failure) {
Error Type:
@evnt.ErrorType
Error Response:
@CreateSnippet(evnt.ErrorResponse)
}
}
@code { private const string REBOOT_ICON = @" "; private const string CLOSE_ICON = @" "; private const string NO_SAMPLE_SELECTED_ID = "void-select-request"; private string FunctionInput { get; set; } private IDictionary> SampleRequests { get; set; } string _selectedSampleRequestName; string SelectedSampleRequestName { get => this._selectedSampleRequestName; set { this._selectedSampleRequestName = value; if(!string.Equals(value, NO_SAMPLE_SELECTED_ID)) { this.FunctionInput = SampleRequestManager.GetRequest(this._selectedSampleRequestName); } this.StateHasChanged(); } } SampleRequestManager SampleRequestManager { get; set; } protected override void OnInitialized() { RuntimeApiModel.StateChange += RuntimeApiModelOnStateChange; this.SampleRequestManager = new SampleRequestManager(LambdaOptions.GetPreferenceDirectory(false)); this.SampleRequests = SampleRequestManager.GetSampleRequests(); } private void RuntimeApiModelOnStateChange(object sender, EventArgs e) { this.InvokeAsync(this.StateHasChanged); } void OnAddEventClick() { RuntimeApiModel.QueueEvent(this.FunctionInput); this.FunctionInput = ""; this.SelectedSampleRequestName = NO_SAMPLE_SELECTED_ID; this.StateHasChanged(); } void OnClearQueued() { this.RuntimeApiModel.ClearQueued(); this.StateHasChanged(); } void OnClearExecuted() { this.RuntimeApiModel.ClearExecuted(); this.StateHasChanged(); } void OnRequeue(string awsRequestId) { IEventContainer evnt = null; if(string.Equals(this.RuntimeApiModel.ActiveEvent?.AwsRequestId, awsRequestId)) { evnt = this.RuntimeApiModel.ActiveEvent; } else { evnt = this.RuntimeApiModel.ExecutedEvents.FirstOrDefault(x => string.Equals(x.AwsRequestId, awsRequestId)); } if (evnt == null) return; this.RuntimeApiModel.QueueEvent(evnt.EventJson); this.StateHasChanged(); } void OnDeleteEvent(string awsRequestId) { this.RuntimeApiModel.DeleteEvent(awsRequestId); this.StateHasChanged(); } string GetStatusStyle(IEventContainer.Status status) => status switch { IEventContainer.Status.Success => "color:green", IEventContainer.Status.Failure => "color:red", _ => "color:black" }; string CreateSnippet(string fullString) { const int maxLength = 50; string trim; if (fullString?.Length < maxLength) { trim = fullString; } else { trim = fullString.Substring(0, maxLength); } return trim; } void ShowEventJson(IEventContainer evnt) { ShowExpandedText("Event JSON", evnt.EventJson); } void ShowResponse(IEventContainer evnt) { ShowExpandedText("Response", evnt.Response); } void ShowError(IEventContainer evnt) { ShowExpandedText("Error Response", evnt.ErrorResponse); } void ShowExpandedText(string title, string text) { var parameters = new ModalParameters(); parameters.Add(ExpandedTextDialog.PARAMETER_NAME_FULL_TEXT, text); Modal.Show(title, parameters); } }