我试图使用python从Lambda函数更新Redshift.为此,我试图合并两个代码片段.当我单独运行它们时,两个片段都是有效的.
从PyDev for Eclipse更新Redshift
import psycopg2
conn_string = "dbname='name' port='0000' user='name' password='pwd' host='url'"
conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
cursor.execute("UPDATE table SET attribute='new'")
conn.commit()
cursor.close()
Run Code Online (Sandbox Code Playgroud)接收上载到S3存储桶的内容(Lambda上可用的预制模板)
from __future__ import print_function
import json
import urllib
import boto3
print('Loading function')
s3 = boto3.client('s3')
def lambda_handler(event, context):
#print("Received event: " + json.dumps(event, indent=2))
# Get the object from the event and show its content type
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.unquote_plus(event['Records'][0]['s3']['object']['key']).decode('utf8')
try:
response = s3.get_object(Bucket=bucket, Key=key)
print("CONTENT TYPE: " + response['ContentType'])
return response['ContentType'] …Run Code Online (Sandbox Code Playgroud)python amazon-web-services amazon-redshift aws-sdk aws-lambda
我的团队正在尝试使用Redshift合并来自多个不同数据库的信息。在我们首次尝试实现此解决方案的过程中,我们使用Kinesis Firehose将POST的记录写入到S3的API中,然后发出COPY命令将要插入的数据写入Redshift中的正确表中。但是,这仅允许我们插入新数据,而不允许我们转换数据,更改后更新行或删除行。
在不使用批处理转换的情况下,在Redshift中维护更新的数据仓库的最佳方法是什么?理想情况下,只要本地数据库中的数据发生更改,我们都希望更新能够“自动”(<5分钟)进行。
amazon-s3 amazon-web-services aws-sdk aws-lambda amazon-kinesis-firehose