diff --git a/packages/aws-cdk/lib/api/hotswap/appsync-mapping-templates.ts b/packages/aws-cdk/lib/api/hotswap/appsync-mapping-templates.ts index b6be17cbf..3f4726f97 100644 --- a/packages/aws-cdk/lib/api/hotswap/appsync-mapping-templates.ts +++ b/packages/aws-cdk/lib/api/hotswap/appsync-mapping-templates.ts @@ -1,6 +1,7 @@ import type { GetSchemaCreationStatusCommandOutput, GetSchemaCreationStatusCommandInput, + FunctionConfiguration, } from '@aws-sdk/client-appsync'; import { type ChangeHotswapResult, @@ -14,6 +15,8 @@ import type { SDK } from '../aws-auth'; import type { EvaluateCloudFormationTemplate } from '../evaluate-cloudformation-template'; +type ApiId = string; + export async function isHotswappableAppSyncChange( logicalId: string, change: HotswappableChangeCandidate, @@ -55,6 +58,7 @@ export async function isHotswappableAppSyncChange( } else { physicalName = arn; } + const functions: Record = {}; ret.push({ hotswappable: true, resourceType: change.newValue.Type, @@ -116,8 +120,10 @@ export async function isHotswappableAppSyncChange( delete sdkRequestObject.runtime; } - const functions = await sdk.appsync().listFunctions({ apiId: sdkRequestObject.apiId }); - const { functionId } = functions.find((fn) => fn.name === physicalName) ?? {}; + if (!functions.hasOwnProperty(sdkRequestObject.apiId)) { + functions[sdkRequestObject.apiId] = await sdk.appsync().listFunctions({ apiId: sdkRequestObject.apiId }); + } + const { functionId } = functions[sdkRequestObject.apiId].find((fn) => fn.name === physicalName) ?? {}; // Updating multiple functions at the same time or along with graphql schema results in `ConcurrentModificationException` await exponentialBackOffRetry( () =>