将文本文件加载到S3存储桶时,如何使用Lambda函数调用Glue函数(ETL) [英] How can I use a Lambda function to call a Glue function (ETL) when a text file is loaded to an S3 bucket

查看:200
本文介绍了将文本文件加载到S3存储桶时,如何使用Lambda函数调用Glue函数(ETL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个Lambda函数,以将.txt文件上传到S3存储桶时激活Glue函数,我正在使用python 3.7

I am trying to set up a lambda function that activates a Glue function when a .txt file is uploaded to an S3 bucket, I am using python 3.7

到目前为止,我有这个:

So far I have this:

from __future__ import print_function

import json
import boto3
import urllib

print('Loading function')

s3 = boto3.client('s3') 

def lambda_handler(event, context): # handler
    source_bucket = event['Records'][0]['s3']['bucket']['name']
    key = urllib.parse.quote_plus(event['Records'][0]['s3']['object']['key'].encode('utf8'))
    try:
        # what to put here
    except Exception as e:
        print(e)
        print('Error')
        raise e

但是我不明白如何调用胶水功能

But I don't understand how can I call the glue function

推荐答案

我设法做到这一点:

from __future__ import print_function
import json
import boto3

client = boto3.client('glue')

def lambda_handler(event, context):
    response = client.start_job_run(JobName = 'GLUE_CODE_NAME')

稍后我将发布S3事件

这篇关于将文本文件加载到S3存储桶时,如何使用Lambda函数调用Glue函数(ETL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