

# Custom integrations

Use a custom integration when there’s no first-party integration for the service that you want to use. A custom integration holds the environment variables that your app needs, such as a queue URL or the endpoint and key of a third-party API. You can reuse it across apps and environments, like any other integration.

A custom integration differs from a first-party integration in the following ways:
+  **You define the environment variables.** Amplify doesn’t set any variables for you.
+  **Amplify doesn’t check the resource.** If you give an ARN, it must name a resource in the same AWS account as your app, but Amplify doesn’t verify that the resource exists.
+  **Amplify grants no permissions.** A custom integration doesn’t add permissions to your app’s role. To use an AWS resource from your app, set the environment’s role permissions mode to `full`, and make sure that the environment’s role has the permissions that your app needs.

## Environment variables for custom integrations
<a name="integrations-custom-env-vars"></a>

You add environment variables when you create the integration:
+  `--integ-env-var KEY=VALUE` adds a plaintext variable. Repeat the option for each variable.
+  `--integ-secret-env-var KEY` adds a secret variable. Amplify reads its value from the dotenv file that you pass with `--integ-secret-env-file`, so the value doesn’t appear on the command line or in your shell history.

Variable values can’t be empty. To change the variables later, use `aws amplifygen3 integration edit`. To remove a variable, use `--integ-env-var-unset KEY`.

## Create a custom integration
<a name="integrations-custom-create"></a>

A custom integration connects only to an environment whose role permissions mode is `full`, even when the integration points to no AWS resource. New environments use `scoped` mode, so change the mode before you connect. Without this step, the `connect` command fails.

**Warning**  
In `full` mode, your app can use every permission attached to the environment’s role, not only the permissions that its integrations need. Attach to the role only the permissions that your app needs.

The following AWS CLI command sets the `preview` environment to `full` mode.

```bash
aws amplifygen3 env edit --env preview --role-permissions-mode full
```

The following AWS CLI command creates a custom integration for an Amazon SQS queue and connects it to the `preview` environment. Replace the ARN and the queue URL with your own values.

```bash
aws amplifygen3 integration connect custom --name orders-queue \
  --arn arn:aws:sqs:us-east-1:111122223333:orders \
  --integ-env-var QUEUE_URL=https://sqs.us-east-1.amazonaws.com/111122223333/orders \
  --env preview
```

The following AWS CLI command creates a custom integration for a third-party service. It stores the service’s endpoint as a plaintext variable, and reads its API key from a `.env.secrets` file.

```bash
aws amplifygen3 integration connect custom --name payments \
  --integ-env-var PAYMENTS_API_URL=https://api.example.com \
  --integ-secret-env-var PAYMENTS_API_KEY --integ-secret-env-file .env.secrets \
  --env preview
```

Your app reads the variables from `process.env`, like any other environment variable. Integration variables are available to the build and to server-side code. A variable reaches browser code only if its name has your framework’s public prefix, such as `NEXT_PUBLIC_`.

## Delete a custom integration
<a name="integrations-custom-delete"></a>

Before you delete an integration, disconnect it from every environment, and then redeploy those environments so that they stop using it. Deleting a custom integration doesn’t change the resource or the service that it points to.

The following AWS CLI commands disconnect the integration from the `preview` environment and then delete it.

```bash
aws amplifygen3 integration disconnect --name payments --env preview
aws amplifygen3 integration delete --name payments
```

The `delete` command asks for confirmation. In a non-interactive session such as CI, add `--yes`.