“AWS Buat ember” Kode Jawaban

AWS Buat ember

import logging
import boto3
from botocore.exceptions import ClientError


def create_bucket(bucket_name, region=None):
    """Create an S3 bucket in a specified region

    If a region is not specified, the bucket is created in the S3 default
    region (us-east-1).

    :param bucket_name: Bucket to create
    :param region: String region to create bucket in, e.g., 'us-west-2'
    :return: True if bucket created, else False
    """

    # Create bucket
    try:
        if region is None:
            s3_client = boto3.client('s3')
            s3_client.create_bucket(Bucket=bucket_name)
        else:
            s3_client = boto3.client('s3', region_name=region)
            location = {'LocationConstraint': region}
            s3_client.create_bucket(Bucket=bucket_name,
                                    CreateBucketConfiguration=location)
    except ClientError as e:
        logging.error(e)
        return False
    return True
Active Programmer

Buat ember

aws s3 mb s3://REPLACE_ME_BUCKET_NAME
Lovely Lemur

Jawaban yang mirip dengan “AWS Buat ember”

Pertanyaan yang mirip dengan “AWS Buat ember”

Lebih banyak jawaban terkait untuk “AWS Buat ember” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya