is there a way to read a .ini configuration file from s3 without downloading it?
What I have tried:
config.ini:
[DEFAULT]
test = test1
test1 = test2
[ME]
me = you
you = he
code:
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()))
It returns [].
I have tried to make sure that
obj['Body'].read()
is returning well a binary with content of config.ini. This is working. It breaks somewhere further.
The read method of ConfigParser takes a file name, and yet you're passing it a file object.
You can instead use the read_string method so that you can pass to it the content returned by the read method of the StreamingBody object:
config.read_string(obj['Body'].read().decode())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With