tools/athena/loadtoathena.py
def create_s3_bucket(dryrun: bool, bucket_name: str, bucket_region: str) -> None:
    """
    Create a bucket.
    If the bucket already exists and you have access to it, no bucket will be created.

    https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Bucket.create
    """

    logger.info("creating bucket %s in region %s", bucket_name, bucket_region)

    if dryrun:
        logger.info("in dry run mode.. not running!")
        return

    response = ""

    # check if the bucket exists and we have access to it or None.
    try:
        # To create bucket in the specified region
        s3client = boto3.client("s3", region_name=bucket_region)
        response = s3client.head_bucket(Bucket=bucket_name)
        logger.info("bucket exists.. not creating")

    except ClientError as err:
        logger.info("lookup on bucket failed with error: %s", err)
        logger.info("bucket doesn't exist, creating...")

        # Let's try to create the bucket. This will fail if
        # the bucket has already been created by someone else.
        try:

            if bucket_region == "us-east-1":
                response = s3client.create_bucket(
                    Bucket=bucket_name, ACL="private")
            else:
                response = s3client.create_bucket(
                    Bucket=bucket_name,
                    ACL="private",
                    CreateBucketConfiguration={
                        "LocationConstraint": bucket_region},
                )
            logger.info(
                "Response Code: %s", response["ResponseMetadata"]["HTTPStatusCode"]
            )

        except ClientError as err:
            logger.warning("failed creating bucket...")
            logger.warning(err)
            raise

    if response:
        logger.debug("response...\n%s", json.dumps(response, indent=2))

    Create a bucket.
    If the bucket already exists and you have access to it, no bucket will be created.

    https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Bucket.create
    
Create a bucket.
If the bucket already exists and you have access to it, no bucket will be created.


Create a bucket . If the bucket already exists and you have access to it no bucket will be created .
def create_s3_bucket(dryrun: bool, bucket_name: str, bucket_region: str) -> None:
    logger.info("creating bucket %s in region %s", bucket_name, bucket_region)
    if dryrun:
        logger.info("in dry run mode.. not running!")
        return
    response = ""
    try:
        s3client = boto3.client("s3", region_name=bucket_region)
        response = s3client.head_bucket(Bucket=bucket_name)
        logger.info("bucket exists.. not creating")
    except ClientError as err:
        logger.info("lookup on bucket failed with error: %s", err)
        logger.info("bucket doesn't exist, creating...")
        try:
            if bucket_region == "us-east-1":
                response = s3client.create_bucket(
                    Bucket=bucket_name, ACL="private")
            else:
                response = s3client.create_bucket(
                    Bucket=bucket_name,
                    ACL="private",
                    CreateBucketConfiguration={
                        "LocationConstraint": bucket_region},
                )
            logger.info(
                "Response Code: %s", response["ResponseMetadata"]["HTTPStatusCode"]
            )
        except ClientError as err:
            logger.warning("failed creating bucket...")
            logger.warning(err)
            raise
    if response:
        logger.debug("response...\n%s", json.dumps(response, indent=2))
def create_s3_bucket ( dryrun : bool , bucket_name : str , bucket_region : str ) -> None : logger . info ( "creating bucket %s in region %s" , bucket_name , bucket_region ) if dryrun : logger . info ( "in dry run mode.. not running!" ) return response = "" try : s3client = boto3 . client ( "s3" , region_name = bucket_region ) response = s3client . head_bucket ( Bucket = bucket_name ) logger . info ( "bucket exists.. not creating" ) except ClientError as err : logger . info ( "lookup on bucket failed with error: %s" , err ) logger . info ( "bucket doesn't exist, creating..." ) try : if bucket_region == "us-east-1" : response = s3client . create_bucket ( Bucket = bucket_name , ACL = "private" ) else : response = s3client . create_bucket ( Bucket = bucket_name , ACL = "private" , CreateBucketConfiguration = { "LocationConstraint" : bucket_region } , ) logger . info ( "Response Code: %s" , response [ "ResponseMetadata" ] [ "HTTPStatusCode" ] ) except ClientError as err : logger . warning ( "failed creating bucket..." ) logger . warning ( err ) raise if response : logger . debug ( "response...\n%s" , json . dumps ( response , indent = 2 ) )
Create a bucket.
Create a bucket .
"""
    Create a bucket.
    If the bucket already exists and you have access to it, no bucket will be created.

    https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Bucket.create
    """ # check if the bucket exists and we have access to it or None. # To create bucket in the specified region # Let's try to create the bucket. This will fail if # the bucket has already been created by someone else.
dryrun
bool
bucket_name
str
bucket_region
str