{"record":{"id":"f34d86ac4b2d9b73","repo":"serverless/serverless","slug":"an-error-occurred-while-getting-location-for-bucke","errorCode":null,"errorMessage":"An error occurred while getting location for bucket \"${bucketName}\": ${err.message}","messagePattern":"An error occurred while getting location for bucket \"(.+?)\": (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/engine/src/lib/aws/s3.js","lineNumber":151,"sourceCode":"   * @param {string} params.bucketName - The name of the S3 bucket.\n   * @returns {Promise<string>} - The bucket location (region).\n   */\n  async getBucketLocation({ bucketName }) {\n    try {\n      const params = { Bucket: bucketName }\n      const command = new GetBucketLocationCommand(params)\n      const response = await this.client.send(command)\n\n      // If LocationConstraint is empty, the bucket is in us-east-1\n      return response.LocationConstraint || 'us-east-1'\n    } catch (err) {\n      const name = err.name\n      if (err instanceof NoSuchBucket || name === 'NoSuchBucket') {\n        throw new Error(\n          `The bucket \"${bucketName}\" does not exist. Please check the bucket name and try again.`,\n        )\n      } else {\n        throw new Error(\n          `An error occurred while getting location for bucket \"${bucketName}\": ${err.message}`,\n        )\n      }\n    }\n  }\n\n  /**\n   * Gets the ACL settings of an S3 bucket.\n   *\n   * @param {Object} params - The parameters for getting the bucket ACL.\n   * @param {string} params.bucketName - The name of the S3 bucket.\n   * @returns {Promise<Object>} - The bucket ACL settings.\n   */\n  async getBucketAcl({ bucketName }) {\n    try {\n      const params = { Bucket: bucketName }\n      const command = new GetBucketAclCommand(params)\n      const response = await this.client.send(command)","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/serverless/serverless/blob/b9d7ea51c8cce57cff1207964b9b71123673081f/packages/engine/src/lib/aws/s3.js#L133-L169","documentation":"Thrown by getBucketLocation() when GetBucketLocationCommand fails with any error other than NoSuchBucket. The original error is wrapped in a plain Error: 'An error occurred while getting location for bucket ...: <err.message>'.","triggerScenarios":"GetBucketLocationCommand rejects with a non-NoSuchBucket error — AccessDenied, PermanentRedirect, throttling, or network failure.","commonSituations":"Missing s3:GetBucketLocation permission (AWS requires this specific permission, which is commonly overlooked); bucket in a different region (PermanentRedirect); throttling; credential issues.","solutions":["Grant s3:GetBucketLocation on the bucket — AWS requires this permission explicitly and it is frequently missing.","Inspect err.message for the underlying code.","If PermanentRedirect, configure the client for the bucket's actual region.","Retry on transient errors."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isLocationIoError(e) {\n  return e instanceof Error && /An error occurred while getting location/.test(e.message)\n}","tryCatchPattern":"try {\n  return await s3.getBucketLocation({ bucketName })\n} catch (e) {\n  if (isLocationIoError(e)) {\n    // s3:GetBucketLocation is frequently missing — grant it explicitly\n  }\n  throw e\n}","preventionTips":["Explicitly grant s3:GetBucketLocation — AWS requires this permission by name.","Configure the client region to avoid PermanentRedirect.","Inspect the embedded err.message for the real AWS code."],"tags":["aws","s3","bucket-location","permissions","error-wrapping"],"backgroundTag":null,"analyzedSha":"b9d7ea51c8cce57cff1207964b9b71123673081f","analyzedAt":"2026-08-13T04:14:40.386Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}