How to install custom packages in Greengrass v2 lambda function

1

Hey there 👋,

I'm trying to put a simple .txt file from my lambda function to a s3 bucket. My GG core device is installed in a Raspberry Pi 4 64bit arm.

However, I'm facing some library issues while doing so. Below you can see the problem.

2023-10-01T05:15:11.388Z [INFO] (Copier) signal_processing_lambda: Startup script exited. {exitCode=0, serviceInstance=1, serviceName=signal_processing_lambda, currentState=STARTING} 2023-10-01T05:15:11.685Z [INFO] (pool-2-thread-86) signal_processing_lambda: lambda_runtime.py:402,Status thread started. {serviceInstance=1, serviceName=signal_processing_lambda, currentState=RUNNING} 2023-10-01T05:15:11.695Z [ERROR] (pool-2-thread-84) signal_processing_lambda: FATAL: lambda_runtime.py:146,Failed to import handler function "lambda_function.lambda_handler" due to exception: No module named 'boto3'. {serviceInstance=1, serviceName=signal_processing_lambda, currentState=RUNNING} 2023-10-01T05:15:11.698Z [ERROR] (pool-2-thread-84) signal_processing_lambda: FATAL: lambda_runtime.py:426,Failed to initialize Lambda runtime due to exception: No module named 'boto3'. {serviceInstance=1, serviceName=signal_processing_lambda, currentState=RUNNING} 2023-10-01T05:15:17.202Z [INFO] (pool-2-thread-82) signal_processing_lambda: shell-runner-start. {scriptName=services.signal_processing_lambda.lifecycle.shutdown.script, serviceInstance=1, serviceName=signal_processing_lambda, currentState=STOPPING, command=["/greengrass/v2/packages/artifacts/aws.greengrass.LambdaLauncher/2.0.11/lambda-..."]}

It seems that I have to install the boto3 library for doing so.

Therefore, my question is: How can I install custom packages in the lambda function running in the core device?

This is my lambda component configuration

{
    "lambdaArn": "arn:aws:lambda:eu-central-1:109139691401:function:lambda_greengrass:${lambda_function_version}",
    "componentName": "signal_processing_lambda",
    "componentVersion": "${lambda_component_version}",
    "componentLambdaParameters": {
        "eventSources": [
            {
                "topic": "thesis/v1/greengrass/lambda/exp1",
                "type": "IOT_CORE"
            }
        ],
        "maxQueueSize": 1000,
        "maxInstancesCount": 100,
        "maxIdleTimeInSeconds": 60,
        "timeoutInSeconds": 3,
        "statusTimeoutInSeconds": 60,
        "pinned": false,
        "inputPayloadEncodingType": "json",
        "linuxProcessParams": {
            "isolationMode": "NoContainer",
            "containerParams": {
                "memorySizeInKB": 16384,
                "mountROSysfs": false,
                "volumes": [],
                "devices": []
            }
        }
    }
}
Ed
gefragt vor 8 Monaten235 Aufrufe
1 Antwort
1

I just figured it out. For this I had to use two components, one for the dependencies and another one for the lambda function.

This is the component for the dependency of the function

{
    "RecipeFormatVersion": "2020-01-25",
    "ComponentName": "lambda_function_depedencies",
    "ComponentDescription": "Install Dependecies for Lambda Function",
    "ComponentPublisher": "Ed",
    "ComponentVersion": "1.0.0",
    "Manifests": [
        {
            "Lifecycle": {
                "install": "python3 -m pip install --user boto3"
            }
        }
    ]
}

This is the updated version of the lambda component

{
    "lambdaArn": "arn:aws:lambda:eu-central-1:109139691401:function:lambda_greengrass:${lambda_function_version}",
    "componentName": "signal_processing_lambda",
    "componentVersion": "${lambda_component_version}",
    "componentDependencies": {
        "lambda_function_depedencies": {
            "versionRequirement": "1.0.0",
            "dependencyType": "HARD"
        }
    },
    "componentLambdaParameters": {
        "eventSources": [
            {
                "topic": "thesis/v1/greengrass/lambda/exp1",
                "type": "IOT_CORE"
            }
        ],
        "maxQueueSize": 1000,
        "maxInstancesCount": 100,
        "maxIdleTimeInSeconds": 60,
        "timeoutInSeconds": 3,
        "statusTimeoutInSeconds": 60,
        "pinned": false,
        "inputPayloadEncodingType": "json",
        "linuxProcessParams": {
            "isolationMode": "NoContainer",
            "containerParams": {
                "memorySizeInKB": 16384,
                "mountROSysfs": false,
                "volumes": [],
                "devices": []
            }
        }
    }
}
Ed
beantwortet vor 8 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien fĂŒr die Beantwortung von Fragen