簡體   English   中英

通過 Lambda 函數觸發 AWS Glue 工作流

[英]Triggering AWS Glue Workflow through Lambda function

我是 AWS GLUE 的新手,並嘗試使用 Lambda 函數觸發 Glue 工作流程。

我正在使用屬性boto3.client('glue')但我收到一條錯誤消息:

膠水對象沒有屬性start_workflow_run

這是我試圖運行的一段代碼:

import json
import boto3
def lambda_handler(event, context):
client = boto3.client('glue')
client.start_workflow_run(Name = 'Workflow_New', Arguments = {})

有沒有其他方法可以實現我想要做的事情?

請參閱此 SO,了解如何從 lambda 調用 AWS Glue,以及代碼片段。

如何通過 S3 事件或 AWS Lambda 觸發 Glue ETL Pyspark 作業?

import boto3
print('Loading function')

def lambda_handler(event, context):
    source_bucket = event['Records'][0]['s3']['bucket']['name']
    s3 = boto3.client('s3')
    glue = boto3.client('glue')
    gluejobname = "YOUR GLUE JOB NAME"

    try:
        runId = glue.start_job_run(JobName=gluejobname)
        status = glue.get_job_run(JobName=gluejobname, RunId=runId['JobRunId'])
        print("Job Status : ", status['JobRun']['JobRunState'])
    except Exception as e:
        print(e)
        print('Error getting object {} from bucket {}. Make sure they exist '
              'and your bucket is in the same region as this '
              'function.'.format(source_bucket, source_bucket))
    raise e

謝謝

尤瓦

這適用於從 Lambda (python) 調用膠水工作流

import json
import boto3
def lambda_handler(event, context):

    # add your region_name
    glue = boto3.client(service_name='glue', region_name='eu-west-2') 
    
    # only 'Name' parameter
    workflow_run_id = glue.start_workflow_run(Name = 'Your_Workflow')

    print(f'workflow_run_id: {workflow_run_id}')

https://docs.aws.amazon.com/glue/latest/dg/glue-dg.pdf AWS Glue 開發人員指南

請嘗試使用以下代碼片段:

import boto3

glueClient = boto3.client('glue')

response = glueClient.start_workflow_run(Name = 'wf_name')

您也可以使用此文檔: https : //boto3.amazonaws.com/v1/documentation/api/latest/reference/services/glue.html#Glue.Client.start_workflow_run

我不認為膠水具有名為“start_workflow_run”的函數。 請嘗試“start_job_run”

response = client.start_job_run(JobName = 'Workflow_New', Arguments = {} )

嘗試使用:

import json
import boto3

def lambda_handler(event, context):
    glueClient = boto3.client('glue', region_name='us-west-2')
    response = glueClient.start_workflow_run(Name=Workflow_name)

另外,我認為您可能還想在響應周圍添加錯誤處理!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM