Get compute metadata from app engine, got 404 page not found error












0















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);
});
}









share|improve this question

























  • which GAE environment?

    – Dan Cornilescu
    Nov 21 '18 at 10:53











  • @DanCornilescu standard environment

    – slideshowp2
    Nov 21 '18 at 11:01
















0















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);
});
}









share|improve this question

























  • which GAE environment?

    – Dan Cornilescu
    Nov 21 '18 at 10:53











  • @DanCornilescu standard environment

    – slideshowp2
    Nov 21 '18 at 11:01














0












0








0








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);
});
}









share|improve this question
















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);
});
}






google-app-engine google-cloud-platform google-compute-engine






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 6 '18 at 4:45







slideshowp2

















asked Nov 16 '18 at 4:45









slideshowp2slideshowp2

2,97322980




2,97322980













  • which GAE environment?

    – Dan Cornilescu
    Nov 21 '18 at 10:53











  • @DanCornilescu standard environment

    – slideshowp2
    Nov 21 '18 at 11:01



















  • which GAE environment?

    – Dan Cornilescu
    Nov 21 '18 at 10:53











  • @DanCornilescu standard environment

    – slideshowp2
    Nov 21 '18 at 11:01

















which GAE environment?

– Dan Cornilescu
Nov 21 '18 at 10:53





which GAE environment?

– Dan Cornilescu
Nov 21 '18 at 10:53













@DanCornilescu standard environment

– slideshowp2
Nov 21 '18 at 11:01





@DanCornilescu standard environment

– slideshowp2
Nov 21 '18 at 11:01












2 Answers
2






active

oldest

votes


















1














A while ago this wasn't at all possible in the standard environment, see Is there a way to access the Google Cloud metadata service from AppEngine Standard for runtime configuration?



But things appear to be changing.



There is a mentioning of the Metadata service in the (1st generation) standard environment documentation, but:




  • only for the java sandbox


  • potentially limited scope - only a subset of the endpoints mentioned, maybe the user-configured aren't, indeed, covered. But may be a matter of interpretation (emphasis mine):



The following table lists the endpoints where you can make HTTP
requests for specific metadata.





  • read-only:



Note: Metadata access is currently read only: you cannot write your own metadata for an instance.




This means the DNS limitation making it impossible a while ago was eliminated. Since you can get the data in the flexible environment it means it exists and you're not really trying to write it, so what you experience isn't related to the read-only limitation either.



It seems that indeed the service feature/endpoint you seek is more likely not available/functional, at least for the go sandbox (if not for all of them), rather than just an accidental documentation omission (which one might suspect/hope).






share|improve this answer
























  • But the metadata can be retrieved in GAE flexible environment. I am pretty sure of this. What a GCP, waste my a lot of times.

    – slideshowp2
    Nov 21 '18 at 12:15













  • Yes, it's actually part of the recommended alternative for the missing App identity. But that's a different environment. And I'm not certain the custom endpoints work in that case either.

    – Dan Cornilescu
    Nov 21 '18 at 17:35



















1














Finally I found the reason, it's metadata api version issue.



Instead of using



http://metadata.google.internal/computeMetadata/v1beta/project/attributes/${attr}



use



http://metadata.google.internal/computeMetadata/v1/project/attributes/${attr}



Now, I can get metadata from app engine flexible environment.



{"IT_EBOOKS_API":"http://it-ebooks-api.info/v1","PROJECT_ID":"just-aloe-212502","API_KEY":"12j28flsrbapznq"}


But for GAE standard environment and GCF. Still get 404 page not found



So I think but not sure that GCF and GAE standard environment are not running in compute engine.



