【问题标题】:How to pass RunProperties while calling the glue workflow using boto3 and python in lambda function?如何在 lambda 函数中使用 boto3 和 python 调用胶水工作流时传递 RunProperties?
【发布时间】:2024-05-21 19:05:02
【问题描述】:

我在 lambda 函数中的 python 代码:

import json

import boto3

from botocore.exceptions import ClientError


glueClient = boto3.client('glue')

default_run_properties = {'s3_path': 's3://bucketname/abc.zip'}

response = glue_client.start_workflow_run(Name="Testing",RunProperties=default_run_properties)

print(response)

我收到这样的错误:

"errorMessage": "Parameter validation failed:\nUnknown parameter in input: \"RunProperties\", must be one of: Name",
  "errorType": "ParamValidationError",

我也试过这样:

session = boto3.session.Session()
glue_client = session.client('glue')

但是遇到了同样的错误。

任何人都可以告诉如何在调用胶水工作流运行时传递 RunProperties。RunProperties 是动态的,需要从 lambda 事件传递。

【问题讨论】:

    标签: python-3.x amazon-web-services aws-lambda aws-glue aws-glue-workflow


    【解决方案1】:

    我有同样的问题,这有点棘手。我不喜欢我的解决方案,所以也许其他人有更好的主意?见这里:https://github.com/boto/boto3/issues/2580 还有这里:https://docs.aws.amazon.com/glue/latest/webapi/API_StartWorkflowRun.html

    所以,你不能在启动工作流时传递参数,这在我看来是一种耻辱,因为即使是 CLI 也建议:https://docs.aws.amazon.com/cli/latest/reference/glue/start-workflow-run.html

    但是,您可以在开始工作流程之前更新参数。然后为每个人设置这些值。如果您期望任何“并发”问题,那么这不是一个好方法。您需要决定是在之后重置这些值还是将其留到工作流程的下一次开始。

    我这样开始我的工作流程:

    glue_client.update_workflow(
        Name=SHOPS_WORKFLOW_NAME,
        DefaultRunProperties={
            's3_key': file_key,
            'market_id': segments[0],
        },
    )
    
    workflow_run_id = glue_client.start_workflow_run(
        Name=SHOPS_WORKFLOW_NAME
    )
    

    这基本上会在下一次运行中产生以下结果:

    【讨论】: