python-3.x - 用于 s3 上传的 AWS lambda 函数 - Python 3.8
问题描述
我已经用 Python 为我的 Lambda 函数编写了一些代码。这应该从 url 获取 CSV 数据,并将其上传/放入同一 aws 帐户中的一个 s3 存储桶中。所有策略和 IAM 角色都已设置,但 lambda 仍然没有执行它的任务。代码如下。有人可以检查代码并让我知道错误。
from urllib.request import urlopen
import boto3
import os
import time
BUCKET_NAME = '***'
CSV_URL = 'http://***'
def lambda_handler(event, context):
response = urlopen(CSV_URL)
s3 = boto3.client('s3')
s3.upload_fileobj(response, BUCKET_NAME,time.strftime('%Y/%m/%d'))
response.close()
除了基本执行之外,我已将以下策略附加到我的 lambda 函数。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::**",
"arn:aws:s3:::*/*"
]
}
]
}
解决方案
推荐阅读
- postgresql - 使用分隔符作为双字节复制 Postgres 表
- reactjs - 在反应js中创建动态数量的组件
- java - 为什么 Java 中的 KeyPairGenerator 不能使用枚举(而不是抛出 NoSuchAlgorithm/Provider 异常)
- r - R:使用宽格式数据进行绘图
- javascript - 如果两个数组包含精确的文本值,则匹配 JSON
- sql-server - SQL Server:当第三个不同时,如何仅返回匹配 2 个字段的行
- ios - Swift 链接器错误:确定可用的 API 表示维度的未定义符号
- c# - SignalR:如果连接不活动,则无法调用“SendCoreAsync”方法
- entity-framework - EF Sum 分组后的嵌套列表值
- python - 无法弄清楚如何从我的结果中删除尾随空格