You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

使用AWS SDK(Node.js)创建S3存储桶时遇InvalidBucketName错误

Fixing the InvalidBucketName Error When Creating an S3 Bucket with AWS SDK for Node.js

Ah, I’ve run into this exact snag before—let’s get you sorted out quickly.

Why You’re Seeing This Error

Your bucket name thisIsTestBucket190 is violating one of AWS S3’s non-negotiable naming rules: bucket names must be entirely lowercase. The uppercase letters sprinkled throughout your name are directly triggering that InvalidBucketName exception.

Quick Recap of S3 Bucket Naming Rules

To avoid this (and other) bucket naming headaches down the line, keep these rules top of mind:

  • Length must be between 3 and 63 characters
  • Only allowed characters: lowercase letters, numbers, hyphens (-), and periods (.)
  • Can’t start or end with a hyphen
  • No consecutive hyphens
  • If you use periods, make sure the name doesn’t resemble a domain (this prevents SSL certificate issues when setting up bucket websites)

Fixing Your Code

All you need to do is convert your bucket name to all lowercase. Here’s what your corrected code would look like with the AWS SDK for Node.js:

const AWS = require('aws-sdk');
const s3 = new AWS.S3({ region: 'us-east-1' }); // Adjust your region as needed

const createBucketParams = {
  Bucket: 'thisistestbucket190' // Updated to all lowercase
};

s3.createBucket(createBucketParams, (err, data) => {
  if (err) {
    console.error('Error creating bucket:', err);
  } else {
    console.log('Bucket created successfully! Location:', data.Location);
  }
});

Quick Side Note

If you still hit issues after fixing the name, double-check that your IAM user/role has the s3:CreateBucket permission assigned. But in your case, the uppercase letters in the bucket name are 100% the culprit here.


内容的提问来源于stack exchange,提问作者Nirojan Selvanathan

火山引擎 最新活动