Can I compare images across S3 buckets in different regions with AWS Rekognition?

28 Views Asked by At

I'm having a problem with AWS Rekognition's CompareFaces function, trying to compare two images stored in S3 buckets in different regions:

import { RekognitionClient, CompareFacesCommand } from "@aws-sdk/client-rekognition"

const client = new RekognitionClient({
  region: process.env.AWS_REGION,
});

const faceCommand = new CompareFacesCommand({
  TargetImage: 
  S3Object: {
      Bucket: PRIMARY_BUCKET_NAME,
      Name: key
    }
  },
  SourceImage: {
    S3Object: {
      Bucket: LIVENESS_BUCKET_NAME,
      Name: referenceKey
    }
  }
})

const faceRes = await client.send(faceCommand)

I get this message from the SDK:

Unable to get object metadata from S3. Check object key, region and/or access permissions

I'm trying to do this because one of the images is the reference image from a Rekognition liveness check. The reference image has to be stored in one of the small subset of supported AWS regions:

Note that the Amazon S3 bucket must be located in the caller's AWS account and in the same region as the Face Liveness end-point.

The rest of my app, including the image I'd like to compare to, is hosted in a different AWS region that is closer to my users, as well as making compliance easier.

I'm sure that the regions are the issue—if I try to compare two files in the same bucket (either region) the error goes away.

In order of preference, I think the solutions are:

  1. find a way to compare these two images across regions (ideal!)
  2. temporarily copy the reference image across to a third s3 bucket in my "native" region, where we can then run the comparison (will increase the storage space needed as well as adding more things to go wrong)
  3. move the entire app to one of Rekognition's special regions (not gonna happen)
  4. a secret fourth thing I haven't thought of

Is what I want possible?

1

There are 1 best solutions below

0
John Rotenstein On

New features eventually spread out to all regions, so I would recommend a temporary approach.

You can use Amazon S3 cross-region replication to automatically the image to a bucket in another region. It's a fully-managed capability, so there is little concern about "more things to go wrong".

Yes, it will cost more for storage but you could delete the target image after processing or configure the source bucket to automatically delete objects after a period of time.