Documentation
Quick Start
Deploying via Infrastructure Tools
AWS CloudFormation

Installing serverless-iiif as part of a CloudFormation (opens in a new tab) template makes it easy to integrate the service with other components. Please refer to the example and the CloudFormation documentation (opens in a new tab) for more information on how you might tailor these templates to your own needs and deploy them to AWS.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

Type: AWS::Serverless::Application
Properties:
  Location:
    ApplicationId: arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif-standalone-dev
    SemanticVersion: 5.0.0
  Parameters:
    CorsAllowCredentials: String
    CorsAllowHeaders: String
    CorsAllowOrigin: String
    CorsExposeHeaders: String
    CorsMaxAge: Number
    ForceHost: String
    IiifLambdaMemory: Number
    IiifLambdaTimeout: Number
    PixelDensity: Number
    Preflight: String
    PyramidLimit: Number
    ResolverTemplate: String
    SharpLayer: String
    SourceBucket: String
 

Properties

CorsAllowCredentials

Value of the CORS Access-Control-Allow-Credentials response header. Must be true to allow requests with Authorization and/or Cookie headers.

Required: No

Type: String

Allowed Values: false | true

CorsAllowHeaders

Value of the CORS Access-Control-Allow-Headers response header

Required: No

Type: String

Default: *

CorsAllowOrigin

Value of the CORS Access-Control-Allow-Origin response header. Use the special value REFLECT_ORIGIN to copy the value from the Origin request header (required to emulate * for XHR requests using Authorization and/or Cookie headers).

Required: No

Type: String

Default: *

CorsExposeHeaders

Value of the CORS Access-Control-Expose-Headers response header

Required: No

Type: String

Default: cache-control,content-language,content-length,content-type,date,expires,last-modified,pragma

CorsMaxAge

Value of the CORS Access-Control-MaxAge response header

Required: No

Type: Number

Default: 3600

ForceHost

Forced hostname to use in responses

Required: No

Type: String

Default: ""

IiifLambdaMemory

The memory provisioned for the lambda.

Required: No

Type: Number

Default: 3008

Min Value: 128

Max Value: 10240

IiifLambdaTimeout

The timeout for the lambda.

Required: No

Type: Number

Default: 10

PixelDensity

Hardcoded DPI/Pixel Density/Resolution to encode in output images

Required: No

Type: Number

Default: 0

Min Value: 0

Preflight

Indicates whether the function should expect preflight headers

Required: No

Type: String

Allowed Values: false | true

PyramidLimit

Smallest pyramid image dimension. Set to 0 to prevent server from auto-calculating pyramid page sizes.

Required: No

Type: Number

Default: 256

Min Value: 0

ResolverTemplate

A printf-style format string that determines the location of source image within the bucket given the image ID

Required: No

Type: String

Default: %s.tif

SharpLayer

ARN of a custom AWS Lambda Layer containing the sharp and libvips dependencies. Use the special value JP2 to use the managed JPEG2000-compatible layer, or INTERNAL to use the built-in dependencies (without JPEG2000 support).

Required: No

Type: String

Default: JP2

Allowed Pattern: ^INTERNAL$|^JP2$|^arn:aws:lambda:.*:.*:layer:.+:\d+$

SourceBucket

Name of bucket containing source images

Required: Yes

Type: String

Example

This example template will deploy a full application stack consisting of:

  • A serverless-iiif image server
  • A CloudFront distribution with a custom hostname and SSL certificate
AWSTemplateFormatVersion: 2010-09-09
Description: IIIF Image server w/CloudFront Caching & Custom Hostname
Parameters:
  CacheDomainName:
    Type: String
    Description: Custom Domain Name for the CloudFront Cache
  CacheHostName:
    Type: String
    Description: Custom Hostname for the CloudFront Cache
  CacheSSLCertificate:
    Type: String
    Description: ARN of the ACM SSL Certification to use for the API Gateway
      Endpoint or CloudFront Cache
  IiifSourceBucket:
    Type: String
    Description: Name of bucket containing source images
Resources:
  ServerlessIiif:
    Type: AWS::Serverless::Application
    Properties:
      Location:
        ApplicationId: arn:aws:serverlessrepo:us-east-1:625046682746:applications/serverless-iiif-standalone-dev
        SemanticVersion: 5.0.3
      Parameters:
        SourceBucket: !Ref IiifSourceBucket
  ResponseHeaderPolicy:
    Type: AWS::CloudFront::ResponseHeadersPolicy
    Properties:
      ResponseHeadersPolicyConfig:
        Name: !Sub "${AWS::StackName}-allow-cors-response-headers"
        Comment: Allows IIIF CORS response headers
        CorsConfig:
          AccessControlAllowCredentials: false
          AccessControlAllowHeaders:
            Items:
              - "*"
          AccessControlAllowMethods:
            Items:
              - GET
              - OPTIONS
          AccessControlAllowOrigins:
            Items:
              - "*"
          AccessControlExposeHeaders:
            Items:
              - cache-control
              - content-language
              - content-length
              - content-type
              - date
              - expires
              - last-modified
              - pragma
          AccessControlMaxAgeSec: 3600
          OriginOverride: false
  CachingEndpoint:
    Type: AWS::CloudFront::Distribution
    Properties:
      DistributionConfig:
        Enabled: true
        PriceClass: PriceClass_100
        Aliases:
          - !Sub "${CacheHostName}.${CacheDomainName}"
        ViewerCertificate:
          AcmCertificateArn: !Ref CacheSSLCertificate
          MinimumProtocolVersion: TLSv1
          SslSupportMethod: sni-only
        Origins:
          - Id: IiifLambda
            CustomOriginConfig:
              OriginProtocolPolicy: https-only
            DomainName: !GetAtt ServerlessIiif.Outputs.FunctionDomain
        DefaultCacheBehavior:
          TargetOriginId: IiifLambda
          ViewerProtocolPolicy: https-only
          AllowedMethods:
            - GET
            - HEAD
            - OPTIONS
          CachedMethods:
            - GET
            - HEAD
          CachePolicyId: 658327ea-f89d-4fab-a63d-7e88639e58f6
          ResponseHeadersPolicyId: !Ref ResponseHeaderPolicy
  Route53Record:
    Type: AWS::Route53::RecordSet
    Properties:
      Name: !Sub "${CacheHostName}.${CacheDomainName}"
      HostedZoneName: !Sub "${CacheDomainName}."
      Type: A
      AliasTarget:
        DNSName: !GetAtt CachingEndpoint.DomainName
        HostedZoneId: Z2FDTNDATAQYW2
Outputs:
  EndpointV2:
    Description: IIIFv2 Endpoint URL
    Value: !Sub "https://${CacheHostName}.${CacheDomainName}/iiif/2"
  EndpointV3:
    Description: IIIFv3 Endpoint URL
    Value: !Sub "https://${CacheHostName}.${CacheDomainName}/iiif/3"
  DistributionId:
    Description: Caching Distribution ID
    Value: !Ref CachingEndpoint
    Export:
      Name: !Sub "${AWS::StackName}:DistributionId"