Created
September 29, 2021 16:14
-
-
Save Dylan0916/0256cc14a840fc814a64b943390abd22 to your computer and use it in GitHub Desktop.
get 與 put 的 S3 操作示範
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
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