- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用表单将文件上传到 S3。该表单还有一些其他数据,虽然文件确实上传到存储桶,但我只是不明白如何获取其余数据以在 Lambda 函数中使用它来更新 RDS 实例中的 mysql 数据库。
这是我的表格(改编自 http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html )
<form name='form10' action="http://<?= $my_bucket ?>.s3.amazonaws.com/" method="post" enctype="multipart/form-data" onsubmit="return v.exec()">
<input type="hidden" name="key" value="videos/${filename}" />
<input type="hidden" name="acl" value="public-read" />
<input type="hidden" name="X-Amz-Credential" value="<?= $access_key; ?>/<?= $short_date; ?>/<?= $region; ?>/s3/aws4_request" />
<input type="hidden" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256" />
<input type="hidden" name="X-Amz-Date" value="<?=$iso_date ; ?>" />
<input type="hidden" name="Policy" value="<?=base64_encode($policy); ?>" />
<input type="hidden" name="X-Amz-Signature" value="<?=$signature ?>" />
<input type="hidden" name="success_action_redirect" value="<?= $success_redirect ?>" />
<table summary="Playlist de Campaña" align=center border="1">
<tr><td colspan="2" align="center">Agregar Videos a Playlist</td></tr>
<tr><td>Selecciona tu Archivo:</td><td><input type="file" name="file" /></td></tr>
<tr><td>Descripción del Video</td><td><input type="text" name="desc_video" value="" size="50"/></td></tr>
<tr><td>Fecha Inicio:
<input type=text name=start_date value="<?PHP echo $fecha_inicio; ?>"><a href="javascript:show_calendar('form10.start_date');" ><img src="images/show-calendar.gif" width="24" height="22" border="0" alt=""></a>
</td><td>Fecha Terminación
<input type=text name=end_date value="<?PHP echo $fecha_termina;?>"><a href="javascript:show_calendar('form10.end_date');" ><img src="images/show-calendar.gif" width="24" height="22" border="0" alt=""></a>
</td></tr>
<tr><td>Hora Inicio:
<select name="hora_inicio">
<?PHP
for ($hr = 0; $hr < 24; $hr++){
echo"<option value=$hr>$hr</option>";
}
?>
</select>:
<select name="mins_inicio">
<?PHP
for ($hr = 0; $hr < 60; $hr+=5){
echo"<option value=$hr>$hr</option>";
}
?>
<option value="59">59</option>
</select></td>
<td>Hora Terminación:
<select name="hora_final">
<?PHP
for ($hr = 0; $hr < 24; $hr++){
if($hr<>23){
echo"<option value=$hr>$hr</option>";
} else {
echo"<option value=$hr selected>$hr</option>";
}
}
?>
</select>:
<select name="mins_final">
<?PHP
for ($hr = 0; $hr < 60; $hr+=5){
echo"<option value=$hr>$hr</option>";
}
?>
<option value="59" selected>59</option>
</select></td>
</tr>
<tr><td colspan="2" align="center"><input type="submit" value="Continuar" /></td></tr>
</table>
<input type="hidden" name="step" value="sube" />
<input type="hidden" name="tipo" value="<?PHP echo $tipo; ?>" />
<input type="hidden" name="id_campana" value="<?PHP echo $id_campana; ?>" />
<input type="hidden" name="fecha_inicio" value="<?PHP echo $fecha_inicio; ?>" />
<input type="hidden" name="fecha_termina" value="<?PHP echo $fecha_termina; ?>" />
</form>
如您所见,我有一堆变量需要保存到我的数据库中,但我只是不知道如何在 Lambda 函数中调用它们。 Lambda 函数可以写入数据库。我有一个能够写入数据库的硬编码 sql 语句,当 S3 存储桶接收到文件时它会自行触发。这是我正在使用的 lambda 函数,(改编自:https://www.isc.upenn.edu/accessing-mysql-databases-aws-python-lambda-function)
import sys
import logging
import rds_config
import pymysql
#rds settings
rds_host = "xxxxxxxxxxxxxxxxxxxx.rds.amazonaws.com"
name = rds_config.db_username
password = rds_config.db_password
db_name = rds_config.db_name
logger = logging.getLogger()
logger.setLevel(logging.INFO)
try:
conn = pymysql.connect(rds_host, user=name, passwd=password, db=db_name, connect_timeout=5)
except:
logger.error("ERROR: Unexpected error: Could not connect to MySql instance.")
sys.exit()
logger.info("SUCCESS: Connection to RDS mysql instance succeeded")
def lambda_handler(event, context):
try:
cur = conn.cursor()
cur.execute("INSERT INTO archivos (id_cliente,id_campana,tipo_asset,id_tipo_asset,file_name,original_name,descripcion,file_type,date_begin,date_end,time_begin,time_end,MD5) VALUES (5,11,'Marca',3,'test.png','test.png','este es el video','png','2017-08-01','2017-08-30','00:00:00','23:59:00','90175908345798dhf')")
conn.commit()
except MySQLError as e:
logger.error(e)
return None
关于如何实现此目标的任何想法?我敢肯定这真的很愚蠢,但我已经尝试了好几天了,但我似乎无法理解它。
最佳答案
将所有内容成功上传到 S3 后,您可以创建从 S3 到 Lambda 的触发器。该事件包含有关上传的 S3 对象的所有信息。
你也可以读取S3对象,提取你想要的字段存储到RDS。
以下是为 Lambda 创建 S3 触发器的文档。
http://docs.aws.amazon.com/lambda/latest/dg/with-s3.html
您还可以根据新帖子、更新或删除自定义触发器。
希望这对您有所帮助。
关于python - 使用lambda python将文件上传到s3后用表单数据更新mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45665388/
我有一台 MySQL 服务器和一台 PostgreSQL 服务器。 需要从多个表中复制或重新插入一组数据 MySQL 流式传输/同步到 PostgreSQL 表。 这种复制可以基于时间(Sync)或事
如果两个表的 id 彼此相等,我尝试从一个表中获取数据。这是我使用的代码: SELECT id_to , email_to , name_to , status_to
我有一个 Excel 工作表。顶行对应于列名称,而连续的行每行代表一个条目。 如何将此 Excel 工作表转换为 SQL 表? 我使用的是 SQL Server 2005。 最佳答案 这取决于您使用哪
我想合并两个 Django 模型并创建一个模型。让我们假设我有第一个表表 A,其中包含一些列和数据。 Table A -------------- col1 col2 col3 col
我有两个表:table1,table2,如下所示 table1: id name 1 tamil 2 english 3 maths 4 science table2: p
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 1 年前。 Improve th
下面两个语句有什么区别? newTable = orginalTable 或 newTable.data(originalTable) 我怀疑 .data() 方法具有性能优势,因为它在标准 AX 中
我有一个表,我没有在其中显式定义主键,它并不是真正需要的功能......但是一位同事建议我添加一个列作为唯一主键以随着数据库的增长提高性能...... 谁能解释一下这是如何提高性能的? 没有使用索引(
如何将表“产品”中的产品记录与其不同表“图像”中的图像相关联? 我正在对产品 ID 使用自动增量。 我觉得不可能进行关联,因为产品 ID 是自动递增的,因此在插入期间不可用! 如何插入新产品,获取产品
我有一个 sql 表,其中包含关键字和出现次数,如下所示(尽管出现次数并不重要): ____________ dog | 3 | ____________ rat | 7 | ____
是否可以使用目标表中的LAST_INSERT_ID更新源表? INSERT INTO `target` SELECT `a`, `b` FROM `source` 目标表有一个自动增量键id,我想将其
我正在重建一个搜索查询,因为它在“我看到的”中变得多余,我想知道什么 (albums_artists, artists) ( ) does in join? is it for boosting pe
以下是我使用 mysqldump 备份数据库的开关: /usr/bin/mysqldump -u **** --password=**** --single-transaction --databas
我试图获取 MySQL 表中的所有行并将它们放入 HTML 表中: Exam ID Status Assigned Examiner
如何查询名为 photos 的表中的所有记录,并知道当前用户使用单个查询将哪些结果照片添加为书签? 这是我的表格: -- -- Table structure for table `photos` -
我的网站都在 InnoDB 表上运行,目前为止运行良好。现在我想知道在我的网站上实时发生了什么,所以我将每个页面浏览量(页面、引荐来源网址、IP、主机名等)存储在 InnoDB 表中。每秒大约有 10
我在想我会为 mysql 准备两个表。一个用于存储登录信息,另一个用于存储送货地址。这是传统方式还是所有内容都存储在一张表中? 对于两个表...有没有办法自动将表 A 的列复制到表 B,以便我可以引用
我不是程序员,我从这个表格中阅读了很多关于如何解决我的问题的内容,但我的搜索效果不好 我有两张 table 表 1:成员 id*| name | surname -------------------
我知道如何在 ASP.NET 中显示真实表,例如 public ActionResult Index() { var s = db.StaffInfoDBSet.ToList(); r
我正在尝试运行以下查询: "insert into visits set source = 'http://google.com' and country = 'en' and ref = '1234
我是一名优秀的程序员,十分优秀!