Google Secret Manager Could not load the default credentials from AWS Lambda nodejs client

Creating secrets in GCP Secret Manager from an AWS Lambda using the Node.js client fails with: Error: Could not load the default credentials, even when projectId and the path to a service-account JSON key file are passed to the SecretManagerServiceClient constructor. Setting GOOGLEAPPLICATIONCREDENTIALS at runtime works, but passing the key file path directly does not.

The Google-recommended approach for AWS-to-GCP auth is Workload Identity Federation instead of long-lived service-account keys: configure a workload identity pool for the AWS account and use google.auth with the external-account credentials file. It avoids key-file path issues entirely. As a fallback, setting process.env.GOOGLEAPPLICATIONCREDENTIALS at runtime before constructing the client works.

Source: https://github.com/googleapis/nodejs-secret-manager/issues/196

Source: https://github.com/googleapis/nodejs-secret-manager/issues/196