@aws-sdk/ec2-metadata-service 3.940.0 → 3.946.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -57,6 +57,7 @@ class MetadataService {
57
57
  const { endpoint, ec2MetadataV1Disabled, httpOptions } = await this.config;
58
58
  const handler = new nodeHttpHandler.NodeHttpHandler({
59
59
  requestTimeout: httpOptions?.timeout,
60
+ throwOnRequestTimeout: true,
60
61
  connectionTimeout: httpOptions?.timeout,
61
62
  });
62
63
  const endpointUrl = new URL(endpoint);
@@ -98,6 +99,7 @@ class MetadataService {
98
99
  const { endpoint, httpOptions } = await this.config;
99
100
  const handler = new nodeHttpHandler.NodeHttpHandler({
100
101
  requestTimeout: httpOptions?.timeout,
102
+ throwOnRequestTimeout: true,
101
103
  connectionTimeout: httpOptions?.timeout,
102
104
  });
103
105
  const endpointUrl = new URL(endpoint);
@@ -112,20 +114,23 @@ class MetadataService {
112
114
  });
113
115
  try {
114
116
  const { response } = await handler.handle(tokenRequest, {});
115
- if (response.statusCode === 200 && response.body) {
116
- return utilStream.sdkStreamMixin(response.body).transformToString();
117
+ let bodyString = "";
118
+ if (response.body) {
119
+ bodyString = await utilStream.sdkStreamMixin(response.body).transformToString();
120
+ }
121
+ if (response.statusCode === 200 && bodyString) {
122
+ return bodyString;
117
123
  }
118
124
  else {
119
- throw new Error(`Failed to fetch metadata token with status code ${response.statusCode}`);
125
+ throw Object.assign(new Error(`Failed to fetch metadata token with status code ${response.statusCode}`), {
126
+ statusCode: response.statusCode,
127
+ });
120
128
  }
121
129
  }
122
130
  catch (error) {
123
- if (error?.statusCode === 400) {
124
- throw new Error(`Error fetching metadata token: ${error}`);
125
- }
126
- else if (error.message === "TimeoutError" || [403, 404, 405].includes(error.statusCode)) {
131
+ if (error.message === "TimeoutError" || [403, 404, 405].includes(error.statusCode)) {
127
132
  this.disableFetchToken = true;
128
- throw new Error(`Error fetching metadata token: ${error}. disableFetchToken is enabled`);
133
+ throw new Error(`Error fetching metadata token: ${error}. [disableFetchToken] is now set to true.`);
129
134
  }
130
135
  throw new Error(`Error fetching metadata token: ${error}`);
131
136
  }
@@ -23,6 +23,7 @@ export class MetadataService {
23
23
  const { endpoint, ec2MetadataV1Disabled, httpOptions } = await this.config;
24
24
  const handler = new NodeHttpHandler({
25
25
  requestTimeout: httpOptions?.timeout,
26
+ throwOnRequestTimeout: true,
26
27
  connectionTimeout: httpOptions?.timeout,
27
28
  });
28
29
  const endpointUrl = new URL(endpoint);
@@ -64,6 +65,7 @@ export class MetadataService {
64
65
  const { endpoint, httpOptions } = await this.config;
65
66
  const handler = new NodeHttpHandler({
66
67
  requestTimeout: httpOptions?.timeout,
68
+ throwOnRequestTimeout: true,
67
69
  connectionTimeout: httpOptions?.timeout,
68
70
  });
69
71
  const endpointUrl = new URL(endpoint);
@@ -78,20 +80,23 @@ export class MetadataService {
78
80
  });
79
81
  try {
80
82
  const { response } = await handler.handle(tokenRequest, {});
81
- if (response.statusCode === 200 && response.body) {
82
- return sdkStreamMixin(response.body).transformToString();
83
+ let bodyString = "";
84
+ if (response.body) {
85
+ bodyString = await sdkStreamMixin(response.body).transformToString();
86
+ }
87
+ if (response.statusCode === 200 && bodyString) {
88
+ return bodyString;
83
89
  }
84
90
  else {
85
- throw new Error(`Failed to fetch metadata token with status code ${response.statusCode}`);
91
+ throw Object.assign(new Error(`Failed to fetch metadata token with status code ${response.statusCode}`), {
92
+ statusCode: response.statusCode,
93
+ });
86
94
  }
87
95
  }
88
96
  catch (error) {
89
- if (error?.statusCode === 400) {
90
- throw new Error(`Error fetching metadata token: ${error}`);
91
- }
92
- else if (error.message === "TimeoutError" || [403, 404, 405].includes(error.statusCode)) {
97
+ if (error.message === "TimeoutError" || [403, 404, 405].includes(error.statusCode)) {
93
98
  this.disableFetchToken = true;
94
- throw new Error(`Error fetching metadata token: ${error}. disableFetchToken is enabled`);
99
+ throw new Error(`Error fetching metadata token: ${error}. [disableFetchToken] is now set to true.`);
95
100
  }
96
101
  throw new Error(`Error fetching metadata token: ${error}`);
97
102
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/ec2-metadata-service",
3
- "version": "3.940.0",
3
+ "version": "3.946.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline ec2-metadata-service",
@@ -33,7 +33,7 @@
33
33
  "tslib": "^2.6.2"
34
34
  },
35
35
  "devDependencies": {
36
- "@aws-sdk/credential-providers": "3.940.0",
36
+ "@aws-sdk/credential-providers": "3.946.0",
37
37
  "@tsconfig/recommended": "1.0.1",
38
38
  "@types/node": "^18.19.69",
39
39
  "concurrently": "7.0.0",