-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
closed-for-stalenessfeature-requestA feature should be added or improved.A feature should be added or improved.
Description
Describe the bug
When an EC2 instance is configured to only allow IMDSv2, the AWS.MetadataService.request() doesn't work. The returned error null is not helpful. The workaround is to manually get a IMDS token and pass it to AWS.MetadataService.request(). The Java SDK handles this transparent to the developer which seems the better approach.
Is the issue in the browser/Node.js?
Node.js
If on Node.js, are you running this on AWS Lambda?
no
Details of the browser/Node.js version
v12.20.0
SDK version number
2.792.0 (but master branch has the issues as well)
To Reproduce (observed behavior)
const AWS = require("aws-sdk");
const meta = new AWS.MetadataService();
meta.request("/latest/meta-data/local-ipv4", function (err, data) {
if (err) {
throw err;
} else {
console.log(data);
}
});throws
Error: null
at IncomingMessage.<anonymous> (/etc/home/ec2-user/app/src/node_modules/aws-sdk/lib/util.js:899:34)
at IncomingMessage.emit (events.js:326:22)
at IncomingMessage.EventEmitter.emit (domain.js:483:12)
at endReadableNT (_stream_readable.js:1241:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
statusCode: 401,
retryable: false,
time: 2020-12-17T13:59:03.709Z
}Expected behavior
return 10.0.32.49
Work around
const AWS = require("aws-sdk");
const meta = new AWS.MetadataService();
meta.fetchMetadataToken(function (err, token) {
if (err) {
throw err;
} else {
meta.request(
"/latest/meta-data/local-ipv4",
{
headers: { "x-aws-ec2-metadata-token": token },
},
function (err, data) {
if (err) {
throw err;
} else {
console.log(data);
}
}
);
}
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
closed-for-stalenessfeature-requestA feature should be added or improved.A feature should be added or improved.