Read yaml file from s3 bucket path

Question:

Is there a way to read a yaml file that is located in a subfolder of a folder in an s3 bucket without iterating over the contents?
An example path for a yaml file would look like s3://bucket/folder/sub/file.yml.
There is a solution for yaml files in a bucket but without the option to access the subfolders

bucket = "bucket"
s3_client = boto3.client('s3')
response = s3_client.get_object(Bucket=bucket, Key="file.yml")
configfile = yaml.safe_load(response["Body"])
Asked By: Blob

||

Answers:

Unless I’m misunderstanding your question, you would just specify all the subfolders in the Key parameter:

response = s3_client.get_object(Bucket=bucket, Key="folder/sub/file.yml")
Answered By: Carlo Mencarelli
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.