AWS integration
Last updated Apr 17, 2026 This guide will walk you through how to set up per-hostname authenticated origin pulls to securely connect to an AWS Application Load Balancer using mutual TLS verify ↗︎.
Before you begin
- You should already have your AWS account and EC2 ↗︎ configured.
- Note that this tutorial uses command-line interface (CLI) to generate a custom certificate, and API calls to configure Cloudflare Authenticated Origin Pulls.
- For the most up-to-date documentation on how to set up AWS, refer to the AWS documentation ↗︎.
1. Generate a custom certificate
- Run the following command to generate a 4096-bit RSA private key, using AES-256 encryption. Enter a passphrase when prompted.
openssl genrsa -aes256 -out rootca.key 4096
- Create the CA root certificate. When prompted, fill in the information to be included in the certificate. For the
Common Namefield, use the domain name as value, not the hostname.
openssl req -x509 -new -nodes -key rootca.key -sha256 -days 1826 -out rootca.crt
- Create a Certificate Signing Request (CSR). When prompted, fill in the information to be included in the request. For the
Common Namefield, use the hostname as value.
openssl req -new -nodes -out cert.csr -newkey rsa:4096 -keyout cert.key
- Sign the certificate using the
rootca.keyandrootca.crtcreated in previous steps.
openssl x509 -req -in cert.csr -CA rootca.crt -CAkey rootca.key -CAcreateserial -out cert.crt -days 730 -sha256 -extfile ./cert.v3.ext
- Make sure the certificate extensions file
cert.v3.extspecifies the following:
basicConstraints=CA:FALSE
2. Configure AWS Application Load Balancer
- Upload the
rootca.certto an S3 bucket ↗︎. - Create a trust store ↗︎ at your EC2 console, indicating the S3 URI where you uploaded the certificate.
- Create an EC2 instance and install an HTTPD daemon. Choose an instance type ↗︎ according to your needs - it can be a minimal instance eligible to AWS Free Tier ↗︎. This tutorial was based on an example using t2.micro and Amazon Linux 2023 ↗︎.
sudo yum install -y httpd
sudo systemctl start httpd
- Create a target group ↗︎ for your Application Load Balancer.
- Choose Instances as target type.
- Specify port
HTTP/80. - After you finish configuring the target group, confirm that the target group is healthy ↗︎.
- Configure a load balancer and a listener ↗︎.
- Choose the Internet-facing scheme.
- Switch the listener to port
443so that the mTLS option is available, and select the target group created in previous steps. - For Default SSL/TLS server certificate, choose Import certificate > Import to ACM, and add the certificate private key and body.
- Under Client certificate handling, select Verify with trust store.
- Save your settings.
- (Optional) Run the following commands to confirm that the Application Load Balancing is asking for the client certificate.
openssl s_client -verify 5 -connect <your-application-load-balancer>:443 -quiet -state
Since you have not yet uploaded the certificate to Cloudflare, the connection should fail (read:errno=54, for example).
You can also run curl --verbose and confirm Request CERT (13) is present within the SSL/TLS handshake:
curl --verbose https://<your-application-load-balancer>
...
* TLSv1.2 (IN), TLS handshake, Request CERT (13):
...
3. Configure Cloudflare
- Upload the certificate you created in Step 1 to Cloudflare. You should use the leaf certificate, not the root CA.
MYCERT="$(cat cert.crt|perl -pe 's/\r?\n/\\n/'|sed -e 's/..$//')"
MYKEY="$(cat cert.key|perl -pe 's/\r?\n/\\n/'|sed -e's/..$//')"
request_body=$(< <(cat <<EOF
{
"certificate": "$MYCERT",
"private_key": "$MYKEY",
"bundle_method":"ubiquitous"
}
EOF
))
# Push the certificate
curl --silent \
"https://api.cloudflare.com/client/v4/zones/$ZONEID/origin_tls_client_auth/hostnames/certificates" \
--header "Content-Type: application/json" \
--header "X-Auth-Email: $MYAUTHEMAIL" \
--header "X-Auth-Key: $MYAUTHKEY" \
--data "$request_body"
- Associate the certificate with the hostname that should use it.
<details>
<summary>
Required API token permissions
</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:
- <code>SSL and Certificates Write</code>
</details>
Enable or Disable a Hostname for Client Authenticationbash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/origin_tls_client_auth/hostnames" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"config": [
{
"enabled": true,
"cert_id": "<CERT_ID>",
"hostname": "<YOUR_HOSTNAME>"
}
]
}'
Note
Make sure your encryption mode is set to Full or higher. If you only want to adjust this setting for a specific hostname, use Configuration Rules.
Roll back the Cloudflare configuration
- Use a
PUTrequest to disable Authenticated Origin Pulls on the hostname.<details><summary>
Required API token permissions</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required: - <code>SSL and Certificates Write</code></details>
Enable or Disable a Hostname for Client Authenticationbash
bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/origin_tls_client_auth/hostnames" \
--request PUT \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"config": [
{
"enabled": false,
"cert_id": "<CERT_ID>",
"hostname": "<YOUR_HOSTNAME>"
}
]
}'
- (Optional) Use a
GETrequest to obtain a list of the client certificate IDs. You will need the ID of the certificate you want to remove for the following step.<details><summary>
Required API token permissions</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required: - <code>SSL and Certificates Write</code> - <code>SSL and Certificates Read</code></details>
List Certificatesbash
bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/origin_tls_client_auth/hostnames/certificates" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
- Use the Delete hostname client certificate endpoint to remove the certificate you had uploaded.<details><summary>
Required API token permissions</summary>
At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required: - <code>SSL and Certificates Write</code></details>
Delete Hostname Client Certificatebash
bash
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/origin_tls_client_auth/hostnames/certificates/$CERTIFICATE_ID" \
--request DELETE \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull/aws-alb-integration/#page","headline":"AWS integration","description":"Learn how to set up Cloudflare Authenticated Origin Pulls with the AWS Application Load Balancer.","url":"https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull/aws-alb-integration/","inLanguage":"en","image":"https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull/aws-alb-integration/og.png?v=78e3120b25b84146","dateModified":"2026-04-17","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["AWS"]}
description: How Authenticated Origin Pulls use mTLS to verify Cloudflare connections. title: About image: https://developers.cloudflare.com/ssl/origin-configuration/authenticated-origin-pull/explanation/og.png?v=8e3d0c02dfacbbb0
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/ssl/llms.txt
Use this file to discover all available pages before exploring further.
Docs