
Your S3 File Is There. So Why Are You Getting 403 AccessDenied?
Have you ever uploaded an object to Amazon S3 successfully, only to receive a 403 AccessDenied error when trying to access it? In this hands-on guide, I'll explain the common causes of S3 access issues, including IAM permissions, bucket policies, Block Public Access, and object ownership. You'll also learn how to generate secure presigned URLs using Node.js, TypeScript, and AWS SDK v3 without making your bucket public.
Your S3 Object Exists, But Returns AccessDenied: How to Troubleshoot It
Imagine uploading an image to Amazon S3.
The upload succeeds. You can see the object in your S3 bucket. The object key is correct, and there are no errors during the upload.
But when you try to open the object URL in your browser, you get:
403 ForbiddenAccessDeniedThe first thing many developers think is that something went wrong with the upload.
But that's not always the case.
An object existing in S3 doesn't automatically mean everyone can access it.
Amazon S3 separates storing an object from granting permission to access it.
In this article, we'll explore why this happens, how to troubleshoot the most common causes, and how to provide secure access using presigned URLs with Node.js, TypeScript, and AWS SDK v3.
1. Understand the Difference Between Uploading and Accessing
Let's look at a simple backend workflow.
A user uploads a profile image through an API. Your AWS Lambda function receives the file and uploads it to an S3 bucket.
The upload succeeds, and S3 stores the object.
Your API then returns an object URL:
https://my-private-bucket.s3.amazonaws.com/profile/image.pngWhen the user opens that URL, S3 responds with
AccessDenied .Why?
Because uploading and downloading require different permissions.
Operation | Required IAM permission |
|---|---|
Upload an object | s3:PutObject |
Download an object | s3:GetObject |
Delete an object | s3:DeleteObject |
List bucket contents | s3:ListBucket |
For example, your Lambda execution role might have permission to upload files but not download them.
The upload works, but the download fails.
This is one of the first things I would check.
2. Check the IAM Permissions
AWS IAM controls what an identity, such as a Lambda execution role, is allowed to do.
Suppose your Lambda function only needs to upload and download objects from a specific folder.
You can attach a policy like this to its execution role:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowImageUploadAndDownload", "Effect": "Allow", "Action": [ "s3:PutObject", "s3:GetObject" ], "Resource": "arn:aws:s3:::my-private-bucket/profile/*" } ]}Replace
my-private-bucket with your actual bucket name.Notice that the resource ends with:
/profile/*This limits access to objects inside the profile folder.
You don't need to give your Lambda function full access to every object in the bucket.
Follow the principle of least privilege: grant only the permissions your application needs.
Also remember that
s3:ListBucket applies to the bucket ARN itself, while s3:GetObject and s3:PutObject apply to object ARNs.3. Understand IAM Policies vs Bucket Policies
IAM policies and S3 bucket policies are two different parts of AWS access control.
IAM policy
Attached to an IAM user, group, or role. It defines what that identity can do.
Bucket policy
Attached directly to an S3 bucket. It defines which principals can access the bucket and its objects.
For example, a bucket policy can allow a specific Lambda role to read objects.
{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowLambdaReadAccess", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:role/MyLambdaRole" }, "Action": "s3:GetObject", "Resource": "arn:aws:s3:::my-private-bucket/profile/*" } ]}Replace the account ID, role name, and bucket name with your own values.
For access within the same AWS account, an applicable identity-based or resource-based policy can grant access, provided no other applicable policy denies it.
For cross-account access, both the caller's identity-based policy and the resource policy must allow the request.
An explicit
Deny in an applicable policy overrides an Allow .4. Check S3 Block Public Access
This is another common reason developers get confused.
You might add a public-read bucket policy and still receive
AccessDenied .Why?
Because Amazon S3 Block Public Access settings can prevent public access even when a bucket policy or ACL attempts to grant it.
New S3 buckets have Block Public Access enabled by default.
There are four settings:
- BlockPublicAcls
- IgnorePublicAcls
- BlockPublicPolicy
- RestrictPublicBuckets
These settings can be applied at the account, bucket, or access point level.
Before changing anything, understand why your application needs public access.
For private files such as profile images, invoices, reports, and documents, you generally shouldn't disable Block Public Access just to fix a 403 error.
A better approach is to keep the bucket private and provide temporary access through presigned URLs.
5. Use Presigned URLs Instead of Making Your Bucket Public
This is one of the most useful approaches for applications that store private files.
A presigned URL allows someone to access a specific S3 object for a limited period without giving them AWS credentials.
For example:
- A user requests a private image.
- Your backend checks whether the user is authorized.
- Lambda generates a presigned URL.
- Your API returns that URL.
- The browser uses it to download the object.
The S3 bucket remains private.
Let's implement this with TypeScript.
6. Generate a Presigned URL Using AWS SDK v3
Install the required packages:
npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presignerCreate a file named
s3.ts :import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
const s3 = new S3Client({ region: process.env.AWS_REGION});
const BUCKET_NAME = process.env.S3_BUCKET_NAME!;
export async function generateDownloadUrl( key: string): Promise<string> { const command = new GetObjectCommand({ Bucket: BUCKET_NAME, Key: key });
const url = await getSignedUrl(s3, command, { expiresIn: 300 });
return url;}Here is what happens:
-
S3Clientcreates an AWS S3 client.
-
GetObjectCommanddefines which object we want to download.
-
getSignedUrl()creates a temporary URL.
-
expiresIn: 300means the URL is configured to expire after five minutes.
Your Lambda execution role needs
s3:GetObject permission for the requested object.The role also needs the relevant KMS permissions if the object uses SSE-KMS encryption.
Now let's use this function in an API handler.
import type { APIGatewayProxyHandlerV2 } from "aws-lambda";import { generateDownloadUrl } from "./s3.js";
export const handler: APIGatewayProxyHandlerV2 = async (event) => { try { const key = event.pathParameters?.key;
if (!key) { return { statusCode: 400, body: JSON.stringify({ message: "Object key is required" }) }; }
// Verify that the authenticated user is allowed // to access this particular object before signing.
const url = await generateDownloadUrl(key);
return { statusCode: 200, body: JSON.stringify({ downloadUrl: url }) }; } catch (error) { console.error("Failed to generate download URL", error);
return { statusCode: 500, body: JSON.stringify({ message: "Unable to generate download URL" }) }; } };This is a simplified handler. In a real application, don't trust an object key supplied by the client without checking ownership or authorization.
A presigned URL is a bearer credential: anyone who has the URL can use it while it remains valid.
7. What If the Presigned URL Also Returns AccessDenied?
Generating a presigned URL doesn't automatically guarantee that the download will work.
The IAM role or user generating the URL must have the required
s3:GetObject permission.Also check:
- Is the bucket policy explicitly denying access?
- Is the URL still valid?
- Are the underlying AWS credentials still valid?
- Does the bucket require a particular encryption configuration?
- Is the object encrypted with SSE-KMS, and does the caller have the required KMS permissions?
- Are there VPC endpoint or organization policies restricting access?
One important detail: a presigned URL expires when its configured expiration is reached or when the underlying credentials expire, whichever happens first.
Also, use the URL with the same HTTP method and signed headers for which it was generated.
8. A Practical S3 AccessDenied Checklist
Whenever an S3 object exists but returns
403 AccessDenied , I would check these things in order:Check | What to verify |
|---|---|
Object key | Is the bucket name and object key correct? |
IAM role | Does the caller have s3:GetObject ? |
Bucket policy | Is there a missing Allow or explicit Deny? |
Block Public Access | Is public access intentionally blocked? |
Object Ownership | Are ACLs disabled or ownership configured differently than expected? |
Encryption | Does the caller have the necessary KMS permissions? |
Presigned URL | Is it valid and signed for the correct operation? |
Other policies | Are VPC endpoint, session, or organization policies restricting access? |
Don't immediately make the bucket public or attach
AmazonS3FullAccess to your Lambda role.Find the exact permission that's missing first.
9. What I Learned
The important lesson is that successfully uploading an object and successfully accessing it are two separate things.
When working with S3, you need to understand who is making the request, what action they're performing, and which policies control access.
For backend applications, keeping private files private and generating presigned URLs when needed is often a better approach than making an entire bucket publicly accessible.
The next time you see
AccessDenied , don't assume the object is missing.Start by checking the permissions.
An object can exist perfectly fine in S3 and still be inaccessible to the person trying to retrieve it.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article