Python configparser从S3读取配置而不下载

Arh*_*ina 3 python amazon-s3 configparser

有没有办法从 s3 读取 .ini 配置文件而不下载它?

我尝试过的:

配置.ini:

[DEFAULT]
test = test1
test1 = test2

[ME]
me = you
you = he
Run Code Online (Sandbox Code Playgroud)

代码:

import boto3
import io
import configparser

s3_boto = boto3.client('s3')
configuration_file_bucket = "mybucket"
configuration_file_key = "config.ini"
obj = s3_boto.get_object(Bucket=configuration_file_bucket, Key=configuration_file_key)

config = configparser.ConfigParser()
config.read(io.BytesIO(obj['Body'].read()))
Run Code Online (Sandbox Code Playgroud)

它返回[]。

我试图确保

obj['Body'].read()
Run Code Online (Sandbox Code Playgroud)

很好地返回了包含 config.ini 内容的二进制文件。这是有效的。它在更远的地方破裂了。

blh*_*ing 5

方法read接受ConfigParser一个文件名,但您向它传递一个文件对象。

您可以改为使用该方法,以便可以将对象的方法read_string返回的内容传递给它:readStreamingBody

config.read_string(obj['Body'].read().decode())
Run Code Online (Sandbox Code Playgroud)