samvera / serverless-iiif

IIIF Image API 2.1 & 3.0 server in an AWS Serverless Application
https://samvera.github.io/serverless-iiif/
Apache License 2.0
69 stars 21 forks source link

can one define a custom host name in place of the Lambda host name #140

Closed rchavez-neu closed 5 months ago

rchavez-neu commented 5 months ago

Question about an issues I'm running into regarding the host name as set in the info.json file.

Long story short (I hope): our IT department now requires us to restrict access to the IIIF Lamba URI to an IAM role, which basically means no more public access to the IIIF Lamba URL. I have a fix in place using CloudFront and Lambda@Edge. The CloudFront has an assigned domain name. Calls directly to CloudFront for image work fine, e.g.:

https://images.library.northeastern.edu/iiif/2/images%2F2047%2FD20211702%2Fm040b174r/full/full/0/default.jpg

However, one of our projects (a page turner) uses the info.json file to obtain the @id value to construct requests for images at various sizes.

The info.json file, always contains a the host URL of the IIIF Lambda service. For example, this info.json file

https://images.library.northeastern.edu/iiif/2/images%2F2047%2FD20211702%2Fm040b174r/info.json

contains an @id where the host URL is https://cthrrlqytftvrwusyfntodhzam0keaum.lambda-url.us-east-1.on.aws. Since this URL is now restricted, all image calls now fail.

My question is: is there a known method/config file/variable in the IIIF Lambda code to configure a host URL, e.g. images.library.northeastern.edu so that the info.json file will use the configured host URL rather than the native Lambda service URL?

This would basically mean that images.library.northeastern.edu would appear in the info.jon file for any image as opposed to cthrrlqytftvrwusyfntodhzam0keaum.lambda-url.us-east-1.on.aws.

Thank you!

mbklein commented 5 months ago

Yes, that's what the ForceHost parameter is for in the deployment template. You can either:

  1. Redeploy/update your stack setting ForceHost to images.library.northeastern.edu
  2. Add a forceHost (note the capitalization difference) environment variable to the lambda's configuration manually

(Note that the latter option will cause stack drift, and the environment variable will be reverted the next time you run a changeset through that SAM/CloudFormation stack).

rchavez-neu commented 5 months ago

I overlooked this in the initial deploy.

Excellent, method #1 worked perfectly for me. Thank you for getting back to me so quickly.

Note for posterity: if using CLoudFront, invalidate the CloudFront cache after making this change to clear out previous (bad) image requests.