11import {
22 GetFunctionCommand ,
3- GetFunctionUrlConfigCommand ,
43 LambdaClient ,
54 ListFunctionsCommand ,
65 UpdateFunctionConfigurationCommand ,
@@ -11,7 +10,12 @@ import { acquireLock, releaseLock } from "../lib/locks";
1110import Logger from "../lib/logger" ;
1211import { put } from "../lib/database" ;
1312
14- const supportedRuntimes = [ "nodejs16.x" , "nodejs18.x" , "nodejs20.x" , "nodejs22.x" ] ;
13+ const supportedRuntimes = [
14+ "nodejs16.x" ,
15+ "nodejs18.x" ,
16+ "nodejs20.x" ,
17+ "nodejs22.x" ,
18+ ] ;
1519const lambdaExecWrapper = "/opt/nodejs/tracer_wrapper" ;
1620
1721const logger = new Logger ( "auto-trace" ) ;
@@ -36,28 +40,7 @@ const getAccountLambdas = async () => {
3640 return lambdas ;
3741} ;
3842
39- const getEdgeEndpoint = async ( lambdas ) => {
40- const lambdaName = `${ process . env . SERVICE } -${ process . env . STAGE } -main` ;
41-
42- try {
43- const command = new GetFunctionUrlConfigCommand ( {
44- FunctionName : lambdaName ,
45- } ) ;
46-
47- const res = await new LambdaClient ( ) . send ( command ) ;
48-
49- return res . FunctionUrl ?. replace ( "https://" , "" ) . replace ( "/" , "" ) ;
50- } catch ( e ) {
51- if ( e . name === "ResourceNotFoundException" ) {
52- throw new Error (
53- `Lambda ${ lambdaName } not found - could not determine edge endpoint.` ,
54- ) ;
55- }
56- throw e ;
57- }
58- } ;
59-
60- const updateLambda = async ( lambda , arnBase , edgeEndpoint ) => {
43+ const updateLambda = async ( lambda , arnBase , queue , queueRegion ) => {
6144 const command = new UpdateFunctionConfigurationCommand ( {
6245 FunctionName : lambda . FunctionName ,
6346 Layers : [
@@ -70,7 +53,8 @@ const updateLambda = async (lambda, arnBase, edgeEndpoint) => {
7053 ...( lambda . Environment || { } ) ,
7154 Variables : {
7255 ...( lambda . Environment ?. Variables || { } ) ,
73- AUTO_TRACE_HOST : edgeEndpoint ,
56+ AUTO_TRACE_QUEUE_URL : queue ,
57+ AUTO_TRACE_QUEUE_REGION : queueRegion ,
7458 AWS_LAMBDA_EXEC_WRAPPER : lambdaExecWrapper ,
7559 } ,
7660 } ,
@@ -127,7 +111,11 @@ export const autoTrace = async () => {
127111 }
128112
129113 // Get our Lambda URL endpoint for the collector
130- const edgeEndpoint = await getEdgeEndpoint ( ) ;
114+ const queue = process . env . QUEUE_URL ;
115+ const queueRegion = process . env . QUEUE_REGION || "eu-west-1" ;
116+ if ( ! queue ) {
117+ throw new Error ( "QUEUE_URL is not defined" ) ;
118+ }
131119
132120 // Make sure we lock so that only one process is updating lambdas
133121 const lockAcquired = await acquireLock ( "auto-trace" ) ;
@@ -137,7 +125,7 @@ export const autoTrace = async () => {
137125 }
138126
139127 // List all the lambda functions in the AWS account
140- const lambdas = await getAccountLambdas ( ) ;
128+ let lambdas = await getAccountLambdas ( ) ;
141129 logger . info ( `Found ${ lambdas . length } lambdas in the account` ) ;
142130
143131 // Update qualifying lambdas
@@ -151,7 +139,7 @@ export const autoTrace = async () => {
151139 const isTraceStack = envVars . LAMBDA_LAYER_ARN === arn ;
152140 const isUpdating = lambda . LastUpdateStatus === "InProgress" ;
153141 const hasDisableEnvVar = envVars . AUTO_TRACE_EXCLUDE ;
154- const hasWrongEndpoint = envVars . AUTO_TRACE_HOST !== edgeEndpoint ;
142+ const hasWrongEndpoint = envVars . AUTO_TRACE_QUEUE_URL !== queue ;
155143 const hasOtherWrapper =
156144 envVars . AWS_LAMBDA_EXEC_WRAPPER &&
157145 envVars . AWS_LAMBDA_EXEC_WRAPPER !== lambdaExecWrapper ;
@@ -192,7 +180,7 @@ export const autoTrace = async () => {
192180 }
193181
194182 try {
195- await updateLambda ( lambda , arnBase , edgeEndpoint ) ;
183+ await updateLambda ( lambda , arnBase , queue , queueRegion ) ;
196184
197185 logger . info ( `✓ Updated ${ lambda . FunctionName } ` ) ;
198186 await saveFunctionInfo ( lambda , "enabled" ) ;
0 commit comments