Amplify GraphQL API Key Expired?

Amplify GraphQL API Key Expired?

When developing an app on AWS Amplify I created an API key that expired in 7 days and ended up coming back to the project later to find the API key had expired. These are the steps to delete the key and recreate a new one. You may want to consider extending the expiration days further out or statically assigning an expiration date with the APIKeyExpirationEpoch parameter. Check out the official documentation for more information.

The key to getting a new key was modifying parameters in the amplify parameters.json file located at

<project-root>/amplify/backend/api/projectname/parameters.json

My parameters.json before:

{
  "AppSyncApiName": "cardz.io",
  "DynamoDBBillingMode": "PAY_PER_REQUEST",
  "DynamoDBEnableServerSideEncryption": false,
  "AuthModeLastUpdated": "2022-10-29T18:15:13.480Z"
}

First you will need to add the CreateAPIKey parameter with a value of 0 to remove the expired API key:

{
  "AppSyncApiName": "cardz.io",
  "DynamoDBBillingMode": "PAY_PER_REQUEST",
  "DynamoDBEnableServerSideEncryption": false,
  "AuthModeLastUpdated": "2022-10-29T18:15:13.480Z",
  "CreateAPIKey": 0
}

Execute amplify push and wait for those changes to finish

Next change the CreateAPIKey value to 1

{
  "AppSyncApiName": "cardz.io",
  "DynamoDBBillingMode": "PAY_PER_REQUEST",
  "DynamoDBEnableServerSideEncryption": false,
  "AuthModeLastUpdated": "2022-10-29T18:15:13.480Z",
  "CreateAPIKey": 1
}

Save those changes and execute amplify push and wait for those changes to apply.

Now that your key has been updated you can add a custom expiration date like this:

{
  "AppSyncApiName": "cardz.io",
  "DynamoDBBillingMode": "PAY_PER_REQUEST",
  "DynamoDBEnableServerSideEncryption": false,
  "AuthModeLastUpdated": "2022-10-29T18:15:13.480Z",
  "APIKeyExpirationEpoch": 4070924400
}

Don't forget to amplify push one last time and wait for those changes to apply.