使用aws_s3扩展从S3导入数据到RDS PostgreSQL失败求助
Let’s break down the most likely issues causing this 404 error—more often than not, it’s rooted in small mismatches or overlooked configuration details rather than a major setup failure:
Double-check your S3 path and filename accuracy
S3 object names are case-sensitive, sofile.csvandFile.csvare treated as entirely different objects. If your file lives in a subfolder (likedata/imports/file.csv), you need to include that full path in theaws_commons.create_s3_uricall—not justfile.csv. Also make sure thebucket-nameparameter exactly matches your actual S3 bucket name (S3 bucket names are strictly lowercase, so no typos there).Verify your IAM policy’s resource matches the target bucket
Your policy specifies resources forarn:aws:s3:::my-bucketandarn:aws:s3:::my-bucket/*—so your command’sbucket-namemust bemy-bucket(not a placeholder or misspelled name). If your actual bucket has a different name, update either the policy or the command to align them perfectly.Ensure RDS and S3 are in the same region
Theregionparameter inaws_commons.create_s3_urineeds to match your S3 bucket’s exact region (e.g.,us-east-1, not an availability zone likeus-east-1a). Cross-region imports can work but require extra steps, so start with matching regions to eliminate this variable.Confirm the S3 object actually exists
Run a quick check with the AWS CLI to validate the file is present:aws s3 ls s3://your-bucket-name/file.csv --region your-regionOr navigate directly to the S3 console to confirm the file’s path and name are exactly what you’re using in the import command.
Validate the IAM role’s trust policy
You’ve attached the correct permission policy, but does the role trust the RDS service to assume it? The trust policy should look like this:{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "rds.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }Without this, RDS can’t use the role to access S3, which might manifest as a 404 error (even though the core issue is permission-related, not file existence).
Recheck that the S3 Import feature is active on your RDS instance
Head to the RDS console, select your instance, and check the "Features" tab to confirms3Importis enabled and in an "Available" state. Sometimes enabling the feature requires a brief instance restart to take full effect, so if you just turned it on, give that a try.
Start with the first three checks—they’re the most common culprits for this error. Once you’ve ruled those out, move on to the permission and configuration validations.
内容的提问来源于stack exchange,提问作者user10916892

