diff --git a/packages/amplify-category-api/provider-utils/awscloudformation/service-walkthroughs/appSync-walkthrough.js b/packages/amplify-category-api/provider-utils/awscloudformation/service-walkthroughs/appSync-walkthrough.js index 8b2057083dd..4b02cb91ae5 100644 --- a/packages/amplify-category-api/provider-utils/awscloudformation/service-walkthroughs/appSync-walkthrough.js +++ b/packages/amplify-category-api/provider-utils/awscloudformation/service-walkthroughs/appSync-walkthrough.js @@ -778,6 +778,8 @@ async function askApiKeyQuestions() { message: 'After how many days from now the API key should expire (1-365):', default: 7, validate: validateDays, + // adding filter to ensure parsing input as int -> https://github.com/SBoudrias/Inquirer.js/issues/866 + filter: value => (isNaN(parseInt(value, 10)) ? value : parseInt(value, 10)), }, ]; @@ -832,7 +834,6 @@ async function askOpenIDConnectQuestions() { function validateDays(input) { const isValid = /^\d+$/.test(input); const days = isValid ? parseInt(input, 10) : 0; - if (!isValid || days < 1 || days > 365) { return 'Number of days must be between 1 and 365.'; } diff --git a/packages/amplify-e2e-core/src/categories/api.ts b/packages/amplify-e2e-core/src/categories/api.ts index 682994b24ba..30f1585e525 100644 --- a/packages/amplify-e2e-core/src/categories/api.ts +++ b/packages/amplify-e2e-core/src/categories/api.ts @@ -57,7 +57,7 @@ export function addApiWithSchema(cwd: string, schemaFile: string) { .wait(/.*Enter a description for the API key.*/) .sendCarriageReturn() .wait(/.*After how many days from now the API key should expire.*/) - .sendCarriageReturn() + .sendLine('1') .wait(/.*Do you want to configure advanced settings for the GraphQL API.*/) .sendCarriageReturn() .wait('Do you have an annotated GraphQL schema?') diff --git a/packages/graphql-auth-transformer/src/resources.ts b/packages/graphql-auth-transformer/src/resources.ts index 17bb677c862..188be1fef46 100644 --- a/packages/graphql-auth-transformer/src/resources.ts +++ b/packages/graphql-auth-transformer/src/resources.ts @@ -105,7 +105,10 @@ export class ResourceFactory { if (apiKeyConfig && apiKeyConfig.apiKeyExpirationDays) { expirationDays = apiKeyConfig.apiKeyExpirationDays; } - const expirationDateInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * expirationDays; /* d */ + // add delay expiration time is valid upon resource creation + let expirationDateInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * expirationDays /* d */; + // Add a 2 minute time delay if set to 1 day: https://github.com/aws-amplify/amplify-cli/issues/4460 + if (expirationDays === 1) expirationDateInSeconds += 60 * 2; const nowEpochTime = Math.floor(Date.now() / 1000); return new AppSync.ApiKey({ ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),