Skip to content

Instantly share code, notes, and snippets.

@Dylan0916
Created September 29, 2021 16:14
Show Gist options
  • Save Dylan0916/0256cc14a840fc814a64b943390abd22 to your computer and use it in GitHub Desktop.
Save Dylan0916/0256cc14a840fc814a64b943390abd22 to your computer and use it in GitHub Desktop.
get 與 put 的 S3 操作示範
const aws = require("aws-sdk");
const s3 = new aws.S3();
const bucketName = "test-firebase-dynamic-links";
const s3FileName = "links_map.json";
function getDataFromS3() {
const params = {
Bucket: bucketName,
Key: s3FileName,
};
return s3
.getObject(params)
.promise()
.then((resp) => resp.Body.toString("utf-8"))
.then((stringData) => JSON.parse(stringData));
}
function putDataToS3(data) {
const params = {
Bucket: bucketName,
Key: s3FileName,
Body: JSON.stringify(data),
ContentType: "application/json",
};
return s3.putObject(params).promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment