AWS Lambda 函数不使用 .DLL 引用转换文件

问题描述 投票:0回答:0

我一直在尝试使用我的 python 代码上的 .DLL 引用将新上传的文件转换为不同的格式。我使用的包是

pythonnet
,它允许我使用
clr
来引用我的 .DLL 文件(.DLL 文件有助于转换)。

我的 Lambda 函数是这样的 --

import boto3
import clr
import os
import tempfile

# Load the external .dll file
clr.AddReference("/RxLibrary.dll")
import RxLibrary

# Initialize S3 client
s3 = boto3.client('s3')

def lambda_handler(event, context):
    # Get bucket and object key from the event
    source_bucket = event['Records'][0]['s3']['bucket']['name']
    object_key = event['Records'][0]['s3']['object']['key']

    # Define the destination bucket
    destination_bucket = 'destination-bucket-name'

    # Download the source file to a temporary directory
    with tempfile.TemporaryDirectory() as temp_dir:
        input_file_path = os.path.join(temp_dir, 'input.rxd')
        output_file_path = os.path.join(temp_dir, 'output.mf4')

        s3.download_file(source_bucket, object_key, input_file_path)

        # Convert the input file using the provided code
        RxLibrary.RxLib.ConvertData(input_file_path, output_file_path)

        # Upload the converted file to the destination bucket
        s3.upload_file(output_file_path, destination_bucket, os.path.basename(output_file_path))

    return {
        'statusCode': 200,
        'body': f'Converted file {object_key} and uploaded to {destination_bucket}'
    }

AWS上的错误信息--

{
  "errorMessage": "Failed to create a default .NET runtime, which would\n                    have been \"mono\" on this system. Either install a\n                    compatible runtime or configure it explicitly via\n                    `set_runtime` or the `PYTHONNET_*` environment variables\n                    (see set_runtime_from_env).",
  "errorType": "RuntimeError",
  "requestId": "",
  "stackTrace": [
    "  File \"/var/lang/lib/python3.9/importlib/__init__.py\", line 127, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n",
    "  File \"<frozen importlib._bootstrap>\", line 1030, in _gcd_import\n",
    "  File \"<frozen importlib._bootstrap>\", line 1007, in _find_and_load\n",
    "  File \"<frozen importlib._bootstrap>\", line 986, in _find_and_load_unlocked\n",
    "  File \"<frozen importlib._bootstrap>\", line 680, in _load_unlocked\n",
    "  File \"<frozen importlib._bootstrap_external>\", line 850, in exec_module\n",
    "  File \"<frozen importlib._bootstrap>\", line 228, in _call_with_frames_removed\n",
    "  File \"/var/task/lambda_function.py\", line 2, in <module>\n    import clr\n",
    "  File \"/var/task/clr.py\", line 6, in <module>\n    load()\n",
    "  File \"/var/task/pythonnet/__init__.py\", line 131, in load\n    set_runtime_from_env()\n",
    "  File \"/var/task/pythonnet/__init__.py\", line 114, in set_runtime_from_env\n    runtime = _create_runtime_from_spec(spec)\n",
    "  File \"/var/task/pythonnet/__init__.py\", line 82, in _create_runtime_from_spec\n    raise RuntimeError(\n"
  ]
}

可见AWS无法使用.DLL进行转换。谁能帮帮我吗? 我在网上尝试了各种方法来纠正这个问题,但无法解决..

python .net amazon-web-services aws-lambda dll
© www.soinside.com 2019 - 2024. All rights reserved.