-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): support hotswapping Lambda functions that use Docker images (
#18319) closes #18302 We must just update `ImageUri` with the new ECR image url. PR for `InlineCode` hotswap: #18408 `----` *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
3 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/aws-cdk/test/api/hotswap/lambda-functions-docker-hotswap-deployments.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Lambda } from 'aws-sdk'; | ||
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 hotswapMockSdkProvider: setup.HotswapMockSdkProvider; | ||
|
||
beforeEach(() => { | ||
hotswapMockSdkProvider = setup.setupHotswapTests(); | ||
mockUpdateLambdaCode = jest.fn(); | ||
mockTagResource = jest.fn(); | ||
mockUntagResource = jest.fn(); | ||
hotswapMockSdkProvider.stubLambda({ | ||
updateFunctionCode: mockUpdateLambdaCode, | ||
tagResource: mockTagResource, | ||
untagResource: mockUntagResource, | ||
}); | ||
}); | ||
|
||
test('calls the updateLambdaCode() API when it receives only a code difference in a Lambda function', async () => { | ||
// GIVEN | ||
setup.setCurrentCfnStackTemplate({ | ||
Resources: { | ||
Func: { | ||
Type: 'AWS::Lambda::Function', | ||
Properties: { | ||
Code: { | ||
ImageUri: 'current-image', | ||
}, | ||
FunctionName: 'my-function', | ||
}, | ||
Metadata: { | ||
'aws:asset:path': 'old-path', | ||
}, | ||
}, | ||
}, | ||
}); | ||
const cdkStackArtifact = setup.cdkStackArtifactOf({ | ||
template: { | ||
Resources: { | ||
Func: { | ||
Type: 'AWS::Lambda::Function', | ||
Properties: { | ||
Code: { | ||
ImageUri: 'new-image', | ||
}, | ||
FunctionName: 'my-function', | ||
}, | ||
Metadata: { | ||
'aws:asset:path': 'new-path', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
// WHEN | ||
const deployStackResult = await hotswapMockSdkProvider.tryHotswapDeployment(cdkStackArtifact); | ||
|
||
// THEN | ||
expect(deployStackResult).not.toBeUndefined(); | ||
expect(mockUpdateLambdaCode).toHaveBeenCalledWith({ | ||
FunctionName: 'my-function', | ||
ImageUri: 'new-image', | ||
}); | ||
}); |