The solution you're looking for is as follows:
- Create a Lambda@Edge function for the origin request behaviour.
- When triggered use SDK to do a check in one of the buckets to check if its there.
- If it is then update the origin/path in the request to become the correct destination.
By calling the head-object command against the first bucket you can verify the object exists there.
It would look similar to this pseudocode
import boto3
client = boto3.client('s3')
def lambda_handler(event, context):
request = event['Records'][0]['cf']['request']"
key = //Code to get the key path from request
try:
s3_client.head_object(Bucket='string', Key=key)
except ClientError as e:
return request
request.origin.s3.domainName = \\Insert domain name here
return request
An in depth tutorial can be found here.