403 Forbidden
How to Fix AWS S3 Error Code 403 (Access Denied)
Amazon S3 returns HTTP 403 Access Denied when the calling identity lacks permission for the requested operation. Fix it with least-privilege IAM permissions and a correctly configured AWS SDK v3 client.
- Applies to
- Amazon S3, AWS SDK for JavaScript v3
- Updated
- Read time
- 1 min
AWS S3 Error 403: Access Denied in Node.js
1. ERROR DETAILS
Error code: 403 Forbidden
AWS service: Amazon S3 Node.js SDK: AWS SDK for JavaScript v3
Typical exception: S3ServiceException: Access Denied
HTTP 403 occurs when Amazon S3 denies a request because the effective permissions of the calling identity do not authorize the requested operation.
2. IMMEDIATE FIX
Step 1: Apply least-privilege IAM permissions
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ListApplicationPrefix",
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME"
},
{
"Sid": "ReadApplicationObjects",
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME/app/*"
}
]
}
Step 2: Configure the Node.js AWS SDK v3 client
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");
const s3 = new S3Client({ region: process.env.AWS_REGION });