From 089d13d6379895da6ffc0cabc8aef4afbd725704 Mon Sep 17 00:00:00 2001 From: Brandon Liu Date: Tue, 10 Sep 2024 22:45:40 -0700 Subject: [PATCH] AWS updates (#447) * AWS updates * CloudFormation stack parameter for changing CloudFront tile cache TTL. * S3 requests are always set as Requester Pays, enabling fetching from buckets in other accounts. --- serverless/aws/protomaps-template.yaml | 12 +++++++++--- serverless/aws/src/index.ts | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/serverless/aws/protomaps-template.yaml b/serverless/aws/protomaps-template.yaml index d48ac00..34d3fbe 100644 --- a/serverless/aws/protomaps-template.yaml +++ b/serverless/aws/protomaps-template.yaml @@ -2,10 +2,15 @@ AWSTemplateFormatVersion: '2010-09-09' Description: Serve Z/X/Y tiles through CloudFront + Lambda from an existing S3 bucket. Parameters: BucketName: - Description: 'Name of an existing S3 bucket with .pmtiles tilesets. Should be in the same region as your CloudFormation stack.' + Description: 'Name of an existing S3 bucket with .pmtiles tilesets. Should be in the same region as your CloudFormation stack. Can be a RequesterPays bucket in another account.' Type: String MinLength: 1 + DefaultTTL: + Description: Default time-to-live for cached tiles in the CloudFront distribution. + Type: Number + Default: 86400 + AllowedOrigins: Description: 'Comma-separated list of domains (e.g. example.com) allowed by browser CORS policy, or * for all origins.' Type: List @@ -17,11 +22,12 @@ Parameters: Outputs: CloudFrontDistributionUrl: - Description: 'URL of the CloudFront distribution' + Description: 'URL of the CloudFront distribution for cached tiles.' Value: !Sub "https://${CloudFrontDistribution.DomainName}" Export: Name: !Sub "${AWS::StackName}-CloudFrontDistributionURL" + Conditions: IsPublicHostnameProvided: Fn::Not: @@ -127,7 +133,7 @@ Resources: Properties: CachePolicyConfig: Name: !Sub "${AWS::StackName}-CachePolicyConfig" - DefaultTTL: 86400 + DefaultTTL: !Ref DefaultTTL MaxTTL: 31536000 MinTTL: 0 ParametersInCacheKeyAndForwardedToOrigin: diff --git a/serverless/aws/src/index.ts b/serverless/aws/src/index.ts index 2ba3153..1322db0 100644 --- a/serverless/aws/src/index.ts +++ b/serverless/aws/src/index.ts @@ -77,6 +77,8 @@ class S3Source implements Source { Range: "bytes=" + offset + "-" + (offset + length - 1), // biome-ignore lint: aws api IfMatch: etag, + // biome-ignore lint: aws api + RequestPayer: "requester", }) ); } catch (e: unknown) {