如何使用 python 触发 aws lambda 的粘合作业?
How do I trigger a glue job with aws lambda using python?
假设我有一个胶水作业,名为:FirstGlueJob
如何在 python 中使用 lambda 函数触发它?
我们可以在着陆文件夹上配置一个 Lambda S3 事件触发器,当文件上传时,我们可以在 Lambda 中有一个简短的脚本来触发 Glue 作业。 glue python 脚本应该具有将输入文本文件转换为 CSV 文件所需的逻辑。这样,当一个文件上传到 S3 时,您的作业可以 运行 任意次数。
您的账单也只针对工作持续时间 运行。请注意,由于其托管服务功能,Glue 的成本并不高。
已创建事件触发器,触发粘合作业。请在此处找到 AWS Lambda 的代码片段:
from __future__ import print_function
import json
import boto3
import time
import sys
import time
from datetime import datetime
s3 = boto3.client('s3')
glue = boto3.client('glue')
def lambda_handler(event, context):
gluejobname="<< THE 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
假设我有一个胶水作业,名为:FirstGlueJob
如何在 python 中使用 lambda 函数触发它?
我们可以在着陆文件夹上配置一个 Lambda S3 事件触发器,当文件上传时,我们可以在 Lambda 中有一个简短的脚本来触发 Glue 作业。 glue python 脚本应该具有将输入文本文件转换为 CSV 文件所需的逻辑。这样,当一个文件上传到 S3 时,您的作业可以 运行 任意次数。
您的账单也只针对工作持续时间 运行。请注意,由于其托管服务功能,Glue 的成本并不高。
已创建事件触发器,触发粘合作业。请在此处找到 AWS Lambda 的代码片段:
from __future__ import print_function
import json
import boto3
import time
import sys
import time
from datetime import datetime
s3 = boto3.client('s3')
glue = boto3.client('glue')
def lambda_handler(event, context):
gluejobname="<< THE 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