GAE flexiable environment use compute engine as its infrastructure. That's why it can get metadata from compute engine.






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331591%2fget-compute-metadata-from-app-engine-got-404-page-not-found-error%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    A while ago this wasn't at all possible in the standard environment, see Is there a way to access the Google Cloud metadata service from AppEngine Standard for runtime configuration?



    But things appear to be changing.



    There is a mentioning of the Metadata service in the (1st generation) standard environment documentation, but:




    • only for the java sandbox


    • potentially limited scope - only a subset of the endpoints mentioned, maybe the user-configured aren't, indeed, covered. But may be a matter of interpretation (emphasis mine):



    The following table lists the endpoints where you can make HTTP
    requests for specific metadata.





    • read-only:



    Note: Metadata access is currently read only: you cannot write your own metadata for an instance.




    This means the DNS limitation making it impossible a while ago was eliminated. Since you can get the data in the flexible environment it means it exists and you're not really trying to write it, so what you experience isn't related to the read-only limitation either.



    It seems that indeed the service feature/endpoint you seek is more likely not available/functional, at least for the go sandbox (if not for all of them), rather than just an accidental documentation omission (which one might suspect/hope).






    share|improve this answer
























    • But the metadata can be retrieved in GAE flexible environment. I am pretty sure of this. What a GCP, waste my a lot of times.

      – slideshowp2
      Nov 21 '18 at 12:15













    • Yes, it's actually part of the recommended alternative for the missing App identity. But that's a different environment. And I'm not certain the custom endpoints work in that case either.

      – Dan Cornilescu
      Nov 21 '18 at 17:35
















    1














    A while ago this wasn't at all possible in the standard environment, see Is there a way to access the Google Cloud metadata service from AppEngine Standard for runtime configuration?



    But things appear to be changing.



    There is a mentioning of the Metadata service in the (1st generation) standard environment documentation, but:




    • only for the java sandbox


    • potentially limited scope - only a subset of the endpoints mentioned, maybe the user-configured aren't, indeed, covered. But may be a matter of interpretation (emphasis mine):



    The following table lists the endpoints where you can make HTTP
    requests for specific metadata.





    • read-only:



    Note: Metadata access is currently read only: you cannot write your own metadata for an instance.




    This means the DNS limitation making it impossible a while ago was eliminated. Since you can get the data in the flexible environment it means it exists and you're not really trying to write it, so what you experience isn't related to the read-only limitation either.



    It seems that indeed the service feature/endpoint you seek is more likely not available/functional, at least for the go sandbox (if not for all of them), rather than just an accidental documentation omission (which one might suspect/hope).






    share|improve this answer
























    • But the metadata can be retrieved in GAE flexible environment. I am pretty sure of this. What a GCP, waste my a lot of times.

      – slideshowp2
      Nov 21 '18 at 12:15













    • Yes, it's actually part of the recommended alternative for the missing App identity. But that's a different environment. And I'm not certain the custom endpoints work in that case either.

      – Dan Cornilescu
      Nov 21 '18 at 17:35














    1












    1








    1







    A while ago this wasn't at all possible in the standard environment, see Is there a way to access the Google Cloud metadata service from AppEngine Standard for runtime configuration?



    But things appear to be changing.



    There is a mentioning of the Metadata service in the (1st generation) standard environment documentation, but:




    • only for the java sandbox


    • potentially limited scope - only a subset of the endpoints mentioned, maybe the user-configured aren't, indeed, covered. But may be a matter of interpretation (emphasis mine):



    The following table lists the endpoints where you can make HTTP
    requests for specific metadata.





    • read-only:



    Note: Metadata access is currently read only: you cannot write your own metadata for an instance.




    This means the DNS limitation making it impossible a while ago was eliminated. Since you can get the data in the flexible environment it means it exists and you're not really trying to write it, so what you experience isn't related to the read-only limitation either.



    It seems that indeed the service feature/endpoint you seek is more likely not available/functional, at least for the go sandbox (if not for all of them), rather than just an accidental documentation omission (which one might suspect/hope).






    share|improve this answer













    A while ago this wasn't at all possible in the standard environment, see Is there a way to access the Google Cloud metadata service from AppEngine Standard for runtime configuration?



    But things appear to be changing.



    There is a mentioning of the Metadata service in the (1st generation) standard environment documentation, but:




    • only for the java sandbox


    • potentially limited scope - only a subset of the endpoints mentioned, maybe the user-configured aren't, indeed, covered. But may be a matter of interpretation (emphasis mine):



    The following table lists the endpoints where you can make HTTP
    requests for specific metadata.





    • read-only:



    Note: Metadata access is currently read only: you cannot write your own metadata for an instance.




    This means the DNS limitation making it impossible a while ago was eliminated. Since you can get the data in the flexible environment it means it exists and you're not really trying to write it, so what you experience isn't related to the read-only limitation either.



    It seems that indeed the service feature/endpoint you seek is more likely not available/functional, at least for the go sandbox (if not for all of them), rather than just an accidental documentation omission (which one might suspect/hope).







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 21 '18 at 12:06









    Dan CornilescuDan Cornilescu

    30k113767




    30k113767













    • But the metadata can be retrieved in GAE flexible environment. I am pretty sure of this. What a GCP, waste my a lot of times.

      – slideshowp2
      Nov 21 '18 at 12:15













    • Yes, it's actually part of the recommended alternative for the missing App identity. But that's a different environment. And I'm not certain the custom endpoints work in that case either.

      – Dan Cornilescu
      Nov 21 '18 at 17:35



















    • But the metadata can be retrieved in GAE flexible environment. I am pretty sure of this. What a GCP, waste my a lot of times.

      – slideshowp2
      Nov 21 '18 at 12:15













    • Yes, it's actually part of the recommended alternative for the missing App identity. But that's a different environment. And I'm not certain the custom endpoints work in that case either.

      – Dan Cornilescu
      Nov 21 '18 at 17:35

















    But the metadata can be retrieved in GAE flexible environment. I am pretty sure of this. What a GCP, waste my a lot of times.

    – slideshowp2
    Nov 21 '18 at 12:15







    But the metadata can be retrieved in GAE flexible environment. I am pretty sure of this. What a GCP, waste my a lot of times.

    – slideshowp2
    Nov 21 '18 at 12:15















    Yes, it's actually part of the recommended alternative for the missing App identity. But that's a different environment. And I'm not certain the custom endpoints work in that case either.

    – Dan Cornilescu
    Nov 21 '18 at 17:35





    Yes, it's actually part of the recommended alternative for the missing App identity. But that's a different environment. And I'm not certain the custom endpoints work in that case either.

    – Dan Cornilescu
    Nov 21 '18 at 17:35













    1














    Finally I found the reason, it's metadata api version issue.



    Instead of using



    http://metadata.google.internal/computeMetadata/v1beta/project/attributes/${attr}



    use



    http://metadata.google.internal/computeMetadata/v1/project/attributes/${attr}



    Now, I can get metadata from app engine flexible environment.



    {"IT_EBOOKS_API":"http://it-ebooks-api.info/v1","PROJECT_ID":"just-aloe-212502","API_KEY":"12j28flsrbapznq"}


    But for GAE standard environment and GCF. Still get 404 page not found



    So I think but not sure that GCF and GAE standard environment are not running in compute engine.



    GAE flexiable environment use compute engine as its infrastructure. That's why it can get metadata from compute engine.






    share|improve this answer






























      1














      Finally I found the reason, it's metadata api version issue.



      Instead of using



      http://metadata.google.internal/computeMetadata/v1beta/project/attributes/${attr}



      use



      http://metadata.google.internal/computeMetadata/v1/project/attributes/${attr}



      Now, I can get metadata from app engine flexible environment.



      {"IT_EBOOKS_API":"http://it-ebooks-api.info/v1","PROJECT_ID":"just-aloe-212502","API_KEY":"12j28flsrbapznq"}


      But for GAE standard environment and GCF. Still get 404 page not found



      So I think but not sure that GCF and GAE standard environment are not running in compute engine.



      GAE flexiable environment use compute engine as its infrastructure. That's why it can get metadata from compute engine.






      share|improve this answer




























        1












        1








        1







        Finally I found the reason, it's metadata api version issue.



        Instead of using



        http://metadata.google.internal/computeMetadata/v1beta/project/attributes/${attr}



        use



        http://metadata.google.internal/computeMetadata/v1/project/attributes/${attr}



        Now, I can get metadata from app engine flexible environment.



        {"IT_EBOOKS_API":"http://it-ebooks-api.info/v1","PROJECT_ID":"just-aloe-212502","API_KEY":"12j28flsrbapznq"}


        But for GAE standard environment and GCF. Still get 404 page not found



        So I think but not sure that GCF and GAE standard environment are not running in compute engine.



        GAE flexiable environment use compute engine as its infrastructure. That's why it can get metadata from compute engine.






        share|improve this answer















        Finally I found the reason, it's metadata api version issue.



        Instead of using



        http://metadata.google.internal/computeMetadata/v1beta/project/attributes/${attr}



        use



        http://metadata.google.internal/computeMetadata/v1/project/attributes/${attr}



        Now, I can get metadata from app engine flexible environment.



        {"IT_EBOOKS_API":"http://it-ebooks-api.info/v1","PROJECT_ID":"just-aloe-212502","API_KEY":"12j28flsrbapznq"}


        But for GAE standard environment and GCF. Still get 404 page not found



        So I think but not sure that GCF and GAE standard environment are not running in compute engine.



        GAE flexiable environment use compute engine as its infrastructure. That's why it can get metadata from compute engine.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 28 '18 at 2:02

























        answered Nov 22 '18 at 10:52









        slideshowp2slideshowp2

        2,97322980




        2,97322980






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53331591%2fget-compute-metadata-from-app-engine-got-404-page-not-found-error%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues