How to run Stockfish on AWS Lambda

73 views Asked by At

I am trying to run stockfish on AWS lambda.

Here is my lambda function

    import os
import json
from stockfish import Stockfish

# The Stockfish binary is located at the root of your deployment package
stockfish_path = "/var/task/stockfish-ubuntu-x86-64-avx2"

def lambda_handler(event, context):
    stockfish = Stockfish(path=stockfish_path)

    # Set the chess position or FEN notation as needed
    position = "rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR w KQkq - 0 2"
    stockfish.set_fen_position(position)

    best_move = stockfish.get_best_move()

    response = {
        "best_move": best_move
    }

    return {
        "statusCode": 200,
        "body": json.dumps(response)
    }

In my root I also have this stockfish binary I downloaded from stockfish.com.

I have deployed it to AWS lambda, but when I run the lambda I get this error:

[ERROR] ValueError: invalid literal for int() with base 10: '/lib64/libm'
Traceback (most recent call last):
  File "/var/task/index.py", line 9, in lambda_handler
    stockfish = Stockfish(path=stockfish_path)
  File "/var/task/stockfish/models.py", line 57, in __init__
    self._stockfish_major_version: int = int(END RequestId: 304e4a19-2097-4770-92fa-8dc1bf9a680d

This is strange since it seems like an internal error with stockfish as opposed to something wrong with my code. I dont want to update the internal stockfish models that the error is referring to.

0

There are 0 answers