s3 = boto3.resource("s3")
s3_client = boto3.client('s3')
name = "devopsProject"
bucketName = (name + str(uuid.uuid4()))
def createBucket():
##### Create the S3 Bucket #####
try:
print('Creating S3 Bucket...')
new_bucket = s3.create_bucket(
Bucket=bucketName,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'},
ACL='public-read',
)
print('Bucket successfully created.')
except Exception as e:
if e.response['Error']['Code'] == 'BucketAlreadyExists':
print('This bucket name is already in use')
else:
print('An error occurred during S3 Bucket creation.')
我正在创建一个S3桶,但由于某种原因,Pylance给了我一个错误,抱怨它不能访问变量。
错误在这里
更新您的代码以删除第三个参数,boto3 s3 create_bucket只需要2个参数,请查看官方文档。
new_bucket = s3.create_bucket(
Bucket=bucketName,
CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
)