* Get the UpstreamId from APIG triggers for a given function. * * @param functionId - The function ID to get triggers for * @returns The UpstreamId from the first APIG trigger found, or null
(functionId: string)
| 325 | * @returns The UpstreamId from the first APIG trigger found, or null |
| 326 | */ |
| 327 | private async getApigTrigger(functionId: string): Promise<string | null> { |
| 328 | const body = JSON.stringify({ |
| 329 | FunctionId: functionId, |
| 330 | }); |
| 331 | |
| 332 | const response = await request( |
| 333 | 'POST', |
| 334 | new Date(), |
| 335 | {}, |
| 336 | {}, |
| 337 | this.accessKey, |
| 338 | this.secretKey, |
| 339 | '', |
| 340 | 'ListTriggers', |
| 341 | body, |
| 342 | this.region, |
| 343 | ); |
| 344 | |
| 345 | if (response && typeof response === 'object') { |
| 346 | const result = response.Result || {}; |
| 347 | const items = result.Items || []; |
| 348 | |
| 349 | for (const item of items) { |
| 350 | if (item.Type === 'apig') { |
| 351 | const detailedConfig = item.DetailedConfig || '{}'; |
| 352 | try { |
| 353 | const config = JSON.parse(detailedConfig); |
| 354 | const upstreamId = config.UpstreamId; |
| 355 | if (upstreamId) { |
| 356 | return upstreamId; |
| 357 | } |
| 358 | } catch (error) { |
| 359 | console.error(`Failed to parse DetailedConfig: ${detailedConfig}`); |
| 360 | continue; |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | return null; |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Get structured domains from APIG routes using the upstream ID. |
no test coverage detected