Skip to content

Instantly share code, notes, and snippets.

@shiro01
Last active May 21, 2018 07:05
Show Gist options
  • Save shiro01/95ecb29598531bde6b8180468879513f to your computer and use it in GitHub Desktop.
Save shiro01/95ecb29598531bde6b8180468879513f to your computer and use it in GitHub Desktop.
s3_bucket_contents_list
import boto3
def lambda_handler(event, context):
AWS_S3_BUCKET_NAME = 'bucket_name'
s3_resource = boto3.resource('s3')
bucket = s3_resource.Bucket(AWS_S3_BUCKET_NAME)
result = bucket.meta.client.list_objects_v2(Bucket=bucket.name, Prefix='bucket_dir')
files = [o.get('Key') for o in result.get('Contents') if not o.get('Key').endswith('/')]
print(files)
return files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment