chore: use org child accounts with existing e2e test infra#14842
chore: use org child accounts with existing e2e test infra#14842
Conversation
eefbe59 to
389ebc6
Compare
I think we can make it simpler. We shouldn't need to shell out from typescript to typescript. Can the jest wrapper just call
|
674e522 to
7222393
Compare
Existing E2Es do not have a way to refresh credentials for org child accounts, only for the org parent account. Since we are running long-running tests on the child accounts, we need another mechanism for two-hop creds refresh. If we used the existing one, we would need to only run gen2-migration tests on a single account, which we have decided not to do. |
d498286 to
bc0f53b
Compare
fb0280a to
05ff875
Compare
Description of changes
Previously, gen2-migration E2E tests were hardcoded as 8 individual jobs in
e2e_workflow_base.ymlusing a custom buildspec. They deployed Amplify apps and ran the migration in a single account and region. They now run through the same split-and-execute pipeline as regular E2E tests — the split script auto-generates one CodeBuild job per migration app. The tests now run across multiple child accounts and regions. Adding a new migration app means adding a test file, not editing YAML.Each migration app gets a Jest test file in
amplify-e2e-tests/src/__tests__/gen2-migration/that callsApp.migrate()directly in-process.E2E flow
sequenceDiagram participant CB as CodeBuild Job participant Shell as _runE2ETestsLinux participant Jest as Jest test participant App as App.migrate() participant CM as CredentialManager participant STS as AWS STS CB->>Shell: source shared-scripts.sh && _runE2ETestsLinux Shell->>Shell: setAwsAccountCredentials → useChildAccountCredentials Note over Shell: Picks random child account X<br/>Sets AWS_ACCESS_KEY_ID/SECRET/TOKEN in env Shell->>Jest: yarn e2e (runs migration test file) Jest->>Jest: resolveChildAccountId()<br/>STS GetCallerIdentity → account X Jest->>Jest: process.env.CHILD_ACCOUNT_ID = X Jest->>App: new App(appName, undefined) App->>CM: CredentialManager reads CHILD_ACCOUNT_ID = X App->>CM: refreshCredentials() CM->>STS: fromContainerMetadata() → TEST_ACCOUNT_ROLE (parent) STS-->>CM: Parent session CM->>STS: Parent → OrganizationAccountAccessRole (account X) STS-->>CM: Child session (account X) CM->>CM: Write to migration profile (account X) Note over App: getEnv() strips AWS credential env vars<br/>so subprocesses use only the profile App->>App: amplify init/push (uses migration profile → account X) App->>App: cdk bootstrap / ampx sandbox (uses migration profile → account X) App-->>Jest: migrate() resolves Jest->>App: app.getClientConfig() App-->>Jest: { credentials: fromIni({ profile }) } Jest->>Jest: new Teardown(name, clientConfig).clean()Key design decisions
Single account for Gen1 and Gen2:
resolveChildAccountId()reads the account from the shell-level env vars (via STS GetCallerIdentity). TheCredentialManagerthen assumes into that same account. This ensures Gen1 commands and Gen2 commands target the same account — the DynamoDB tables created byamplify pushare found byampx sandbox.getEnv()strips credential env vars: Without this, the AWS CLI and CDK prefer env var credentials overAWS_PROFILE, causing operations to run in the wrong account (the shell-level account instead of the profile account).fromContainerMetadata()for hop 1: TheCredentialManagerexplicitly uses container metadata credentials for the first hop, bypassing any env var credentials. This lets it refresh mid-run without depending on the shell-level session.Teardownaccepts client config:Teardownnow takes aclientConfigobject (fromApp.getClientConfig()) instead of a profile string. This reuses the same credential provider that worked throughout the migration, avoiding issues wherefromInican't resolve a freshly-written profile.Changes
amplify-e2e-tests/src/__tests__/gen2-migration/, one per app, plus a shared helpersplitTestsV3call for migration tests (isMigration=true,BUILD_GENERAL1_LARGE,DISABLE_COVERAGE=1)migrate_*jobs frome2e_workflow_base.ymlcodebuild_specs/run_gen2_migration_e2e.ymland the_runGen2MigrationE2E/runGen2MigrationE2eTestCbshell functions fromshared-scripts.shCredentialManager.refresh()now usesfromContainerMetadata()explicitly instead of the default provider chainApp.getEnv()strips credential env vars so subprocesses use only the profileTeardownconstructor accepts a client config object instead of a profile stringIssue #, if available
Description of how you validated changes
BUILD_GENERAL1_LARGE), andDISABLE_COVERAGE=1toContaininstead oftoEqual) passesChecklist
yarn testpassesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.