Skip to content

MIGRATION ISSUE: Unknown (403) error on POST policy condition violation (forbidden)Β #6597

@yvele

Description

@yvele

Pre-Migration Checklist

Which JavaScript Runtime is this issue in?

Node.js (includes AWS Lambda)

AWS Lambda Usage

  • Yes, my application is running on AWS Lambda.
  • No, my application is not running on AWS Lambda.

Describe the Migration Issue

When sending an HeadObjectCommand on an existing S3 object that has been uploaded without respecting POST policy conditions (size out of range in my particular case) I get a 403 "UnknownError" with AWS SDK v3:

{
    "name": "403",
    "$fault": "client",
    "$metadata": {
        "httpStatusCode": 403,
        "requestId": "XXXXX",
        "extendedRequestId": "XXXXX/XXXXX/XXXXX=",
        "attempts": 1,
        "totalRetryDelay": 0
    },
    "message": "UnknownError"
}

With AWS SDK v2 the error code was "Forbidden".

Code Comparison

AWS SDK v2

let head;
try {
  head = await s3.headObject({
    Bucket : "bucketName",
    Key : "key"
  }).promise();
} catch (err) {
  if (err.code === "Forbidden") {
    // Catched!
  }
  throw err;
}

AWS SDK v3

const headObjectCommand = new HeadObjectCommand({
  Bucket : "bucketName",
  Key : "key"
});
let head;
try {
  head = await s3Client.send(headObjectCommand);
} catch (err) {
  if (err.name === "403" && err.message === "UnknownError") {
    // Catched!
  }
  throw err;
}

Observed Differences/Errors

I'm using the AWS SDK v3 and typically catch errors based on their specific types, such as if (err instanceof NoSuchKey).

However, when handling POST policy condition violations, I encounter an ambiguous "unknown error" rather than a specific Forbidden error as expected. This lack of clarity makes it difficult to diagnose and handle POST policy condition issues effectively.

Additional Context

@aws-sdk/client-s3 v3.679.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2This is a standard priority issuev2-v3-inconsistencyBehavior has changed from v2 to v3, or feature is missing altogether

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions