Quickstart Guide for AWS CLI and Backblaze B2 Cloud Storage Quickstart Guide for AWS CLI and Backblaze B2 Cloud Storage

Quickstart Guide for AWS CLI and Backblaze B2 Cloud Storage

Udara Gunawardena Udara Gunawardena

Using B2’s S3 endpoints you are able to use AWS CLI to communicate and update your B2 buckets. Once configured you can use this tool to transfer data between and S3 bucket and B2.


Start by installing AWS CLI. You can do this by following the instructions
here.

Confirm that it is installed by using aws --version.

 

Configuring AWS CLI to interface with your B2 account:

Step 1:

Use the command aws configure to start the configuration process.

 

You will be prompted with the following. You can find information highlighted in red by creating keys in the “App Key” section of your Backblaze account. Note that your Master Application Key will not work with the S3 Compatible API. You must create a new key that is eligible for use. For more information: https://help.backblaze.com/hc/en-us/articles/360047425453

 

AWS Access Key ID [None]: keyID

AWS Secret Access Key [None]: applicationKey

Default region name [None]: leave blank

Default output format [None]: leave blank

 

Step 2:

Configuration should be set now. You should be able to test the integration by attempting to list buckets on your account.

aws s3 ls --endpoint-url=<S3 Endpoint URL>

 

For example:

 

Using AWS CLI to transfer data to B2

Step 1 (Optional):

If data is coming from an AWS S3 Bucket, you will first need to add your S3 buckets using the configuration tool.

Then you will need to copy files to a local directory using the command:

aws s3 cp s3://<source_bucket>/ <local_directory> --recursive

 

Step 2:

Now you can transfer files directly to B2 using the command:

aws s3 cp <local_directory>/ s3://<destination_bucket>/ --recursive --endpoint-url=<S3 Endpoint URL>

 

 

Creating presigned URLs from AWS CLI

Generating a presigned URL on a bucket that expires in 3600 seconds (default)

aws s3 presign s3://<destination_bucket>/  --endpoint-url=<S3 Endpoint URL>

 

Generating a presigned URL on a folder in a bucket, that expires in 360 seconds

aws s3 presign s3://<destination_bucket>/<folder>/<object-name> --expires-in 300 --endpoint-url=<S3 Endpoint URL>

 

Example:

aws s3 presign s3://allgroups/mygroup/  --expires-in 300 --endpoint-url=https://s3.us-west-002.backblazeb2.com

Output:
https://s3.us-west-002.backblazeb2.com/allgroups/mygroup/?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=002b1af53845f82000000000b%2F20200917%2Fus-west-002%2Fs3%2Faws4_request&X-Amz-Date=20200917T205553Z&X-Amz-Expires=300&X-Amz-SignedHeaders=host&X-Amz-Signature=731d32987530b9fdf76b59d9c84c8fb91a5548ac3b6f708d92de153564542878

Note: Depending on how you are using the presigned URL, you may need to enclose it in quotes.

 

The S3 Compatible API for Backblaze B2 Cloud Storage allows 1000’s of integrations to work with B2 natively. If you’re new to the S3 Compatible API, please see our Getting Started Guide. If you have any trouble using the AWS CLI with B2, please let us know by emailing us at b2feedback@backblaze.com