Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot launch Amplify Studio: A valid backend environment was not specified #1068

Closed
4 tasks done
stephenjen opened this issue Nov 15, 2023 · 28 comments
Closed
4 tasks done
Labels
login issues when logging into studio pending-triage An issue that is pending triage studio-backend An issue that needs to be tracked by Studio Backend team

Comments

@stephenjen
Copy link

Before opening, please confirm:

App Id

d22yyxv6tcw0zy

Region

ap-northeast-2

Environment name

rectangles

Figma File Version (if applicable)

No response

Amplify CLI Version

No response

If applicable, what version of Node.js are you using?

v17.5.0

What operating system are you using?

MacOS Sonoma

Browser type?

Safari and Firefox

Describe the bug

My Amplify Studio all of as sudden stopped working. When I access it from the browser, I get the following info message: A valid backend environment was not specified. There's a dropdown with one option, dev, but selecting it bring me to the same message.

image

Expected behavior

Amplify Studio to load in browser

Reproduction steps

  1. Log into AWS Console
  2. Click on AWS Amplify
  3. Click app rectangles
  4. Click Backend Environments tab
  5. Click Launch Studio button

Project Identifier

No response

Additional information

No response

@stephenjen stephenjen added the pending-triage An issue that is pending triage label Nov 15, 2023
@ykethan
Copy link
Contributor

ykethan commented Nov 15, 2023

Hey @stephenjen, thank you for reaching out.
On the screen where you are observing the A valid backend environment was not specified, do you observe any errors on the browser debug console?
Additionally, could you try disabling and re-enabling studio, please refer to the documentation providing this information: https://docs.amplify.aws/console/adminui/access-management/#troubleshooting

@ykethan ykethan added pending-response An issue is pending response from the issue requestor studio-backend An issue that needs to be tracked by Studio Backend team login issues when logging into studio labels Nov 15, 2023
@stephenjen
Copy link
Author

Hi @ykethan , I'm seeing this issue on at this url: https://ap-northeast-2.admin.amplifyapp.com/admin/d22yyxv6tcw0zy/dev/data-manager#, below:

image

On Firefox's debug console I see a bunch of warnings and one error:

2023-11-16_12-11-06

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Nov 16, 2023
@ykethan
Copy link
Contributor

ykethan commented Nov 16, 2023

@stephenjen did you try disabling and re-enabling studio? similar to steps in: docs.amplify.aws/console/adminui/access-management/#troubleshooting

@ykethan ykethan added the pending-response An issue is pending response from the issue requestor label Nov 16, 2023
@stephenjen
Copy link
Author

Sorry. Yes, I did, before posting this issue.

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Nov 16, 2023
@ykethan
Copy link
Contributor

ykethan commented Nov 17, 2023

Hey @stephenjen, thank you for the confirmation. From the error message in the error message in the screenshot does seem to be occurring on the cli.json file.
In the AWS S3 console, could you open the deployment bucket that contains the name of your application. The bucket should contain a studio-backend folder object with the cli.json file. could you download this and crosscheck with the cli.json file in your local project(if present)

the file should be similar to

{
    "features": {
        "graphqltransformer": {
            "addmissingownerfields": true,
            "improvepluralization": false,
            "validatetypenamereservedwords": true,
            "useexperimentalpipelinedtransformer": true,
            "enableiterativegsiupdates": true,
            "secondarykeyasgsi": true,
            "skipoverridemutationinputtypes": true,
            "transformerversion": 2,
            "suppressschemamigrationprompt": true,
            "securityenhancementnotification": false,
            "showfieldauthnotification": false,
            "usesubusernamefordefaultidentityclaim": true,
            "usefieldnameforprimarykeyconnectionfield": false,
            "enableautoindexquerynames": true,
            "respectprimarykeyattributesonconnectionfield": true,
            "shoulddeepmergedirectiveconfigdefaults": false,
            "populateownerfieldforstaticgroupauth": true
        },
        "frontend-ios": {
            "enablexcodeintegration": true
        },
        "auth": {
            "enablecaseinsensitivity": true,
            "useinclusiveterminology": true,
            "breakcirculardependency": true,
            "forcealiasattributes": false,
            "useenabledmfas": true
        },
        "codegen": {
            "useappsyncmodelgenplugin": true,
            "usedocsgeneratorplugin": true,
            "usetypesgeneratorplugin": true,
            "cleangeneratedmodelsdirectory": true,
            "retaincasestyle": true,
            "addtimestampfields": true,
            "handlelistnullabilitytransparently": true,
            "emitauthprovider": true,
            "generateindexrules": true,
            "enabledartnullsafety": true,
            "generatemodelsforlazyloadandcustomselectionset": false
        },
        "appsync": {
            "generategraphqlpermissions": true
        },
        "latestregionsupport": {
            "pinpoint": 1,
            "translate": 1,
            "transcribe": 1,
            "rekognition": 1,
            "textract": 1,
            "comprehend": 1
        },
        "project": {
            "overrides": true
        }
    },
    "debug": {}
}

@ykethan ykethan added the pending-response An issue is pending response from the issue requestor label Nov 17, 2023
@stephenjen
Copy link
Author

Hi @ykethan, the bucket does not contain a studio-backend folder:

2023-11-18_08-22-30

But I do have a cli-inputs.json on local:

image

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Nov 18, 2023
@ykethan
Copy link
Contributor

ykethan commented Nov 20, 2023

Hey @stephenjen, the screeenshot shows the bucket created by the storage category. There should be another bucket similar to amplify-<app-name>-staging-34648-deployment ending with deployment in the name

@ykethan ykethan added the pending-response An issue is pending response from the issue requestor label Nov 20, 2023
@stephenjen
Copy link
Author

There isn't:

2023-11-28_15-35-27

Do I need to create one?

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Nov 28, 2023
@ykethan
Copy link
Contributor

ykethan commented Nov 29, 2023

Hey @stephenjen, interesting. The bucket gets created when we create a amplify backend using Amplify CLI or Studio.
When running amplify pull --appId <app-id> --envName <env-name> in a empty folder outside the present directory are you able to pull the backend?

@ykethan ykethan added the pending-response An issue is pending response from the issue requestor label Nov 29, 2023
@stephenjen
Copy link
Author

Hi @ykethan, do you mean run it outside of my project or inside an empty folder within my project?

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Dec 4, 2023
@ykethan
Copy link
Contributor

ykethan commented Dec 5, 2023

@stephenjen outside your existing project directory, wanted to ensure if you are able to pull the projects backend.

@ykethan ykethan added the pending-response An issue is pending response from the issue requestor label Dec 5, 2023
@stephenjen
Copy link
Author

2023-12-06_08-31-31

And then it opens my browser where I'm already logged into the admin panel, and then the same page where I am encountering the issue:

image

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Dec 6, 2023
@ykethan
Copy link
Contributor

ykethan commented Dec 6, 2023

@stephenjen could you disable studio on the AWS Amplify console then re-run the pull command it should use the AWS profile to pull the project.

@ykethan ykethan added the pending-response An issue is pending response from the issue requestor label Dec 6, 2023
@stephenjen
Copy link
Author

Ok. I created a new Flutter project and ran amplify pull --appId <app-id> --envName <env-name>. I still only have the -dev bucket.

Here the new cli.json:

{
  "features": {
    "graphqltransformer": {
      "addmissingownerfields": true,
      "improvepluralization": false,
      "validatetypenamereservedwords": true,
      "useexperimentalpipelinedtransformer": true,
      "enableiterativegsiupdates": true,
      "secondarykeyasgsi": true,
      "skipoverridemutationinputtypes": true,
      "transformerversion": 2,
      "suppressschemamigrationprompt": true,
      "securityenhancementnotification": false,
      "showfieldauthnotification": false,
    },
    "frontend-ios": {
      "enablexcodeintegration": true
    },
    "auth": {
      "enablecaseinsensitivity": true,
      "useinclusiveterminology": true,
      "breakcirculardependency": true,
      "forcealiasattributes": false,
      "useenabledmfas": true
    },
    "codegen": {
      "useappsyncmodelgenplugin": true,
      "usedocsgeneratorplugin": true,
      "usetypesgeneratorplugin": true,
      "cleangeneratedmodelsdirectory": true,
      "retaincasestyle": true,
      "addtimestampfields": true,
      "handlelistnullabilitytransparently": true,
      "emitauthprovider": true,
      "generateindexrules": true,
      "enabledartnullsafety": true
    },
    "appsync": {
      "generategraphqlpermissions": true
    },
    "latestregionsupport": {
      "pinpoint": 1,
      "translate": 1,
      "transcribe": 1,
      "rekognition": 1,
      "textract": 1,
      "comprehend": 1
    },
    "project": {
      "overrides": true
    }
  },
  "debug": {
    "shareProjectConfig": false
  }
}

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Dec 7, 2023
@ykethan
Copy link
Contributor

