- Newest
- Most votes
- Most comments
You're on the right track with your approach to running Haskell on AWS Lambda using a custom runtime, but there are a few adjustments you can make to improve your setup and ensure it works correctly.
To run a custom runtime on AWS Lambda:
-
Create a custom runtime: This involves creating an executable file named 'bootstrap' that can run your Haskell code. Your bootstrap script is a good start, but it needs to handle the Lambda runtime API.
-
Package your function: Include your Haskell executable and the bootstrap file in a .zip file.
-
Create a Lambda function: Use the 'provided' or 'provided.al2' runtime when creating your function in AWS Lambda.
-
Upload your package: Upload the .zip file as your function code.
Your current setup is close, but there are a few issues:
-
Runtime API: Your Haskell code isn't interacting with the Lambda Runtime API. It needs to handle getting invocations, processing them, and sending responses.
-
Error handling: The function is exiting without providing a proper response, causing the "Runtime exited without providing a reason" error.
-
Execution flow: The function seems to run twice, which suggests an issue with how it's handling invocations.
To improve your setup:
-
Modify your Haskell code to interact with the Lambda Runtime API. This involves making HTTP requests to the runtime API endpoints to get invocations and send responses.
-
Update your bootstrap script to properly handle the Lambda environment variables and pass them to your Haskell executable.
-
Ensure your Haskell code doesn't exit after processing a single request, but instead loops to handle multiple invocations.
-
Consider using a Haskell Lambda runtime library if available, as it can simplify the process of interacting with the Lambda environment.
For performance testing, this approach of using a custom runtime is appropriate. It allows you to run Haskell code on AWS Lambda in a way that's as close to a native runtime as possible without extensive modifications.
Remember to set the handler in your Lambda function configuration to match your bootstrap file (typically just "bootstrap" if it's in the root of your deployment package).
Your Dockerfile looks good for building the Haskell executable, but make sure you're including all necessary dependencies in the final image. The bootstrap file should be executable (which you've correctly set with chmod +x).
By making these adjustments, you should be able to successfully run and test your Haskell code on AWS Lambda using a custom runtime.
Sources
Building a custom runtime for AWS Lambda - AWS Lambda
Building Lambda functions with custom runtimes in AWS SAM - AWS Serverless Application Model
Choosing and managing runtimes in Lambda functions - AWS Lambda
Tutorial: Building a custom runtime - AWS Lambda
Relevant content
- asked 4 months ago
- asked 4 years ago
