Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of GoogleAuth.getClient() via gax-nodejs via @googlemaps/addressvalidation in AWS Lambda causes slow GCE metadata fetch attempt #1944

Open
7 tasks done
jstephenson opened this issue Mar 4, 2025 · 0 comments

Comments

@jstephenson
Copy link

jstephenson commented Mar 4, 2025

Please make sure you have searched for information in the following guides.

A screenshot that you have tested with "Try this API".

API does not seem to be available in the explorer

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

https://gist.github.com/jstephenson/d8a44a2d28b73923796952aa8a02d081

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

  1. Execute the above sample in an AWS Lambda function
    • This should be reproducible in any environment which does not provide project ID in one of the pre-metadata fashions encoded here:
      projectId ||= await this.getProductionProjectId();
      projectId ||= await this.getFileProjectId();
      projectId ||= await this.getDefaultServiceProjectId();
      projectId ||= await this.getGCEProjectId();
      projectId ||= await this.getExternalAccountClientProjectId();

A clear and concise description of what the bug is, and what you expected to happen.

I have attempted a trivial usage of the Google Maps Platform's Address Validation API from an AWS Lambda function today. This service uses an API key for authentication.

It takes ~15 seconds for execution to resume at the API call site. Upon inspection—primarily via NODE_DEBUG=http—I can see three failed attempts to connect to a GCP metadata endpoint at 169.254.169.254 which each have a five second timeout.

As documented
I am using the apiKey auth strategy for the Address Validation API. Looking at the code, it seems that GoogleAuth's getClient() method kicks off a call stack which ends up making a call into the gcp-metadata package's project() function in my use-case. This then in turn attempts to reach a link-local metadata server, and this then becomes slow.

To validate that this is indeed the issue I have set the environment variable GOOGLE_CLOUD_PROJECT on my AWS Lambda function and verified that no attempts are then made to reach a metadata service.

I can't find any documentation which suggests I am doing anything wrong, so I'm raising this here in the belief that this represents a bug. Sorry if I'm wrong.

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

The Address Validation API uses API key authentication and this appears to be supported by the SDK

@jstephenson jstephenson changed the title Use of GoogleAuth.getClient() via gax-nodejs via google-cloud-node causes slow metadata fetch attempt in AWS Use of GoogleAuth.getClient() via gax-nodejs via @googlemaps/addressvalidation in AWS Lambda causes slow GCE metadata fetch attempt Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant