Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ module.exports = {
'/cypress',
'/packages/amplify-appsync-simulator/public',
'/packages/amplify-cli/scripts/post-install.js',
'/packages/amplify-migration-e2e-system/src/test-setup.ts',

// Ignore project/file templates
'function-template-dir',
Expand Down
38 changes: 38 additions & 0 deletions amplify-migration-apps/app-4/migration-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"app": {
"name": "app-4",
"description": "Fitness goal tracker with progress photos and authentication logging",
"framework": "react"
},
"categories": {
"api": {
"type": "GraphQL",
"schema": "schema.graphql",
"authModes": ["API_KEY", "COGNITO_USER_POOLS"]
},
"auth": {
"signInMethods": ["email"],
"socialProviders": []
},
"storage": {
"buckets": [
{
"name": "progress-photos",
"access": ["auth", "guest"]
}
]
},
"function": {
"functions": [
{
"name": "quotegenerator",
"runtime": "nodejs",
"template": "hello-world"
}
]
},
"hosting": {
"type": "amplify-console"
}
}
}
78 changes: 78 additions & 0 deletions amplify-migration-apps/app-5/migration-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"app": {
"name": "app-5",
"description": "Advanced fitness goal tracker with stress-test schema, comprehensive logging, and authentication triggers",
"framework": "react"
},
"categories": {
"api": {
"type": "GraphQL",
"schema": "schema.graphql",
"authModes": ["API_KEY", "COGNITO_USER_POOLS"],
"customQueries": ["getRandomQuote"]
},
"auth": {
"signInMethods": ["email"],
"socialProviders": [],
"userPoolConfig": {
"emailVerification": true,
"mfaConfiguration": {
"mode": "OFF"
}
},
"triggers": {
"postAuthentication": {
"functionName": "PostAuthentication",
"description": "Logs user authentication events to S3"
}
}
},
"storage": {
"buckets": [
{
"name": "fitnessappstorage",
"access": ["auth", "guest"],
"cors": {
"allowedOrigins": ["*"],
"allowedMethods": ["GET", "POST", "PUT", "DELETE"],
"allowedHeaders": ["*"],
"maxAge": 3000
}
}
]
},
"function": {
"functions": [
{
"name": "quotegenerator",
"runtime": "nodejs",
"template": "hello-world",
"handler": "index.handler",
"description": "Generates motivational fitness quotes"
},
{
"name": "PostAuthentication",
"runtime": "nodejs",
"template": "trigger",
"handler": "index.handler",
"description": "Cognito post-authentication trigger for logging user activity",
"permissions": [
"s3:PutObject",
"s3:GetObject"
],
"environment": {
"STORAGE_FITNESSAPPSTORAGE_BUCKETNAME": "fitnessappbucket"
}
}
]
},
"hosting": {
"type": "amplify-console",
"buildSettings": {
"buildCommand": "npm run build",
"outputDirectory": "dist",
"nodeVersion": "25"
}
}
}
}
39 changes: 39 additions & 0 deletions amplify-migration-apps/discussions/migration-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"app": {
"name": "discussions",
"description": "Discussion app with phone authentication and activity logging"
},
"categories": {
"api": {
"type": "GraphQL",
"schema": "schema.graphql",
"authModes": ["API_KEY", "COGNITO_USER_POOLS"],
"customQueries": ["getUserActivity"],
"customMutations": ["logActivity"]
},
"auth": {
"signInMethods": ["phone"],
"socialProviders": []
},
"storage": {
"buckets": [
{
"name": "countsTable",
"access": ["auth"]
}
]
},
"function": {
"functions": [
{
"name": "activityLogger",
"runtime": "nodejs",
"template": "hello-world"
}
]
},
"hosting": {
"type": "amplify-console"
}
}
}
37 changes: 37 additions & 0 deletions amplify-migration-apps/media-vault/migration-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"app": {
"name": "media-vault",
"description": "Personal media vault with social authentication and thumbnail generation"
},
"categories": {
"api": {
"type": "GraphQL",
"schema": "schema.graphql",
"authModes": ["COGNITO_USER_POOLS", "API_KEY"]
},
"auth": {
"signInMethods": ["email", "phone"],
"socialProviders": ["facebook", "google"]
},
"storage": {
"buckets": [
{
"name": "media",
"access": ["auth", "guest"]
}
]
},
"function": {
"functions": [
{
"name": "thumbnailgen",
"runtime": "nodejs",
"template": "hello-world"
}
]
},
"hosting": {
"type": "amplify-console"
}
}
}
39 changes: 39 additions & 0 deletions amplify-migration-apps/product-catalog/migration-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"app": {
"name": "app-1",
"description": "Product catalog with role-based authentication and inventory management",
"framework": "react"
},
"categories": {
"api": {
"type": "GraphQL",
"schema": "schema.graphql",
"authModes": ["IAM", "API_KEY", "COGNITO_USER_POOLS"],
"customQueries": ["checkLowStock"]
},
"auth": {
"signInMethods": ["email"],
"socialProviders": []
},
"storage": {
"buckets": [
{
"name": "productimages3bucket",
"access": ["auth"]
}
]
},
"function": {
"functions": [
{
"name": "lowstockproductcatalog",
"runtime": "nodejs",
"template": "hello-world"
}
]
},
"hosting": {
"type": "amplify-console"
}
}
}
38 changes: 38 additions & 0 deletions amplify-migration-apps/project-boards/migration-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"app": {
"name": "project-boards",
"description": "Project board app with authentication and file storage",
"framework": "react"
},
"categories": {
"api": {
"type": "GraphQL",
"schema": "schema.graphql",
"authModes": ["API_KEY", "COGNITO_USER_POOLS"]
},
"auth": {
"signInMethods": ["email"],
"socialProviders": []
},
"storage": {
"buckets": [
{
"name": "images",
"access": ["auth", "guest"]
}
]
},
"function": {
"functions": [
{
"name": "quotegenerator",
"runtime": "nodejs",
"template": "hello-world"
}
]
},
"hosting": {
"type": "amplify-console"
}
}
}
57 changes: 52 additions & 5 deletions packages/amplify-e2e-core/src/init/initProjectHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,49 @@
/* eslint-disable func-style */
import { EOL } from 'os';
import { v4 as uuid } from 'uuid';
import * as fs from 'fs-extra';
import * as ini from 'ini';
import { pathManager } from '@aws-amplify/amplify-cli-core';
import { nspawn as spawn, getCLIPath, singleSelect, addCircleCITags } from '..';
import { KEY_DOWN_ARROW } from '../utils';
import { amplifyRegions } from '../configure';

/**
* Gets the index of a profile in the AWS config file.
* The Amplify CLI uses the config file order for profile selection.
* Config file sections are named "default" or "profile <name>".
* @param profileName The name of the profile to find
* @returns The index of the profile in the list (0-based), or 0 if not found
*/
function getProfileIndex(profileName: string): number {
try {
const configPath = pathManager.getAWSConfigFilePath();
if (!fs.existsSync(configPath)) {
console.log('[getProfileIndex] Config file not found, defaulting to index 0');
return 0;
}
const configContents = ini.parse(fs.readFileSync(configPath, 'utf-8'));
// Config file uses "default" and "profile <name>" as section names
// Extract actual profile names from section names
const profiles = Object.keys(configContents).map((section) => {
if (section === 'default') {
return 'default';
}
// Remove "profile " prefix if present
return section.replace(/^profile\s+/, '');
});
const index = profiles.indexOf(profileName);
console.log(`[getProfileIndex] Available profiles: ${profiles.join(', ')}`);
if (index === -1) {
throw Error(`Profile: ${profileName} not found.`);
}
console.log(`[getProfileIndex] Profile: ${profileName}, found at index: ${index}`);
return index;
} catch (error) {
throw Error(`[getProfileIndex] Error reading config file: ${(error as Error).message}`);
}
}

const defaultSettings = {
name: EOL,
// eslint-disable-next-line spellcheck/spell-checker
Expand All @@ -33,6 +72,7 @@ const defaultSettings = {

export function initJSProjectWithProfile(cwd: string, settings?: Partial<typeof defaultSettings>): Promise<void> {
const s = { ...defaultSettings, ...settings };

let env;

if (s.disableAmplifyAppCreation === true) {
Expand All @@ -46,6 +86,7 @@ export function initJSProjectWithProfile(cwd: string, settings?: Partial<typeof
const cliArgs = ['init'];
const providerConfigSpecified = !!s.providerConfig && typeof s.providerConfig === 'object';
if (providerConfigSpecified) {
console.log('initJSProjectWithProfile: provider config specified: ', s.providerConfig);
cliArgs.push('--providers', JSON.stringify(s.providerConfig));
}

Expand Down Expand Up @@ -93,12 +134,20 @@ export function initJSProjectWithProfile(cwd: string, settings?: Partial<typeof
.sendCarriageReturn();

if (!providerConfigSpecified) {
const profileIndex = getProfileIndex(s.profileName);
console.log('initJSProjectWithProfile: no provider config specified, using profile', s.profileName, 'at index', profileIndex);

chain
.wait('Using default provider awscloudformation')
.wait('Select the authentication method you want to use:')
.sendCarriageReturn()
.wait('Please choose the profile you want to use')
.sendLine(s.profileName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was as bug in the original code, that was unused. Sending profile name in this way did not select the expected profile, as it is not a typed input. It is only a selection via up/down arrow keys.

.wait('Please choose the profile you want to use');

if (profileIndex > 0) {
chain.sendKeyDown(profileIndex);
}

chain.sendCarriageReturn();
}

if (s.includeUsageDataPrompt) {
Expand Down Expand Up @@ -309,9 +358,7 @@ export function initProjectWithAccessKey(
const chain = spawn(getCLIPath(), ['init'], {
cwd,
stripColors: true,
env: {
CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: '1',
},
env: { CLI_DEV_INTERNAL_DISABLE_AMPLIFY_APP_CREATION: s.disableAmplifyAppCreation ? '1' : '0' },
})
.wait('Do you want to continue with Amplify Gen 1?')
.sendYes()
Expand Down
Loading
Loading