
## Installation

Before you can use the AWS CLI with Rabata.io, you need to install it on your system.

### Install AWS CLI

Follow the official AWS CLI installation instructions for your operating system:

#### macOS

```bash
$ curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
$ sudo installer -pkg AWSCLIV2.pkg -target /
```

#### Linux

```bash
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
$ unzip awscliv2.zip
$ sudo ./aws/install
```

#### Windows

Download and run the [AWS CLI MSI installer](https://awscli.amazonaws.com/AWSCLIV2.msi) for Windows.

### Verify Installation

Verify that the AWS CLI is installed correctly:

```bash
$ aws --version
aws-cli/2.x.x Python/3.x.x OS-NAME.x86_64 exec-env/AWS
```

## Configuration

To use the AWS CLI with Rabata.io, you need to configure it with your Rabata.io credentials and endpoint.

### Create a Profile

Create a dedicated profile for Rabata.io:

```bash
$ aws configure --profile rabata
AWS Access Key ID [None]: YOUR_ACCESS_KEY
AWS Secret Access Key [None]: YOUR_SECRET_KEY
Default region name [None]: us-east-1
Default output format [None]: json
```

### Configure the Endpoint

Create or edit the AWS CLI configuration file to specify the Rabata.io endpoint:

```bash
$ mkdir -p ~/.aws/
$ cat >> ~/.aws/config << EOF
[profile rabata]
region = us-east-1
s3 =
    endpoint_url = https://s3.us-east-1.rabata.io
    addressing_style = virtual
EOF
```

> **Windows Users**: On Windows, the AWS CLI configuration file is located at `%USERPROFILE%\.aws\config`. You can edit it with a text editor.

## Basic Operations

Here are some common operations you can perform with the AWS CLI and Rabata.io.

### Bucket Operations

#### List All Buckets

```bash
$ aws s3 ls --profile rabata
```

#### Create a Bucket

```bash
$ aws s3 mb s3://my-bucket-name --profile rabata
```

#### Delete a Bucket

```bash
$ aws s3 rb s3://my-bucket-name --profile rabata
```

Note: The bucket must be empty before it can be deleted. To delete a non-empty bucket, add the `--force` flag:

```bash
$ aws s3 rb s3://my-bucket-name --force --profile rabata
```

### Object Operations

#### List Objects in a Bucket

```bash
$ aws s3 ls s3://my-bucket-name --profile rabata
```

#### Upload a File

```bash
$ aws s3 cp local-file.txt s3://my-bucket-name/ --profile rabata
```

#### Download a File

```bash
$ aws s3 cp s3://my-bucket-name/remote-file.txt local-file.txt --profile rabata
```

#### Delete a File

```bash
$ aws s3 rm s3://my-bucket-name/file-to-delete.txt --profile rabata
```

#### Sync a Local Directory with a Bucket

```bash
$ aws s3 sync local-directory/ s3://my-bucket-name/ --profile rabata
```

#### Sync a Bucket with a Local Directory

```bash
$ aws s3 sync s3://my-bucket-name/ local-directory/ --profile rabata
```

## Advanced Operations

Here are some more advanced operations you can perform with the AWS CLI and Rabata.io.

### Working with Object Metadata

You can set metadata when uploading objects:

```bash
$ aws s3 cp local-file.txt s3://my-bucket-name/ \
  --metadata '{"x-amz-meta-custom-key":"custom-value"}' \
  --profile rabata
```

<!-- ### Setting Object ACLs

You can set access control lists (ACLs) when uploading objects:

```bash
$ aws s3 cp local-file.txt s3://my-bucket-name/ \
  --acl public-read \
  --profile rabata
``` -->

### Multipart Uploads

For large files, the AWS CLI automatically uses multipart uploads:

```bash
$ aws s3 cp large-file.iso s3://my-bucket-name/ --profile rabata
```

### Using Presigned URLs

Generate a presigned URL to allow temporary access to an object:

```bash
$ aws s3 presign s3://my-bucket-name/private-file.txt \
  --expires-in 3600 \
  --profile rabata
```

This generates a URL that is valid for 3600 seconds (1 hour).

## Troubleshooting

Here are some common issues and their solutions when using the AWS CLI with Rabata.io.

### Connection Issues

If you're having trouble connecting to Rabata.io, check the following:

- Verify that the endpoint URL is correct: `https://s3.us-east-1.rabata.io`
- Check your internet connection
- Ensure your access key and secret key are correct

### Permission Denied

If you receive a "Permission Denied" error:

- Verify that your access key has the necessary permissions
- Check if the bucket or object exists
- Ensure you're using the correct profile with `--profile rabata`

### Debugging

You can enable debug mode to get more information about what's happening:

```bash
$ aws s3 ls --profile rabata --debug
```

---

<div class="docs-article__actions">
  <a href="/docs/getting-started/" class="btn btn--secondary">Back to Getting Started</a>
  <a href="/docs/quickstart/terraform/" class="btn btn--secondary">Terraform Quickstart</a>
</div>