ykethan commented Dec 8, 2023

Hey @stephenjen,

if you are unable to find the bucket, could you replace cli.json contents locally in the project that is having issues opening studio and run amplify push

{
    "features": {
        "graphqltransformer": {
            "addmissingownerfields": true,
            "improvepluralization": false,
            "validatetypenamereservedwords": true,
            "useexperimentalpipelinedtransformer": true,
            "enableiterativegsiupdates": true,
            "secondarykeyasgsi": true,
            "skipoverridemutationinputtypes": true,
            "transformerversion": 2,
            "suppressschemamigrationprompt": true,
            "securityenhancementnotification": false,
            "showfieldauthnotification": false,
            "usesubusernamefordefaultidentityclaim": true,
            "usefieldnameforprimarykeyconnectionfield": false,
            "enableautoindexquerynames": true,
            "respectprimarykeyattributesonconnectionfield": true,
            "shoulddeepmergedirectiveconfigdefaults": false,
            "populateownerfieldforstaticgroupauth": true
        },
        "frontend-ios": {
            "enablexcodeintegration": true
        },
        "auth": {
            "enablecaseinsensitivity": true,
            "useinclusiveterminology": true,
            "breakcirculardependency": true,
            "forcealiasattributes": false,
            "useenabledmfas": true
        },
        "codegen": {
            "useappsyncmodelgenplugin": true,
            "usedocsgeneratorplugin": true,
            "usetypesgeneratorplugin": true,
            "cleangeneratedmodelsdirectory": true,
            "retaincasestyle": true,
            "addtimestampfields": true,
            "handlelistnullabilitytransparently": true,
            "emitauthprovider": true,
            "generateindexrules": true,
            "enabledartnullsafety": true,
            "generatemodelsforlazyloadandcustomselectionset": false
        },
        "appsync": {
            "generategraphqlpermissions": true
        },
        "latestregionsupport": {
            "pinpoint": 1,
            "translate": 1,
            "transcribe": 1,
            "rekognition": 1,
            "textract": 1,
            "comprehend": 1
        },
        "project": {
            "overrides": true
        }
    },
    "debug": {}
}

additioanlly, in the account do you not see any S3 bucket names that starts with amplify ending with -deployment?
The bucket is created when you first ran amplify init creating a new app.
If no, please ensure you are using the correct account matching the profile being used locally.
the bucket should contain
image

as if the bucket contains folder like private, public or protected it an storage resource created by amplify add storage or amplify studio storage.

@ykethan ykethan added the pending-response An issue is pending response from the issue requestor label Dec 8, 2023
@stephenjen
Copy link
Author

I did the above and was able to access Studio after re-enabling it, though I'm still missing the -deployment bucket and the DynamoDB tables in Studio are all empty.

If no, please ensure you are using the correct account matching the profile being used locally.
the bucket should contain

My app is still updating the DynamoDB that is accessible from AWS Console, but this isn't appearing in Studio. How can I get them using the same account?

Thanks.

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Dec 15, 2023
@stephenjen
Copy link
Author

I should have been more clear - what can I do to make sure Studio is pointed to the same place as my app and AWS Console?

@stephenjen
Copy link
Author

Both AWS Console > my_app and Amplify Studio seem to be pointing to the same app, but while AWS Console > my_app shows data, Amplify Studio is empty.

@johnpc
Copy link

johnpc commented Jan 22, 2024

Hi @stephenjen - it definitely looks like there's drift between the s3 bucket for your app and the deployed state of your resources. If you update your data model via CLI and run amplify push, it should cause the data category related files in your s3 bucket to be updated.

Can you try that and let me know if it helps?

