0
 
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.') 

I am creating an S3 bucket but for some reason, Pylance is giving me an error complaining it cant access the variable.

Error here

1 Answers1

0

Update your code to remove the 3rd parameter, boto3 s3 create_bucket takes exactly 2 arguments, take a look at the official documentation.

new_bucket = s3.create_bucket(
            Bucket=bucketName,
            CreateBucketConfiguration={'LocationConstraint': 'eu-west-1'}
        )
Subhashis Pandey
  • 1,473
  • 1
  • 13
  • 16