MCPcopy
hub / github.com/mongodb/node-mongodb-native / getFAASEnv

Function getFAASEnv

src/cmap/handshake/client_metadata.ts:242–316  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

240 * - `name` MUST be the last key in the Map returned.
241 */
242export function getFAASEnv(): Map<string, string | Int32> | null {
243 const {
244 AWS_EXECUTION_ENV = '',
245 AWS_LAMBDA_RUNTIME_API = '',
246 FUNCTIONS_WORKER_RUNTIME = '',
247 K_SERVICE = '',
248 FUNCTION_NAME = '',
249 VERCEL = '',
250 AWS_LAMBDA_FUNCTION_MEMORY_SIZE = '',
251 AWS_REGION = '',
252 FUNCTION_MEMORY_MB = '',
253 FUNCTION_REGION = '',
254 FUNCTION_TIMEOUT_SEC = '',
255 VERCEL_REGION = ''
256 } = process.env;
257
258 const isAWSFaaS =
259 AWS_EXECUTION_ENV.startsWith('AWS_Lambda_') || AWS_LAMBDA_RUNTIME_API.length > 0;
260 const isAzureFaaS = FUNCTIONS_WORKER_RUNTIME.length > 0;
261 const isGCPFaaS = K_SERVICE.length > 0 || FUNCTION_NAME.length > 0;
262 const isVercelFaaS = VERCEL.length > 0;
263
264 // Note: order matters, name must always be the last key
265 const faasEnv = new Map();
266
267 // When isVercelFaaS is true so is isAWSFaaS; Vercel inherits the AWS env
268 if (isVercelFaaS && !(isAzureFaaS || isGCPFaaS)) {
269 if (VERCEL_REGION.length > 0) {
270 faasEnv.set('region', VERCEL_REGION);
271 }
272
273 faasEnv.set('name', 'vercel');
274 return faasEnv;
275 }
276
277 if (isAWSFaaS && !(isAzureFaaS || isGCPFaaS || isVercelFaaS)) {
278 if (AWS_REGION.length > 0) {
279 faasEnv.set('region', AWS_REGION);
280 }
281
282 if (
283 AWS_LAMBDA_FUNCTION_MEMORY_SIZE.length > 0 &&
284 Number.isInteger(+AWS_LAMBDA_FUNCTION_MEMORY_SIZE)
285 ) {
286 faasEnv.set('memory_mb', new Int32(AWS_LAMBDA_FUNCTION_MEMORY_SIZE));
287 }
288
289 faasEnv.set('name', 'aws.lambda');
290 return faasEnv;
291 }
292
293 if (isAzureFaaS && !(isGCPFaaS || isAWSFaaS || isVercelFaaS)) {
294 faasEnv.set('name', 'azure.func');
295 return faasEnv;
296 }
297
298 if (isGCPFaaS && !(isAzureFaaS || isAWSFaaS || isVercelFaaS)) {
299 if (FUNCTION_REGION.length > 0) {

Callers 4

constructorMethod · 0.90
makeClientMetadataFunction · 0.85

Calls 1

setMethod · 0.80

Tested by

no test coverage detected