Created
April 17, 2023 19:33
-
-
Save statico/9a746d404c7379b42e59daf034925523 to your computer and use it in GitHub Desktop.
sanity blog backup to lambda (not working because of --raw)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global fetch*/ | |
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3"; | |
const client = new S3Client({}); | |
export const handler = async (event) => { | |
const projectId = process.env.SANITY_PROJECT_ID | |
const dataset = process.env.SANITY_DATASET | |
const token = process.env.SANITY_TOKEN | |
const bucket = process.env.S3_BUCKET | |
const date = new Date().toISOString() | |
// https://www.sanity.io/docs/export | |
const url = `https://${projectId}.api.sanity.io/v2021-06-07/data/export/${dataset}` | |
const headers = { | |
Authorization: `Bearer ${token}` | |
} | |
const res = await fetch(url, { headers }) | |
const data = await res.text() | |
// https://docs.aws.amazon.com/AmazonS3/latest/userguide/example_s3_PutObject_section.html | |
const command = new PutObjectCommand({ | |
Bucket: bucket, | |
Key: `sanity-${projectId}-${dataset}-${date}.ndjson`, | |
Body: data | |
}) | |
await client.send(command) | |
const response = { statusCode: 200, body: 'ok' } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't work because of https://www.sanity.io/help/import-asset-has-different-target