-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add hotswap to canaries * try this * try this * try this * try this * try this * change this * pr feedback * pr feedback
- Loading branch information
Showing
13 changed files
with
242 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
--- |
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
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
5 changes: 5 additions & 0 deletions
5
...n-tests/src/test-project-setup/live-dependency-health-checks-projects/README.md
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,5 @@ | ||
Projects in this directory are meant for `live-dependency-health-checks` (aka canaries). | ||
|
||
1. These projects must not be used in e2e tests to provide deep functional coverage. | ||
2. These projects must be lightweight to provide fast runtime and stability. | ||
3. These projects must cover only P0 scenarios we care most. (That are not covered by "getting started" flow, aka `create-amplify`). |
143 changes: 143 additions & 0 deletions
143
...ts/src/test-project-setup/live-dependency-health-checks-projects/function_code_hotswap.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,143 @@ | ||
import fs from 'fs/promises'; | ||
import { createEmptyAmplifyProject } from '../create_empty_amplify_project.js'; | ||
import { CloudFormationClient } from '@aws-sdk/client-cloudformation'; | ||
import { TestProjectBase, TestProjectUpdate } from '../test_project_base.js'; | ||
import { fileURLToPath, pathToFileURL } from 'node:url'; | ||
import path from 'path'; | ||
import { TestProjectCreator } from '../test_project_creator.js'; | ||
import { AmplifyClient } from '@aws-sdk/client-amplify'; | ||
import { e2eToolingClientConfig } from '../../e2e_tooling_client_config.js'; | ||
import { execa } from 'execa'; | ||
|
||
/** | ||
* Creates test projects with function hotswap. | ||
*/ | ||
export class FunctionCodeHotswapTestProjectCreator | ||
implements TestProjectCreator | ||
{ | ||
readonly name = 'function-code-hotswap'; | ||
|
||
/** | ||
* Creates project creator. | ||
*/ | ||
constructor( | ||
private readonly cfnClient: CloudFormationClient = new CloudFormationClient( | ||
e2eToolingClientConfig | ||
), | ||
private readonly amplifyClient: AmplifyClient = new AmplifyClient( | ||
e2eToolingClientConfig | ||
) | ||
) {} | ||
|
||
createProject = async (e2eProjectDir: string): Promise<TestProjectBase> => { | ||
const { projectName, projectRoot, projectAmplifyDir } = | ||
await createEmptyAmplifyProject(this.name, e2eProjectDir); | ||
|
||
const project = new FunctionCodeHotswapTestTestProject( | ||
projectName, | ||
projectRoot, | ||
projectAmplifyDir, | ||
this.cfnClient, | ||
this.amplifyClient | ||
); | ||
await fs.cp( | ||
project.sourceProjectAmplifyDirURL, | ||
project.projectAmplifyDirPath, | ||
{ | ||
recursive: true, | ||
} | ||
); | ||
|
||
// we're not starting from create flow. install latest versions of dependencies. | ||
await execa( | ||
'npm', | ||
[ | ||
'install', | ||
'@aws-amplify/backend', | ||
'@aws-amplify/backend-cli', | ||
'aws-cdk@^2', | ||
'aws-cdk-lib@^2', | ||
'constructs@^10.0.0', | ||
'typescript@^5.0.0', | ||
'tsx', | ||
'esbuild', | ||
], | ||
{ | ||
cwd: projectRoot, | ||
stdio: 'inherit', | ||
} | ||
); | ||
|
||
return project; | ||
}; | ||
} | ||
|
||
/** | ||
* Test project with function hotswap. | ||
*/ | ||
class FunctionCodeHotswapTestTestProject extends TestProjectBase { | ||
// Note that this is pointing to the non-compiled project directory | ||
// This allows us to test that we are able to deploy js, cjs, ts, etc. without compiling with tsc first | ||
readonly sourceProjectRootPath = | ||
'../../../src/test-projects/live-dependency-health-checks-projects/function-code-hotswap'; | ||
|
||
readonly sourceProjectRootURL: URL = new URL( | ||
this.sourceProjectRootPath, | ||
import.meta.url | ||
); | ||
|
||
readonly sourceProjectAmplifyDirURL: URL = new URL( | ||
`${this.sourceProjectRootPath}/amplify`, | ||
import.meta.url | ||
); | ||
|
||
private readonly sourceProjectUpdateDirURL: URL = new URL( | ||
`${this.sourceProjectRootPath}/hotswap-update-files`, | ||
import.meta.url | ||
); | ||
|
||
/** | ||
* Create a test project instance. | ||
*/ | ||
constructor( | ||
name: string, | ||
projectDirPath: string, | ||
projectAmplifyDirPath: string, | ||
cfnClient: CloudFormationClient, | ||
amplifyClient: AmplifyClient | ||
) { | ||
super( | ||
name, | ||
projectDirPath, | ||
projectAmplifyDirPath, | ||
cfnClient, | ||
amplifyClient | ||
); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
override async getUpdates(): Promise<TestProjectUpdate[]> { | ||
return [ | ||
{ | ||
replacements: [ | ||
this.getUpdateReplacementDefinition('func-src/handler.ts'), | ||
], | ||
}, | ||
]; | ||
} | ||
|
||
private getUpdateReplacementDefinition = (suffix: string) => ({ | ||
source: this.getSourceProjectUpdatePath(suffix), | ||
destination: this.getTestProjectPath(suffix), | ||
}); | ||
|
||
private getSourceProjectUpdatePath = (suffix: string) => | ||
pathToFileURL( | ||
path.join(fileURLToPath(this.sourceProjectUpdateDirURL), suffix) | ||
); | ||
|
||
private getTestProjectPath = (suffix: string) => | ||
pathToFileURL(path.join(this.projectAmplifyDirPath, suffix)); | ||
} |
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
5 changes: 5 additions & 0 deletions
5
...ration-tests/src/test-projects/live-dependency-health-checks-projects/README.md
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,5 @@ | ||
Projects in this directory are meant for `live-dependency-health-checks` (aka canaries). | ||
|
||
1. These projects must not be used in e2e tests to provide deep functional coverage. | ||
2. These projects must be lightweight to provide fast runtime and stability. | ||
3. These projects must cover only P0 scenarios we care most. (That are not covered by "getting started" flow, aka `create-amplify`). |
4 changes: 4 additions & 0 deletions
4
...-projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/backend.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,4 @@ | ||
import { defineBackend } from '@aws-amplify/backend'; | ||
import { nodeFunc } from './function.js'; | ||
|
||
defineBackend({ nodeFunc }); |
6 changes: 6 additions & 0 deletions
6
.../live-dependency-health-checks-projects/function-code-hotswap/amplify/func-src/handler.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,6 @@ | ||
/** | ||
* Dummy lambda handler. | ||
*/ | ||
export const handler = async () => { | ||
return 'Hello'; | ||
}; |
7 changes: 7 additions & 0 deletions
7
...projects/live-dependency-health-checks-projects/function-code-hotswap/amplify/function.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,7 @@ | ||
import { defineFunction } from '@aws-amplify/backend'; | ||
|
||
export const nodeFunc = defineFunction({ | ||
name: 'nodeFunction', | ||
entry: './func-src/handler.ts', | ||
timeoutSeconds: 5, | ||
}); |
6 changes: 6 additions & 0 deletions
6
...ncy-health-checks-projects/function-code-hotswap/hotswap-update-files/func-src/handler.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,6 @@ | ||
/** | ||
* Non-functional change to the lambda, but it triggers a sandbox hotswap | ||
*/ | ||
export const handler = async () => { | ||
return 'Hello V2'; | ||
}; |