问题标签 [botocore]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1436 浏览

python - 下载 S3 存储桶文件夹中的最新文件

我正在编写一个 Python 脚本来从 S3 Bucket 的文件夹中下载最新文件。我了解如何从我的 S3 存储桶下载最新的文件对象,但是我要下载的文件位于存储桶内的文件夹中。我完全不知道如何做以及可以在我的代码中添加它的位置。我尝试将路径放在存储桶链接的末尾,但这似乎不起作用。

0 投票
0 回答
478 浏览

amazon-s3 - s3 客户端 get_object(Range=byte_range) 无法检索对象的第一个字节

修复以下代码的所有变量都会返回异常“SignatureDoesNotMatch”,仅当它尝试返回早期字节范围(例如字节=0-1000)时。如果范围更高(例如字节=400000-500000),则不会发生异常

注意:该问题并非在所有环境中都可重现,但在我部署到的环境(Pivotal Cloud Foundry)上是一致的。

故障排除,我推测在计算签名时存在混淆boto3的环境因素。关于 boto3 - Pivotal Cloud Foundry 交互可能导致此异常的任何想法?

如果可能的话,您可以指出我可以理解 boto3 如何验证签名的方向。

例外

0 投票
1 回答
141 浏览

python - 即使使用正确的键,S3 boto 连接也会导致 ClientError

我正在运行一个命令:

我已确保两台 pc 上的键相同,但是,一台 pc 能够访问该对象,而另一台收到错误:

需要注意的是,我的实例的时区是 UTC 命令:

但是当我输入时,date我得到Fri Jan 4 09:05:44 UTC 2019 但是,谷歌将 utc 时间显示为:8:52 am Friday, 4 January 2019 Coordinated Universal Time (UTC)

0 投票
0 回答
450 浏览

python - Python Botocore 从数据文件夹中删除未使用的文件

我有一个在 OpenWrt 路由器 (Chaos Calmer) 上运行的 Python 应用程序,它使用 boto3 包来创建和更新 AWS IoT 事物影子。该应用程序使用自己的 Python 和依赖项(包括 boto3 和 botocore)打包。boto3 依赖于 botocore,它有一个数据文件夹,其中包含我的应用程序未使用的其他 AWS 服务(S3、dynamoDB、route53、lambda 等)的一堆 json 文件。在所有应用程序的资源中,此文件夹占用的空间最多。最终,我需要通过蜂窝网络对其中许多路由器进行 OTA 更新,这意味着数据使用是一个问题。因此,我想在不破坏代码的情况下从数据文件夹中删除尽可能多的未使用的 json 文件。

这些是我的应用程序使用的仅有的三个 boto3 和 botocore 导入:

如何确定可以删除哪些 json 文件?

更新 (1-8-19):我想出了如何解决这个问题。我没有删除一些看起来不相关的文件,然后运行应用程序以确保它没有损坏,然后删除更多文件等等,我做了相反的事情:删除所有文件,然后慢慢添加文件这看起来很相关,直到只剩下必要的文件。最后,数据文件夹从 ~35 Mb 变为 < 2 Mb(这对我的用例来说是一笔巨大的交易)

0 投票
0 回答
261 浏览

python - 我们应该关闭 botocore 的 StreamingBody 吗?

close()方法StreamingBody明确记载。但是,目前还不清楚我们是否应该在使用后主动关闭它。

在我见过的几个例子close()中,该方法从未被显式调用。

我担心/问题是,如果我们不明确关闭它,是否会有泄漏连接的风险。

0 投票
1 回答
1752 浏览

amazon-s3 - 调用 PutBucketAcl 操作时发生错误 (InvalidArgument):未知

调用 boto3.client 的 put_bucket_acl(**kwargs) 方法设置存储桶 acl 时出现此异常。(PS:它是一桶ceph对象而不是aws)


我的代码:

我也尝试 Session.client:

如果我删除参数 AccessControlPolicy,它运行成功

我是否以错误的方式调用此方法?但是该指南也以相同的方式调用此方法:https : //boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_bucket_acl 认为有任何帮助。

0 投票
1 回答
508 浏览

django - 带有 Django 的 Amazon SES 不在 UTC 时区

