Skip to content

Instantly share code, notes, and snippets.

@jastang
Last active March 12, 2018 20:17
Show Gist options
  • Save jastang/d9ed18bb7d72f0db32d28d5bcbc94d3c to your computer and use it in GitHub Desktop.
Save jastang/d9ed18bb7d72f0db32d28d5bcbc94d3c to your computer and use it in GitHub Desktop.
Reading a JSON configuration from S3
s3 = boto3.resource('s3')
conf = json.loads(s3.meta.client.get_object(Bucket=b, Key='my-config.json')['Body'].read(), object_pairs_hook=OrderedDict)
bucket = s3.Bucket(name=b)
# This is just metadata
src = bucket.objects.filter(Prefix='sftp')
# If we have N mandatory files, are most recent N uploads representative of the mandatory files?
mandatory_objects = [o.key for o in sorted(src, key=lambda x: x.last_modified, reverse=True)][:len(conf['mandatory_files'])]
# You can now validate whatever you want in mandatory_objects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment