擅长:python、mysql、java
<p><strong>有一个使用AWS胶水的无服务器解决方案!</strong>(想清楚这一点,我差点就死了)</p>
<p><strong>此解决方案分为两部分:</strong></p>
<ol>
<li>一个lambda函数,在上载ZIP文件时由S3触发并创建GlueJobRun-将S3对象键作为参数传递给Glue。在</li>
<li>解压文件(内存中)的胶水作业并上传回S3。在</li>
</ol>
<p>请参阅下面我的代码,其中解压缩ZIP文件并将内容放回同一个bucket(可配置)。在</p>
<p>如有帮助,请投赞成票:)</p>
<p><strong>调用名为YourGlueJob的粘合作业的Lambda脚本(python3)</strong></p>
<pre><code>import boto3
import urllib.parse
glue = boto3.client('glue')
def lambda_handler(event, context):
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
print(key)
try:
newJobRun = glue.start_job_run(
JobName = 'YourGlueJob',
Arguments = {
' bucket':bucket,
' key':key,
}
)
print("Successfully created unzip job")
return key
except Exception as e:
print(e)
print('Error starting unzip job for' + key)
raise e
</code></pre>
<p>解压文件的AWS胶水作业脚本</p>
^{pr2}$