Skip to content

@aws-sdk/ec2-metadata-service supressing HTTP statusCode #7357

@rynop

Description

@rynop

Checkboxes for prior research

Describe the bug

When the SDK makes an internal request to the EC2 instance's meta-data service, if the HTTP request fails the .statusCode does not bubble back up to the calling code.

In AWS SDK for JS v2, calling code could get at the .statusCode on the thrown Error. In V3, the original error is caught and re-thrown as a string: Error making request to the metadata service: ${error}. For example: Error making request to the metadata service: Error: Request failed with status code 404

The offending code is here: https://github.com/aws/aws-sdk-js-v3/blob/main/packages/ec2-metadata-service/src/MetadataService.ts#L80

The failing status code needs to be available to the caller so we don't have to do string matching.

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

AWS SDK v2

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

node: v22.15.0

Reproduction Steps

import {MetadataService} from '@aws-sdk/ec2-metadata-service';

const metaService = new MetadataService({});
await metaService.request(`/latest/meta-data/DNE`, {});

Observed Behavior

Original error is caught and re-thrown, with the original error flattened to a string. Ex: Error making request to the metadata service: Error: Request failed with status code 404

Expected Behavior

statusCode on the failing request should be available to the caller

Possible Solution

No response

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p2This is a standard priority issuepotential-regressionMarking this issue as a potential regression to be checked by team memberqueuedThis issues is on the AWS team's backlog

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions