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
SourceBucket: String
Properties
CorsAllowCredentialsValue of the CORS
Access-Control-Allow-Credentialsresponse header. Must betrueto allow requests withAuthorizationand/orCookieheaders.Required: No
Type: String
Allowed Values:
false | trueCorsAllowHeadersValue of the CORS
Access-Control-Allow-Headersresponse headerRequired: No
Type: String
Default:
*CorsAllowOriginValue of the CORS
Access-Control-Allow-Originresponse header. Use the special valueREFLECT_ORIGINto copy the value from theOriginrequest header (required to emulate*for XHR requests usingAuthorizationand/orCookieheaders).Required: No
Type: String
Default:
*CorsExposeHeadersValue of the CORS
Access-Control-Expose-Headersresponse headerRequired: No
Type: String
Default:
cache-control,content-language,content-length,content-type,date,expires,last-modified,pragmaCorsMaxAgeValue of the CORS
Access-Control-MaxAgeresponse headerRequired: No
Type: Number
Default:
3600ForceHostForced hostname to use in responses
Required: No
Type: String
Default:
""IiifLambdaMemoryThe memory provisioned for the lambda.
Required: No
Type: Number
Default:
3008Min Value:
128Max Value:
10240IiifLambdaTimeoutThe timeout for the lambda.
Required: No
Type: Number
Default:
10PixelDensityHardcoded DPI/Pixel Density/Resolution to encode in output images
Required: No
Type: Number
Default:
0Min Value:
0PreflightIndicates whether the function should expect preflight headers
Required: No
Type: String
Allowed Values:
false | truePyramidLimitSmallest pyramid image dimension. Set to
0to prevent server from auto-calculating pyramid page sizes.Required: No
Type: Number
Default:
256Min Value:
0ResolverTemplateA printf-style format string that determines the location of source image within the bucket given the image ID
Required: No
Type: String
Default:
%s.tifSourceBucketName 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
SemanticVersion: 6.0.1
Parameters:
ForceHost: !Sub "${CacheHostName}.${CacheDomainName}"
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"