Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
corymhall committed Jan 21, 2022
1 parent 4333dfe commit 757eb20
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 22 deletions.
13 changes: 7 additions & 6 deletions packages/aws-cdk/lib/api/hotswap/lambda-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,9 @@ class LambdaFunctionHotswapOperation implements HotswapOperation {
ZipFile: resource.code.functionCodeZip,
}).promise();

await this.waitForLastUpdateStatusComplete(updateFunctionCodeResponse, lambda);
await this.waitForLambdasCodeUpdateToFinish(updateFunctionCodeResponse, lambda);

// only if the code changed is there any point in publishing a new Version
if (this.lambdaFunctionResource.publishVersion) {
const publishVersionPromise = lambda.publishVersion({
FunctionName: this.lambdaFunctionResource.physicalName,
Expand Down Expand Up @@ -304,14 +305,14 @@ class LambdaFunctionHotswapOperation implements HotswapOperation {
* or very slowly. For example, Zip based functions _not_ in a VPC can take ~1 second whereas VPC
* or Container functions can take ~25 seconds (and 'idle' VPC functions can take minutes).
*/
private async waitForLastUpdateStatusComplete(currentFunctionConfiguration: AWS.Lambda.FunctionConfiguration, lambda: AWS.Lambda): Promise<void> {
private async waitForLambdasCodeUpdateToFinish(currentFunctionConfiguration: AWS.Lambda.FunctionConfiguration, lambda: AWS.Lambda): Promise<void> {
const functionIsInVpcOrUsesDockerForCode = currentFunctionConfiguration.VpcConfig?.VpcId ||
currentFunctionConfiguration.PackageType === 'Image';

// if the function is deployed in a VPC or if it is a container image function
// then the update will take much longer and we can wait longer between checks
// otherwise, the update will be quick, so a 1-second delay is fine
const delaySeconds = currentFunctionConfiguration.VpcConfig?.VpcId ||
currentFunctionConfiguration.PackageType === 'Image'
? 5
: 1;
const delaySeconds = functionIsInVpcOrUsesDockerForCode ? 5 : 1;

// configure a custom waiter to wait for the function update to complete
(lambda as any).api.waiters.updateFunctionCodeToFinish = {
Expand Down
12 changes: 0 additions & 12 deletions packages/aws-cdk/test/api/hotswap/hotswap-deployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ beforeEach(() => {
mockGetEndpointSuffix = jest.fn(() => 'amazonaws.com');
hotswapMockSdkProvider.stubLambda({
updateFunctionCode: mockUpdateLambdaCode,
}, {
// these are needed for the waiter API that the Lambda service hotswap uses
api: {
waiters: {},
},
makeRequest() {
return {
promise: () => Promise.resolve({}),
response: {},
addListeners: () => {},
};
},
});
hotswapMockSdkProvider.setUpdateStateMachineMock(mockUpdateMachineDefinition);
hotswapMockSdkProvider.stubGetEndpointSuffix(mockGetEndpointSuffix);
Expand Down
9 changes: 7 additions & 2 deletions packages/aws-cdk/test/api/hotswap/hotswap-test-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ export class HotswapMockSdkProvider {
});
}

public stubLambda(stubs: SyncHandlerSubsetOf<AWS.Lambda>, additionalProperties: { [key: string]: any } = {}) {
public stubLambda(
stubs: SyncHandlerSubsetOf<AWS.Lambda>,
serviceStubs?: SyncHandlerSubsetOf<AWS.Service>,
additionalProperties: { [key: string]: any } = {},
): void {
this.mockSdkProvider.stubLambda(stubs, {
api: {
waiters: {},
Expand All @@ -95,11 +99,12 @@ export class HotswapMockSdkProvider {
addListeners: () => {},
};
},
...serviceStubs,
...additionalProperties,
});
}

public getLambdaApiWaiters() {
public getLambdaApiWaiters(): { [key: string]: any } {
return (this.mockSdkProvider.sdk.lambda() as any).api.waiters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let mockUpdateLambdaCode: (params: Lambda.Types.UpdateFunctionCodeRequest) => La
let mockTagResource: (params: Lambda.Types.TagResourceRequest) => {};
let mockUntagResource: (params: Lambda.Types.UntagResourceRequest) => {};
let hotswapMockSdkProvider: setup.HotswapMockSdkProvider;
let mockMakeRequest: (operation: string, params: any) => {};
let mockMakeRequest: (operation: string, params: any) => AWS.Request<any, AWS.AWSError>;

beforeEach(() => {
hotswapMockSdkProvider = setup.setupHotswapTests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as setup from './hotswap-test-setup';
let mockUpdateLambdaCode: (params: Lambda.Types.UpdateFunctionCodeRequest) => Lambda.Types.FunctionConfiguration;
let mockTagResource: (params: Lambda.Types.TagResourceRequest) => {};
let mockUntagResource: (params: Lambda.Types.UntagResourceRequest) => {};
let mockMakeRequest: (operation: string, params: any) => {};
let mockMakeRequest: (operation: string, params: any) => AWS.Request<any, AWS.AWSError>;
let hotswapMockSdkProvider: setup.HotswapMockSdkProvider;

beforeEach(() => {
Expand Down

0 comments on commit 757eb20

Please sign in to comment.