amplify-backend
amplify-backend copied to clipboard
Could not decode AmplifyOutputs
Before opening, please confirm:
- [X] I have searched for duplicate or closed issues and discussions.
Language and Async Model
Kotlin
Amplify Categories
Authentication
Gradle script dependencies
amplifyUiAuthenticator = "1.2.1"
amplifyCore = "2.20.0"
amplify-ui-authenticator = { group = "com.amplifyframework.ui", name = "authenticator", version.ref = "amplifyUiAuthenticator" }
amplify-core = { group = "com.amplifyframework", name = "core", version.ref = "amplifyCore" }
amplify-core-kotlin = { group = "com.amplifyframework", name = "core-kotlin", version.ref = "amplifyCore" }
Environment information
Welcome to Gradle 8.7!
Here are the highlights of this release:
- Compiling and testing with Java 22
- Cacheable Groovy script compilation
- New methods in lazy collection properties
For more details see https://docs.gradle.org/8.7/release-notes.html
------------------------------------------------------------
Gradle 8.7
------------------------------------------------------------
Build time: 2024-03-22 15:52:46 UTC
Revision: 650af14d7653aa949fce5e886e685efc9cf97c10
Kotlin: 1.9.22
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 11.0.9 (Oracle Corporation 11.0.9+7-LTS)
OS: Windows 10 10.0 amd64
Please include any relevant guides or documentation you're referencing
https://docs.amplify.aws/android/start/quickstart/
Describe the bug
I followed the quickstart for AWS Amplify Gen 2 on Android, however it does not work. When launching the app the login screen does not show up and instead the app runs into an error.
Reproduction steps (if applicable)
- Install the latest version of Android Studio.
- Create a new Android project using Jetpack Compose.
- Follow the steps described in the quickstart section for Amplify Gen 2 until the end of step 6.
Code Snippet
Authenticator { state ->
Column(modifier = modifier) {
Text(
text = "Hello ${state.user.username}!",
)
Button(onClick = {
Amplify.Auth.signOut { }
}) {
Text(text = "Sign Out")
}
}
}
Log output
Could not initialize Amplify
AmplifyException{message=Could not decode AmplifyOutputs, cause=kotlinx.serialization.SerializationException: com.amplifyframework.core.configuration.AmplifyOutputsData.Auth.MfaConfiguration does not contain element with name 'OFF' at path $.auth.mfaConfiguration, recoverySuggestion=Ensure the AmplifyOutputs data is correct}
at com.amplifyframework.core.configuration.AmplifyOutputsData$Companion.deserialize$com_amplifyframework_core_release(AmplifyOutputsData.kt:238)
at com.amplifyframework.core.configuration.AmplifyOutputsData$Companion.deserialize(AmplifyOutputsData.kt:225)
at com.amplifyframework.core.configuration.AmplifyOutputsData.deserialize(Unknown Source:2)
at com.amplifyframework.core.Amplify.configure(Amplify.java:210)
at my.package.MainActivity.onCreate(MainActivity.kt:30)
at android.app.Activity.performCreate(Activity.java:8305)
at android.app.Activity.performCreate(Activity.java:8284)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7872)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
amplifyconfiguration.json
{
"auth": {
"user_pool_id": "REDACTED",
"aws_region": "eu-central-1",
"user_pool_client_id": "REDACTED",
"identity_pool_id": "REDACTED",
"mfa_methods": [],
"standard_required_attributes": [
"email"
],
"username_attributes": [
"email"
],
"user_verification_types": [
"email"
],
"mfa_configuration": "OFF",
"password_policy": {
"min_length": 8,
"require_numbers": true,
"require_lowercase": true,
"require_uppercase": true,
"require_symbols": true
},
"unauthenticated_identities_enabled": true
},
"data": {
"url": "REDACTED",
"aws_region": "eu-central-1",
"api_key": "REDACTED",
"default_authorization_type": "API_KEY",
"authorization_types": [
"AMAZON_COGNITO_USER_POOLS",
"AWS_IAM"
],
"model_introspection": {
"version": 1,
"models": {
"Todo": {
"name": "Todo",
"fields": {
"id": {
"name": "id",
"isArray": false,
"type": "ID",
"isRequired": true,
"attributes": []
},
"content": {
"name": "content",
"isArray": false,
"type": "String",
"isRequired": false,
"attributes": []
},
"createdAt": {
"name": "createdAt",
"isArray": false,
"type": "AWSDateTime",
"isRequired": false,
"attributes": [],
"isReadOnly": true
},
"updatedAt": {
"name": "updatedAt",
"isArray": false,
"type": "AWSDateTime",
"isRequired": false,
"attributes": [],
"isReadOnly": true
}
},
"syncable": true,
"pluralName": "Todos",
"attributes": [
{
"type": "model",
"properties": {}
},
{
"type": "auth",
"properties": {
"rules": [
{
"allow": "public",
"provider": "apiKey",
"operations": [
"create",
"update",
"delete",
"read"
]
}
]
}
}
],
"primaryKeyInfo": {
"isCustomPrimaryKey": false,
"primaryKeyFieldName": "id",
"sortKeyFieldNames": []
}
}
},
"enums": {},
"nonModels": {}
}
},
"version": "1"
}
GraphQL Schema
No response
Additional information and screenshots
Hi @spiekermax - this appears to be a bug in the Amplify CLI. Your amplify_outputs.json file has an mfa_configuration value of OFF, which is not valid. Valid values are NONE, OPTIONAL, and REQUIRED.
I am going to transfer this issue to the CLI repo to take a look at, but in the meantime you can manually change the mfa_configuration value to be NONE to resolve the error.
Thank you, this worked for me! My amplify_outputs.json-file was automatically generated with this entry in place, so I believe you are correct with this being a bug of the CLI.
Hey @spiekermax :wave: thanks for raising this! Can you post the output from npx ampx info?
Sure here it is, however I ran this command locally. The outputs file was generated on AWS during the build stage when I deployed my backend. My backend is an exact replica of this template. If I should run this command on AWS instead, please let me know how, since CloudShell did not work for me here.
System:
OS: Windows 10 10.0.19045
CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
Memory: 7.03 GB / 15.95 GB
Binaries:
Node: 20.16.0 - E:\Programme\NodeJS\node.EXE
Yarn: undefined - undefined
npm: 9.5.0 - E:\Programme\NodeJS\npm.CMD
pnpm: undefined - undefined
NPM Packages:
@aws-amplify/backend: 1.0.4
@aws-amplify/backend-cli: 1.1.1
aws-amplify: 6.4.0
aws-cdk: 2.149.0
aws-cdk-lib: 2.149.0
typescript: 5.5.3
AWS environment variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
AWS_SDK_LOAD_CONFIG = 1
AWS_STS_REGIONAL_ENDPOINTS = regional
No CDK environment variables
Hey @spiekermax thanks for posting that! Can you try upgrading the CLI package with
npm update @aws-amplify/backend-cli
or you can manually update the package.json with the following and run npm install
"@aws-amplify/backend-cli": "^1.2.1",
This was fixed recently with https://github.com/aws-amplify/amplify-backend/issues/1644
Thank you! I tried this, however the generated amplify_outputs.json still contains OFF for the relevant field in my case.
Hey @spiekermax the update might not have upgraded the dependencies of the dependency, but we've upgraded the info command to show all relevant Amplify packages in the latest version. Now that the CLI is upgraded can you re-run ampx info and paste the output?
Sure! Here it is:
System:
OS: Windows 10 10.0.19045
CPU: (12) x64 AMD Ryzen 5 3600 6-Core Processor
Memory: 7.89 GB / 15.95 GB
Binaries:
Node: 20.16.0 - E:\Programme\NodeJS\node.EXE
Yarn: undefined - undefined
npm: 9.5.0 - E:\Programme\NodeJS\npm.CMD
pnpm: undefined - undefined
NPM Packages:
@aws-amplify/auth-construct: 1.2.0
@aws-amplify/backend: 1.0.4
@aws-amplify/backend-auth: 1.1.0
@aws-amplify/backend-cli: 1.2.1
@aws-amplify/backend-data: 1.1.0
@aws-amplify/backend-deployer: 1.0.2
@aws-amplify/backend-function: 1.3.0
@aws-amplify/backend-output-schemas: 1.1.0
@aws-amplify/backend-output-storage: 1.0.2
@aws-amplify/backend-secret: 1.0.0
@aws-amplify/backend-storage: 1.0.4
@aws-amplify/cli-core: 1.1.1
@aws-amplify/client-config: 1.1.1
@aws-amplify/deployed-backend-client: 1.1.0
@aws-amplify/form-generator: 1.0.0
@aws-amplify/model-generator: 1.0.2
@aws-amplify/platform-core: 1.0.3
@aws-amplify/plugin-types: 1.1.0
@aws-amplify/sandbox: 1.1.1
@aws-amplify/schema-generator: 1.2.0
aws-amplify: 6.4.3
aws-cdk: 2.150.0
aws-cdk-lib: 2.150.0
typescript: 5.5.4
AWS environment variables:
AWS_NODEJS_CONNECTION_REUSE_ENABLED = 1
AWS_SDK_LOAD_CONFIG = 1
AWS_STS_REGIONAL_ENDPOINTS = regional
No CDK environment variables
Hey @spiekermax thanks for posting that! It looks like you have the updated package. Can you try regenerating this file with ampx generate outputs?
I'm running into an error there:
StackDoesNotExistError: Stack does not exist.
Resolution: Ensure the CloudFormation stack ID or Amplify App ID and branch specified are correct and exists, then re-run this command.
Cause: Stack with id amplify-amplifybackendapptemplate-Max-sandbox-REDACTED does not exist
So far I have always used the following button in the AWS console and from there it is still generating OFF with the updated dependencies:
Hey @spiekermax, is the sandbox running locally? Could you run npx ampx sandbox then verify the amplify_outputs.json locally?
The amplify_outputs.json maybe be referring to an build with older dependencies and would need to be rebuilt with the updated dependencies.
Alright, I managed to get the output locally by using this command:
npx @aws-amplify/backend-cli generate outputs --app-id MY_APP_ID --branch main
Now the field for mfa_configuration is indeed set to NONE instead of OFF.
So there appears to be an issue with the download button I used, right?
From the build logs on AWS (not locally), I can tell a new amplify_outputs.json was generated using my latest changes.
✨ Total time: 112.49s
2024-08-03T19:19:53.869Z [INFO]:
2024-08-03T19:19:54.297Z [INFO]: File written: amplify_outputs.json
2024-08-03T19:19:54.658Z [INFO]: # Completed phase: build
## Completed Backend Build
2024-08-03T19:19:54.662Z [INFO]: ## Starting Frontend Build
# Starting phase: build
2024-08-03T19:19:54.662Z [INFO]: # Executing command: mkdir ./dist && touch ./dist/index.html
2024-08-03T19:19:54.665Z [INFO]: # Completed phase: build
## Completed Frontend Build
2024-08-03T19:19:54.706Z [INFO]: ## Build completed successfully
2024-08-03T19:19:54.708Z [INFO]: # Starting caching...
2024-08-03T19:19:54.718Z [INFO]: # Creating cache artifact...
2024-08-03T19:20:13.931Z [INFO]: # Created cache artifact
2024-08-03T19:20:14.024Z [INFO]: # Uploading cache artifact...
2024-08-03T19:20:23.507Z [INFO]: # Uploaded cache artifact
2024-08-03T19:20:23.608Z [INFO]: # Caching completed
2024-08-03T19:20:23.648Z [INFO]: # Starting build artifact upload process...
2024-08-03T19:20:23.664Z [INFO]: # Uploading build artifact '__artifacts.zip'...
2024-08-03T19:20:23.725Z [INFO]: # Build artifact upload completed
2024-08-03T19:20:23.726Z [INFO]: # Starting environment caching...
2024-08-03T19:20:23.726Z [INFO]: # Uploading environment cache artifact...
2024-08-03T19:20:23.806Z [INFO]: # Uploaded environment cache artifact
2024-08-03T19:20:23.806Z [INFO]: # Environment caching completed
@spiekermax was a new build created with the updated dependencies on the Amplify console?
The console download amplify_outputs.json should now provide the latest version of the outputs file. Closing the issue, do reach out if you are still experiencing this.