Skip to content

Commit

Permalink
Account for possible path prefix in cloudfront invalidation (bluesky-…
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy authored Apr 7, 2023
1 parent f818d1c commit 2aeda0f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 8 additions & 6 deletions packages/aws/src/cloudfront.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import * as aws from '@aws-sdk/client-cloudfront'

export type CloudfrontConfig = { distributionId: string } & Omit<
aws.CloudFrontClientConfig,
'apiVersion'
>
export type CloudfrontConfig = {
distributionId: string
pathPrefix?: string
} & Omit<aws.CloudFrontClientConfig, 'apiVersion'>

export class CloudfrontInvalidator implements ImageInvalidator {
distributionId: string
pathPrefix: string
client: aws.CloudFront
constructor(cfg: CloudfrontConfig) {
const { distributionId, ...rest } = cfg
const { distributionId, pathPrefix, ...rest } = cfg
this.distributionId = distributionId
this.pathPrefix = pathPrefix ?? ''
this.client = new aws.CloudFront({
...rest,
apiVersion: '2020-05-31',
Expand All @@ -23,7 +25,7 @@ export class CloudfrontInvalidator implements ImageInvalidator {
CallerReference: `cf-invalidator-${subject}-${Date.now()}`,
Paths: {
Quantity: paths.length,
Items: paths,
Items: paths.map((path) => this.pathPrefix + path),
},
},
})
Expand Down
7 changes: 4 additions & 3 deletions packages/pds/service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ const main = async () => {
schema: env.dbSchema,
})
const s3Blobstore = new S3BlobStore({ bucket: env.s3Bucket })
const cfInvalidator = new CloudfrontInvalidator({
distributionId: env.cfDistributionId,
})
const repoSigningKey = await Secp256k1Keypair.import(env.repoSigningKey)
const plcRotationKey = await KmsKeypair.load({
keyId: env.plcRotationKeyId,
Expand All @@ -59,6 +56,10 @@ const main = async () => {
password: env.smtpPassword,
}),
})
const cfInvalidator = new CloudfrontInvalidator({
distributionId: env.cfDistributionId,
pathPrefix: cfg.imgUriEndpoint && new URL(cfg.imgUriEndpoint).pathname,
})
const pds = PDS.create({
db,
blobstore: s3Blobstore,
Expand Down

0 comments on commit 2aeda0f

Please sign in to comment.