Skip to content

Commit

Permalink
🚧 s3client doesn't work inside worker, removing it
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Aug 8, 2024
1 parent b052167 commit 54c6f8d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
56 changes: 28 additions & 28 deletions functions/_common/grapherRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ import { Env } from "../grapher/thumbnail/[slug].js"
import { R2GrapherConfigDirectory } from "@ourworldindata/types"
import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3"

Check warning on line 21 in functions/_common/grapherRenderer.ts

View workflow job for this annotation

GitHub Actions / eslint

'GetObjectCommand' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 21 in functions/_common/grapherRenderer.ts

View workflow job for this annotation

GitHub Actions / eslint

'S3Client' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 21 in functions/_common/grapherRenderer.ts

View workflow job for this annotation

GitHub Actions / eslint

'GetObjectCommand' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 21 in functions/_common/grapherRenderer.ts

View workflow job for this annotation

GitHub Actions / eslint

'S3Client' is defined but never used. Allowed unused vars must match /^_/u

async function getFileFromR2(key: string, env: Env): Promise<string | null> {
const s3Client = new S3Client({
endpoint: env.R2_ENDPOINT,
forcePathStyle: false,
region: env.R2_REGION,
credentials: {
accessKeyId: env.R2_ACCESS_KEY_ID,
secretAccessKey: env.R2_SECRET_ACCESS_KEY,
},
})

const params = {
Bucket: env.GRAPHER_CONFIG_R2_BUCKET,
Key: key,
}

try {
console.log("preparing s3 get")
const response = await s3Client.send(new GetObjectCommand(params))
console.log("got s3 response")
const content = await response.Body.transformToString()
console.log("got s3 content")
return content
} catch (err) {
if (err.name === "NoSuchKey") return null
else throw err
}
}
// async function getFileFromR2(key: string, env: Env): Promise<string | null> {
// const s3Client = new S3Client({
// endpoint: env.R2_ENDPOINT,
// forcePathStyle: false,
// region: env.R2_REGION,
// credentials: {
// accessKeyId: env.R2_ACCESS_KEY_ID,
// secretAccessKey: env.R2_SECRET_ACCESS_KEY,
// },
// })

// const params = {
// Bucket: env.GRAPHER_CONFIG_R2_BUCKET,
// Key: key,
// }

// try {
// console.log("preparing s3 get")
// const response = await s3Client.send(new GetObjectCommand(params))
// console.log("got s3 response")
// const content = await response.Body.transformToString()
// console.log("got s3 content")
// return content
// } catch (err) {
// if (err.name === "NoSuchKey") return null
// else throw err
// }
// }

declare global {
// eslint-disable-next-line no-var
Expand Down
1 change: 0 additions & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "owid-functions",
"dependencies": {
"@aws-sdk/client-s3": "3.572.0",
"@ourworldindata/grapher": "workspace:^",
"@ourworldindata/utils": "workspace:^",
"itty-router": "^5.0.17",
Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ __metadata:
languageName: node
linkType: hard

"@aws-sdk/client-s3@npm:3.572.0, @aws-sdk/client-s3@npm:^3.572.0":
"@aws-sdk/client-s3@npm:^3.572.0":
version: 3.572.0
resolution: "@aws-sdk/client-s3@npm:3.572.0"
dependencies:
Expand Down Expand Up @@ -15274,7 +15274,6 @@ __metadata:
version: 0.0.0-use.local
resolution: "owid-functions@workspace:functions"
dependencies:
"@aws-sdk/client-s3": "npm:3.572.0"
"@cloudflare/workers-types": "npm:^4.20240614.0"
"@ourworldindata/grapher": "workspace:^"
"@ourworldindata/utils": "workspace:^"
Expand Down

0 comments on commit 54c6f8d

Please sign in to comment.