Skip to content

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

Open
@jstephenson

Description

@jstephenson

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    size: lPull request size is large.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions