If you don't know AWS Lambda is a "serverless" code execution environment in which code runs in response to events. You only pay for runtime and the first 1,000,000 a month are free so for small code it's practically free.
Anyway, last week AWS announced that you could now bring any language to Lambda with custom runtimes, so I've made a prototype for FPC code. Check it out, if you're interested:
github:
https://github.com/macmike/fpc-lambdablog:
https://mikemacd.wordpress.com/2018/12/03/building-a-custom-lambda-runtime-for-anything-even-pascal-yes-lambda-reinvent-aws/twitter announcement:
https://twitter.com/mikemacd/status/1069655731773812741Basically this means you can write code to respond to JSON events like so (function.pas):
uses
fpjson, jsonparser, sysutils;
var
lambdaEventData: TJSONData;
lambdaEvent: TJSONObject;
nameParameter, outputJSON: string;
begin
//get incoming JSON and parse
lambdaEventData := GetJSON(ParamStr(1));
// cast as TJSONObject to make access easier
lambdaEvent := TJSONObject(lambdaEventData);
nameParameter := lambdaEvent.Get('name');
outputJSON := format('{"status":"200", "message":"hello %s from fpc lambda"}',[nameParameter]);
WriteLn(outputJSON);
end.
and then create it as a lambda function by doing the following:
zip function.zip ./function.pas
aws lambda create-function --function-name fpc-lambda-event --zip-file fileb://function.zip --handler function.handler --runtime provided --layers arn:aws:lambda:eu-west-1:743697633610:layer:fpc-runtime:20 --role arn:aws:iam::<your-id>:role/lambda-role --timeout 10
You can then invoke from the command line, trigger from a https endpoint (api gateway), an AWS service, or the web console:
aws lambda invoke --function-name fpc-lambda-event --payload '{"name":"Mike"}' response.txt
cat response.txt
// result:
{"status":"200", "message":"hello Mike from fpc lambda"}