@johnpc johnpc added the pending-response An issue is pending response from the issue requestor label Jan 22, 2024
@stephenjen
Copy link
Author

Hi @johnpc, because the app is still in development, I'm frequently (maybe a 2-3 times a week) updating the data model, running amplify codegen models and then amplify push, and throughout these model updates the issue remains.

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Jan 23, 2024
@johnpc
Copy link

johnpc commented Jan 23, 2024

I see. In order to debug this, I'll need some more information. It's important to note that the Amplify Studio interface is driven by calls to the AmplifyBackend sdk, which in turn reads configuration from files in your S3 bucket. So to debug, let's take a look at these s3 files and AmplifyBackend sdk responses.

First, find your S3 bucket

First, you will need to find your app's S3 bucket. You can find it by running the AWS CLI like this:

aws s3 ls | grep "amplify\-" | grep "\-deployment" | grep "\-rectangles\-"

The bucket will be named with your app name and environment name in it - the above will grep for your environment name rectangles.

Once you find your bucket name (like amplify-<your-app-name>-rectangles-<your-random-numbers>-deployment), lets copy it down to our local filesystem to understand what's inside:

mkdir bucket && cd bucket
aws s3 sync s3://amplify-<your-app-name>-rectangles-<your-random-numbers>-deployment .

Then lets open this directory in your code editor so we can see everything.

Understand S3 Bucket Contents

Your S3 bucket contains a number of directories, but lets focus for now on the models/ directory and the studio-backend/ directory, since those are the directories relevant to the problems you've described.

First let's look at studio-backend/amplify-meta.json and cli.json. These files drive the response from running the SDK command

aws amplifybackend get-backend --backend-environment-name <your-environment-name> --app-id <your-app-id> | jq   

This explains your first problem. The contents of cli.json was invalid JSON, which caused the Studio UI to crash. It looks like you've successfully fixed this issue already, so you should notice that your cli.json is now valid.

Second, lets look at models/<your-app-name>/ directory. It contains 3 files:

  • modelIntrospection.json
  • schema.graphql
  • schema.js

These files drive the response from the SDK command:

aws amplifybackend get-backend-api-models --backend-environment-name <your-environment-name> --app-id <your-app-id> --resource-name <your-app-name> | jq   

These are the proximate cause of your issue in the "Data Modeling" and "Manage Content" tab of Studio. Check these files and ensure they are set to the proper values that you expect, and that the values from the get-backend-api-models cli call are valid json. If they are not, or you find some issue with them, you can fix them locally and upload your changes back to the bucket with

aws s3 sync . s3://amplify-<your-app-name>-rectangles-<your-random-numbers>-deployment

I cannot be certain how your bucket got into its invalid state, but hopefully this information helps find more information or get things back in order.

@johnpc johnpc added the pending-response An issue is pending response from the issue requestor label Jan 23, 2024
@stephenjen
Copy link
Author

stephenjen commented Jan 24, 2024

Hi @johnpc,

I'm getting zsh: killed when I run AWS CLI, after switching to bash, I wasn't able to find my app's S3 bucket using aws s3 ls | grep "amplify\-" | grep "\-deployment" | grep "\-rectangles\-" but through the console I can see that the app is updating rectangles<random-number>-dev, and I also see a amplify-rectangles-dev-<random-number>-deployment

When I run aws s3 sync s3://rectangles\<random-number>-dev . or aws s3 sync s3://amplify-rectangles-dev-\<random-number>-deployment ., I get Killed: 9.

Does the fact that my app is updating rectangles<random-number>-dev and not amplify-rectangles-dev-<random-number>-deployment a possible source of problems? The directories you mentioned are in amplify-rectangles-dev-<random-number>-deployment but not in rectangles<random-number>-dev.

Thanks again.

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Jan 24, 2024
@johnpc
Copy link

johnpc commented Jan 24, 2024

It is not a problem that you have two buckets. One of those buckets (rectangles<random-number>-dev) is associated with your deployed Storage category. It is used for all the files that you need to store for your application runtime. It's expected that you'll write application code interact with this bucket or manage the files stored within that via Studio.

The other bucket is the bucket we're talking about - amplify-rectangles-dev-<random-number>-deployment is used strictly to manage deployment state for the Amplify CLI and Amplify Studio. Ideally, we wouldn't have to poke around this bucket, but in your case it's gotten into a state where it's causing problems.

Getting the AWS CLI working properly will help debug the problem in your bucket's state. You can follow https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html to update your aws cli version as well as find troubleshooting instructions for AWS CLI.

Since we're still just exploring and understanding this bucket, lets only run the aws commands that read the bucket (aws s3 ls and aws s3 sync s3://... .) and not the commands that write to the bucket yet (aws s3 sync . s3://...).

@johnpc johnpc added the pending-response An issue is pending response from the issue requestor label Jan 24, 2024
@stephenjen
Copy link
Author

@johnpc Thanks again for the informative, detail reply. Much appreciated. Let me provide some updates:

I was able to sync the local bucket folder to aws deployment directories and check the modelIntrospection.json, schema.graphql and schema.js files. The schema.graphql synced from S3 is identical to local at app_name/amplify/backend/api/amplifyDatasourceDev/schema.graphql, and there was nothing obviously wrong with the other two files.

I then changed the local schema.graphql by removing all models and then adding a simple test model with just an ID and a string field, codegen'ed and pushed the update to AWS. I looked at the newly generated modelIntrospection.json, schema.graphql and schema.js files and they seem to properly reflect the update Then I added two new item to the model, one using AWS Console and the other using Amplify Studio, and even with this simple test model the issue still remains - the item added through AWS Console isn't visible through Amplify Studio and vice versa.

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Jan 25, 2024
@johnpc
Copy link

johnpc commented Jan 25, 2024

I see - so you're not having trouble interacting with your models themselves via Studio, and adding and removing fields from your model is working properly.

It sounds like the problem is viewing individual records within the Content tab of Studio - when you create a record directly via Studio's Content tab, the record appears, but when you add a record to the underlying DynamoDB table directly, the record does not appear.

Is that a correct understanding of what you're experiencing?

Does the Content tab page show any error loading the record?

Screenshot 2024-01-25 at 9 01 59 AM

The Content tab in Studio expects the data to be formatted in a certain way, so adding records to dynamo out-of-band won't work in every case - for example, in the screenshot above, I added a record without createdAt and updatedAt fields. I am interested in more information regarding how you are adding records via AWS Console.

@johnpc johnpc added the pending-response An issue is pending response from the issue requestor label Jan 25, 2024
@stephenjen
Copy link
Author

Hi @johnpc,

Everything's back to working!

After your latest feedback I tested how creating an item manually through AWS Console differs from creating an item manually through Studio, and sure enough, creating through the Console does not create createdAt and updatedAt fields, however, these fields were created and populated automatically when going through Studio. I also noticed the item created through Studio was visible through Console. Then I deleted these records and loaded items through my app, and now both Console and Studio are in sync and items are visible in both.

So to trace my last couple actions:

  1. Couple weeks ago I noticed I wasn't able to access Studio and was stuck at "A valid environment was not specified" message.
  2. After updating my cli.json as advised, I was able to access Studio, but although DynamoDB models had items, these items were not visible in Studio. All models appeared empty in Studio.
  3. I replaced all my app's models with a test model (replaced the schema with just the test model, codegen'ed and pushed), and manually created an item each through Studio and Console. These items were still only visible through the tools used to create them.
  4. I replaced back the test model with my app's model (replaced the schema with just models from my app, codegen'ed and pushed), then tested by manually creating one item each in a model through Console and Studio. I saw the item created through Studio had the createdAt and updatedAt fields populated and this item was also visible through Console.
  5. Deleted the manually created items, loaded items through the app, and now everything's working!

Hope the above help to narrow down the issue.

@github-actions github-actions bot removed the pending-response An issue is pending response from the issue requestor label Jan 27, 2024
@johnpc
Copy link

johnpc commented Jan 27, 2024

Awesome! Thanks for that summary! I'll close this out - feel free to reopen or cut a new issue if you have trouble with anything else!

@johnpc johnpc closed this as completed Jan 27, 2024
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
login issues when logging into studio pending-triage An issue that is pending triage studio-backend An issue that needs to be tracked by Studio Backend team
Projects
None yet
Development

No branches or pull requests

3 participants