Transfers from Amazon S3 can use an
[Amazon CloudFront](https://aws.amazon.com/cloudfront/) distribution as an
egress path.
Data transfers through CloudFront may benefit from lower AWS egress costs compared to transferring directly from S3. See [CloudFront pricing](https://aws.amazon.com/cloudfront/pricing/) and [S3 egress charges](https://aws.amazon.com/s3/pricing/) for details.

Using CloudFront as the egress path does not expose your S3 objects to the
public. See
[Does using CloudFront expose my objects to the public?](https://docs.cloud.google.com/storage-transfer/docs/s3-cloudfront.md.txt#does_cloudfront_expose_objects)

## Overview

In order to transfer S3 data through CloudFront, you must follow these steps:

- [Configure IAM permissions](https://docs.cloud.google.com/storage-transfer/docs/s3-cloudfront.md.txt#iam)
- [Configure access to your S3 bucket](https://docs.cloud.google.com/storage-transfer/docs/s3-cloudfront.md.txt#s3-access)
- [Create a CloudFront distribution for your S3 bucket](https://docs.cloud.google.com/storage-transfer/docs/s3-cloudfront.md.txt#create-cf)
- [Create a transfer job](https://docs.cloud.google.com/storage-transfer/docs/s3-cloudfront.md.txt#create-job)

## Configure IAM permissions

Follow the instructions in
[Configure access to a sink: Cloud Storage](https://docs.cloud.google.com/storage-transfer/docs/sink-cloud-storage.md.txt) to grant the
required Google Cloud permissions on the destination bucket.

## Configure access to your S3 bucket

Follow the instructions in
[Configure access to a source: Amazon S3](https://docs.cloud.google.com/storage-transfer/docs/source-amazon-s3.md.txt)
to configure access to your data in Amazon S3.

## Create a CloudFront distribution for your S3 bucket

1. In your AWS account, go to **CloudFront**.
2. Click **Create a CloudFront distribution**.
3. Under **Origin domain** select your S3 bucket.
4. **Origin path** must be left empty.
5. Accept the auto-filled **Origin name** or specify your own value.
6. In the **Origin access** section, select *Public*. This does not make your bucket public; instead it indicates to CloudFront that no access mechanism should be configured.
7. In the **Cache key and origin requests** section:
   1. For **Cache policy** select *CachingDisabled*. This prevents CloudFront from caching requests and serving them to unauthenticated viewers.
   2. For **Origin request policy** select *AllViewerExceptHostHeader*. This allows CloudFront to forward authentication headers to S3, so that Storage Transfer Service can access your bucket with your secure credentials.
8. In the **Web Application Firewall (WAF)** section, select *Do not enable*.
9. Optionally, choose a **Price class** . Storage Transfer Service selects worker pools based on the source bucket's region, so CloudFront pricing is incurred in that region. To obtain the lowest pricing, either ensure that your source bucket is in the US or Europe, or select *Use only North America and Europe* as the **Price class** in CloudFront.
10. Click **Create CloudFront distribution**.

    Once successfully created, the CloudFront distribution details page is
    displayed.
11. Note the **Distribution domain name** . For example:
    `https://dy1h2n3l4ob56.cloudfront.net`. If the details page doesn't include
    the `https://` protocol in front of the distribution domain name, you'll need
    to add it yourself when creating the transfer job.

## Create a transfer job

Transferring via a CloudFront distribution is supported in the Google Cloud console
and the REST API.
Don't include sensitive information such as personally identifiable information (PII) or security data in your transfer job name. Resource names may be propagated to the names of other Google Cloud resources and may be exposed to Google-internal systems outside of your project.

<br />

### Google Cloud console

To create a transfer using a the Google Cloud console, follow the
instructions to
[create a transfer](https://docs.cloud.google.com/storage-transfer/docs/create-transfers.md.txt?tab=google-cloud-console#create_a_transfer).

When prompted to enter the **CloudFront domain** , enter the distribution
domain name you noted in the previous section. You can also find this value
listed in the CloudFront section of the Amazon Web Services console. It has
the format `https://dy1h2n3l4ob56.cloudfront.net`.

### REST API

To create a transfer using the REST API, follow the example on the
[Create transfers](https://docs.cloud.google.com/storage-transfer/docs/create-transfers.md.txt?tab=rest#s3-to-cloud)
page.

Specify the distribution domain name as the value of the
`transferSpec.awsS3DataSource.cloudfrontDomain` field:

```json
"transferSpec": {
  "awsS3DataSource": {
    "bucketName": "AWS_SOURCE_NAME",
    "cloudfrontDomain": "https://dy1h2n3l4ob56.cloudfront.net",
    "awsAccessKey": {
      "accessKeyId": "AWS_ACCESS_KEY_ID",
      "secretAccessKey": "AWS_SECRET_ACCESS_KEY"
    }
  },
  ...
}
```

## Troubleshooting

### AuthorizationHeaderMalformed error

If you encounter an `AuthorizationHeaderMalformed` error that specifies a
region mismatch (for example, `the region 'Location A' is wrong; expecting
'Location B'`), it is likely due to an unsupported CloudFront configuration.

This error occurs if you use a single CloudFront distribution to front multiple
S3 buckets that reside in different AWS regions.

To resolve this issue, ensure that each CloudFront distribution fronts S3
buckets in only a single AWS region. If you have S3 buckets in different
regions, create a separate CloudFront distribution for each region.

## Frequently asked questions

### Does using CloudFront expose my objects to the public?

No. If you've followed the configuration steps on this page, your objects are
not exposed to the public.

- Cloudfront does not have direct access to your S3 objects.
- Users receive a `permission denied` error if they try to access your objects either directly or through CloudFront (if your bucket is private).
- Storage Transfer Service signs requests to CloudFront using the credentials you provided in the transfer job, which allows us to download your objects securely as if we were downloading directly from S3. This works due to the header forwarding setting `AllViewerExceptHostHeader`.