I’m getting a bucket x already exists error when d...
# help
r
I’m getting a bucket x already exists error when deploying a stack to a new stage. The buckets are created based on an environment variable, basically a comma-separated list of countries. The creation function looks like this:
Copy code
createPortfolioDataBuckets(removalPolicy: RemovalPolicy, countries: string[]): EnvVarBucketMap {
    const envVarBucketMap: EnvVarBucketMap = {};
    for (const country of countries) {
      const bucket = new sst.Bucket(this, `${this.stage}-${country}-portfolio-data`, {
        s3Bucket: {
          removalPolicy,
          accessControl: BucketAccessControl.PRIVATE,
          blockPublicAccess: BlockPublicAccess.BLOCK_ALL,
          versioned: true,
          bucketName: `${this.stage}-${country}-portfolio-data`,
        },
      });
      bucket.s3Bucket.addCorsRule(corsBucketRule);
      const envVarName = `${country.toUpperCase()}_PORTFOLIO_BUCKET`;
      envVarBucketMap[envVarName] = bucket;
    }
    return envVarBucketMap;
  }
This function is called only once in the stack, the value of the string array that’s passed in is
['germany', 'italy']
so the bucket names and IDs should be unique. Can anyone see what could be causing the issue?
This is with SST 0.67.2
t
Is it possible the bucket is already in use by someone else?
bucketName probably needs your company name in it
r
Oh, you think this is a globally unique problem
t
yeah
r
Good shout
That was it, didn’t cross my mind it was a name that someone else in the world might have used! Thank you