Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

check if file exists on s3 python

import boto3

def get_resource(config: dict={}):
    """Loads the s3 resource.

    Expects AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to be in the environment
    or in a config dictionary.
    Looks in the environment first."""

    s3 = boto3.resource('s3',
                        aws_access_key_id=os.environ.get(
                            "AWS_ACCESS_KEY_ID", config.get("AWS_ACCESS_KEY_ID")),
                        aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", config.get("AWS_SECRET_ACCESS_KEY")))
    return s3


def get_bucket(s3, s3_uri: str):
    """Get the bucket from the resource.
    A thin wrapper, use with caution.

    Example usage:

    >> bucket = get_bucket(get_resource(), s3_uri_prod)"""
    return s3.Bucket(s3_uri)


def isfile_s3(bucket, key: str) -> bool:
    """Returns T/F whether the file exists."""
    objs = list(bucket.objects.filter(Prefix=key))
    return len(objs) == 1 and objs[0].key == key


def isdir_s3(bucket, key: str) -> bool:
    """Returns T/F whether the directory exists."""
    objs = list(bucket.objects.filter(Prefix=key))
    return len(objs) > 1
Comment

PREVIOUS NEXT
Code Example
Typescript :: pass function as argument typescript 
Typescript :: typescript type definition 
Typescript :: listobjects vba 
Typescript :: typescript null and undefined check 
Typescript :: typescript object key as enum 
Typescript :: Angular import from local library 
Typescript :: filter() array of objects on change react 
Typescript :: array in typescript 
Typescript :: typescript open site in frame 
Typescript :: gamemanager unity resets after reloading scene 
Typescript :: watch ref.current changes typescript 
Typescript :: how to Write a program that accepts three decimal numbers as input and outputs their sum on python 
Typescript :: react tailwind css components npm 
Typescript :: latest unity version that supports 32 bit 
Typescript :: outside click hook react 
Typescript :: typescript one of array 
Typescript :: paragraph dots after 2 lines css 
Typescript :: mailbox exists c# 
Typescript :: conventional commits cheat sheet 
Typescript :: Interface with custom property name type 
Typescript :: angular images 
Typescript :: ts builder pattern 
Typescript :: grid implementation html canvas 
Typescript :: Scroll, Position 
Typescript :: 8.1.3. Varying Data Types¶ Arrays 
Typescript :: Angular Compiler Options to enable AOT compilation 
Typescript :: basic of angular typescript 
Typescript :: c# ienumerable wrap to know when its compltee 
Typescript :: when 2 emits on a same chatroom at a time only one is working using socket.io 
Typescript :: How to loop the jquery formData key object in jqueyr 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =