export const meta = {
  title: `Extend with the Amplify CLI`,
  description: `Install the Amplify CLI and use the CLI without an AWS account`
};

Amplify Studio allows you to use all the Amplify CLI's features without the need to configure it with AWS Identity and Access Management (IAM). Changes made in Amplify Studio can be made available in the CLI by running the `amplify pull` command. Similarly, CLI changes to the data model or auth will be visible in Amplify Studio. For all other categories, Studio provides links to the relevant service consoles in AWS.

![autologin](/images/console/cli-autologin.gif)

## To install the Amplify CLI

1. Open a terminal window and install the CLI.

import all0 from '/src/fragments/cli-install-block.mdx';

<Fragments fragments={{ all: all0 }} />

After the Amplify CLI finishes installing, you can configure the CLI so that you can use it without an AWS account.

## To configure the Amplify CLI for use without an AWS account

import all1 from '/src/fragments/pull-cli-studio.mdx';

<Fragments fragments={{ all: all1 }} />

## Adding features with the Amplify CLI

The Studio **Set up** menu lists cloud backend features such as functions, storage, and APIs that you can add to your app using the CLI. For each backend resource, Studio displays the CLI commands to run in your terminal window.

1. In Studio, on the **Set up** menu, choose **Storage** or **Functions**.
2. On the **Storage** page, under **Pull your Amplify project**, copy the following command and run it in your terminal window.
3. After your backend environment has been successfully pulled from the cloud, copy the following command under **Add storage capabilities** and paste it in your terminal window:

```bash
amplify add storage
```

4. Follow the prompts in the terminal window to configure storage with your desired settings.
5. Run the following command in your terminal window to build your local backend resources and provision them in the cloud:

```bash
amplify push
```

6. Return to the Studio **Storage** page. Confirm that a link to your new storage resource is available in the **Deployed storage resources** section.

## Infrastructure-as-code

All backends created in Amplify Studio and Amplify CLI are deployed using AWS CloudFormation. AWS CloudFormation allows you store your backend configuration as code in your repository. This has three major benefits:

1. Ability to extend a project with capabilities offered by individual services (e.g. Cognito, DynamoDB) that are not available in Amplify.
2. Ability to easily replicate backend environments across AWS accounts and regions.
3. Ability to easily integrate with CI/CD pipelines such as the pipeline offered in the Amplify console.

All backend infrastructure-as-code definitions can be added to your project with the Amplify Command Line Interface (CLI).

## Troubleshooting

### Logging into Amplify Studio using Amplify CLI does not provide a Token or Prompt

This behavior is observed when running a Amplify CLI `amplify pull --appId <appID> --envName <envName>` command in the terminal, which opens a new tab in the browser with a Amplify Studio login screen. On logging in, if you are not redirected back and observe the CLI being stuck in a loading state.

To resolve this issue,

1. Exit from the Amplify CLI prompt
1. If present, remove the leftover artifacts created in your current directory (e.g. `amplify` or `amplify-backup`) from the failed pull attempt
1. Rerun the Amplify CLI `amplify pull --appId <appID> --envName <envName>` command

### Authentication tokens

When using Amplify CLI, you may encounter the following error message:


```console
Failed to receive expected authentication tokens. Error: [Error: 'jsonString' argument missing or empty]
```

This message occurs when running a Amplify CLI `amplify pull --appId <appID> --envName <envName>` command in the terminal and allowing access permission to the CLI. 

To resolve this issue,

1. Delete the `config.json` file present at the location `~/.amplify/admin/`
1. If present, remove the leftover artifacts created in your current directory (e.g. `amplify` or `amplify-backup`) from the failed pull attempt
1. Rerun the Amplify CLI `amplify pull --appId <appID> --envName <envName>` command

<Callout>

Note, the content of `~/.amplify/admin/config.json` is utilized to store JWTs to vend temporary AWS credentials and should **NOT be shared.

</Callout>