I try to get project-wide metadata
from app engine, the url like this:
http://metadata.google.internal/computeMetadata/v1/project/attributes/IT_EBOOKS_API
The stackdriver logging
give me an error:
message: '404 - "404 page not found\\n"',
But I can get metadata
from compute engine. Here is the metadata
output:
novaline_dulin@test:~$ curl http://metadata.google.internal/computeMetadata/v1/project/attributes/IT_EBOOKS_API -H
"Metadata-Flavor: Google"
http://it-ebooks-api.info/v1novaline_dulin@test:~$
And, here is my code for getting custom project-wide metadata
const request = require('request-promise');
async function getMetaData(attr) {
const url = `http://metadata.google.internal/computeMetadata/v1/project/attributes/${attr}`;
const options = {
headers: {
'Metadata-Flavor': 'Google'
}
};
console.log('url:', url);
return request(url, options)
.then((response) => {
console.info(`Retrieve meta data successfully. meta data: ${response}`);
return response;
})
.catch((err) => {
console.error('Retrieve meta data failed.', err);
return '';
});
}
Is there something wrong? thanks.
update
I can get project-id
from metadata
server correctly. Here is the code:
const METADATA_PROJECT_ID_URL = 'http://metadata.google.internal/computeMetadata/v1/project/project-id';
async function getProjectId() {
const options = {
headers: {
'Metadata-Flavor': 'Google'
}
};
return request(METADATA_PROJECT_ID_URL, options)
.then((response) => {
console.log('response: ', response);
return response;
})
.catch((err) => {
if (err && err.statusCode !== 200) {
console.log('Error while talking to metadata server.');
return 'Unknown_Project_ID';
}
return Promise.reject(err);
});
}