-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
<
34 lines (29 loc) · 733 Bytes
/
<
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import AWS from 'aws-sdk'
export const BUCKET_NAME = process.env.BUCKET_NAME
const S3_ENDPOINT_URL = process.env.S3_ENDPOINT_URL
const ID = process.env.ACCESS_KEY_ID
const SECRET = process.env.ACCESS_KEY
// Create S3 service object
export const s3 = new AWS.S3({
endpoint: S3_ENDPOINT_URL,
credentials: {
accessKeyId: ID,
secretAccessKey: SECRET,
},
})
export const testStorage = async () => {
try {
const data = await s3
.getObject({
Bucket: BUCKET_NAME,
Key: 'yo.txt',
})
.promise()
console.log(
`Successfully read test file from ${BUCKET_NAME} : S3 storage works.`
)
console.log(`<<${data.Body.toString('utf-8')}>>`)
} catch (e) {
console.log('Problem fetching S3 test object', e)
}
}