Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): hotswapping appsync functions fails when API does not return function on the first page #31406

Merged
merged 9 commits into from
Sep 17, 2024
19 changes: 17 additions & 2 deletions packages/aws-cdk/lib/api/hotswap/appsync-mapping-templates.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetSchemaCreationStatusRequest, GetSchemaCreationStatusResponse } from 'aws-sdk/clients/appsync';
import { GetSchemaCreationStatusRequest, GetSchemaCreationStatusResponse, ListFunctionsResponse, FunctionConfiguration } from 'aws-sdk/clients/appsync';
import { ChangeHotswapResult, classifyChanges, HotswappableChangeCandidate, lowerCaseFirstCharacter, transformObjectKeys } from './common';
import { ISDK } from '../aws-auth';

Expand Down Expand Up @@ -96,7 +96,7 @@ export async function isHotswappableAppSyncChange(
delete sdkRequestObject.runtime;
}

const { functions } = await sdk.appsync().listFunctions({ apiId: sdkRequestObject.apiId }).promise();
const functions = await getAppSyncFunctions(sdk, sdkRequestObject.apiId!, undefined);
const { functionId } = functions?.find(fn => fn.name === physicalName) ?? {};
// Updating multiple functions at the same time or along with graphql schema results in `ConcurrentModificationException`
await simpleRetry(
Expand Down Expand Up @@ -155,3 +155,18 @@ async function simpleRetry(fn: () => Promise<any>, numOfRetries: number, errorCo
async function sleep(ms: number) {
return new Promise(ok => setTimeout(ok, ms));
}

/**
* Get all functions for a given AppSync API by iterating through the paginated list of functions
*/
async function getAppSyncFunctions(sdk: ISDK, apiId: string, nextToken: string | undefined): Promise<FunctionConfiguration[]> {
const ret = new Array<FunctionConfiguration>();
kaizencc marked this conversation as resolved.
Show resolved Hide resolved
return sdk.appsync().listFunctions({ apiId, nextToken }).promise()
.then(async (listFunctionsResponse: ListFunctionsResponse) => {
ret.push(...(listFunctionsResponse.functions ?? []));
if (listFunctionsResponse.nextToken) {
ret.push(...await getAppSyncFunctions(sdk, apiId, listFunctionsResponse.nextToken));
}
return ret;
});
}
Loading