UNPKG

864 BJavaScriptView Raw
1const AWS = require('./aws-helper')
2
3/** Verifies AWS credentials by accessing S3
4 * Returns a promise
5 * Options object keys:
6 * filepath: 'specify path to credentials file if not ~/.aws/credentials '
7 * credentials: 'an object containing accessKeyId and secretAccessKey if not using values in ~/.aws/credentials'
8 */
9module.exports = async (opts = {}) => {
10 if (opts.filepath) {
11 const creds = new AWS.SharedIniFileCredentials({ filename: opts.filepath })
12 AWS.config.credentials = creds
13 }
14 const awsParams = {
15 params: {
16 Bucket: 'trmr-animate-vpaid',
17 ACL: 'public-read'
18 }
19 }
20 if (opts.credentials) {
21 Object.assign(awsParams, opts.credentials)
22 }
23 const s3 = new AWS.S3(awsParams)
24 await s3.putObject({
25 ContentType: 'application/json',
26 Body: JSON.stringify({}),
27 Key: 'test/access.json'
28 }).promise()
29}