我正在开发一个用于美国的 django 项目,特别是纽约时区,系统托管在 AWS 上,SES 发送电子邮件。电子邮件后端使用django-anymail,它是 SES 的简单包装器,系统使用send_maildjango 核心。

为了支持这一点,我选择了以下 Django 设置;

使用上述设置 djangotzset()在启动时调用它会修改系统时区。这意味着用于签署 SES 请求的时间戳botocore不是 UTC,因为从消息发送中收到以下错误;

调用 SendRawEmail 操作时发生错误(ExpiredToken):请求中包含的安全令牌已过期

将设置更改为 即可成功发送电子邮件TIME_ZONE = 'UTC'

我只能假设请求是在 UTC -4 中签名的,然后到达 UTC 中的 AWS。

django 如何在特定时区运行,但 boto 使用 UTC 时间戳运行?

系统在 docker 容器中运行(预生产);

  • docker compose 3.4(unix主机)
  • 蟒蛇2.7
  • django 1.11
  • django-anymail 3.0
  • LocaleMiddleware已加载
0 投票
2 回答
2539 浏览

amazon-web-services - AWS boto3:UnknownServiceError:未知服务:'apigatewaymanagementapi'

我在 AWS 中遇到了 boto3 模块的奇怪问题。我正在使用 lambda 函数编写无服务器框架。我正在使用 aws boto3 模块并在 python 中运行以下代码。代码执行在本地运行时成功,但在 AWS 中执行时失败并出现 UnknownServiceError。

经过大量研究,我发现本地boto3版本是1.9.119,AWS boto3版本是1.9.42。我不太确定这是否是问题的根本原因。

我尝试在 venv 目标中安装 boto3 并使用该参考。无论如何,AWS 中的代码执行都会失败。

我检查了是否有方法可以更新 aws boto3 版本。

我还尝试在需求文件中添加 boto3 作为外部依赖项

我还尝试使用 boto3 zip 添加图层并映射到 lambda 函数。

不幸的是,没有一个解决方案有效。请为此问题提出替代解决方案。

0 投票
1 回答
775 浏览

python-3.x - Python AWS S3FS API:手动设置代理服务器

我无法为 S3FS Python API 设置代理服务器。由于 S3FS 的 Config 类是从 botocore 导入的,因此没有关于它的 S3FS 文档。所以,我已经阅读了这个问题以及botocore 文档

但是,我无法让 botocore Config 类与 S3FS 一起使用。

我努力了:

我也试过:

我也尝试为 http 设置相同的代理。代理在这台计算机上工作正常,我已经从命令行成功测试了几次。

我总是收到连接超时错误消息:

ConnectTimeoutError:端点 URL 上的连接超时:....

任何建议表示赞赏。谢谢

0 投票
1 回答
1890 浏览

python - Reading multiple "bulked" jsons from s3 asynchronously. Is there a better way?

The goal is to try to load a large amount of "bulked" jsons from s3. I found aiobotocore and felt urged to try in hope to get more efficiency and at the same time familiarise myself with asyncio. I gave it a shot, and it works but I know basically nada about asynchronous programming. Therefore, I was hoping for some improvements/comments. Maybe there are some kind souls out there that can spot some obvious mistakes.

The problem is that boto3 only supports one http request at a time. By utilising Threadpool I managed to get significant improvements, but I'm hoping for a more efficient way.

Here is the code:

Imports:

Some helper generator I found somewhere to return decoded jsons from string with multiple jsons.

This function gets keys from an s3 bucket with a given prefix:

This function gets the content for a provided key. Untop of that it flattens the list of decoded content:

Here is the main function which gathers the contents for all the found keys and flattens the list of contents.

Finally, I run this and the result list of dicts ends up nicely in result

  • One thing that I think might be a bit wierd is that I create a client in each async function. Probably that can be lifted out. Note sure about how aiobotocore works with multiple clients.

  • Furthermore, I think that you would not need to await that all keys are loaded before loading the objects for the keys, which I think is the case in this implementation. I'm assuming that as soon as a key is found you could call get_object. So, maybe it should be an async generator. But I'm not completely in the clear here.

Thank you in advance! Hope this helps someone in a similar situation.