Created
April 11, 2019 18:24
-
-
Save andreybleme/7f88229382a6270ee62e94adbb923172 to your computer and use it in GitHub Desktop.
andreybleme.com | Criando uma CLI para fazer deploy de sites estáticos
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') | |
function setAwsCredentials(awsCredentials) { | |
AWS.config.update(awsCredentials) | |
} | |
function createBucket(bucketParams, staticHostParams) { | |
const s3 = new AWS.S3() | |
s3.createBucket(bucketParams, function(err, data) { | |
if (err) { | |
console.log('Error creating bucket: ', err) | |
} else { | |
console.log('Successfully created bucket at ', data.Location) | |
setPoliciesForWebSiteHosting(staticHostParams) | |
} | |
}); | |
} | |
function setPoliciesForWebSiteHosting(staticHostParams) { | |
const s3 = new AWS.S3() | |
s3.putBucketWebsite(staticHostParams, function(err, data) { | |
if (err) { | |
console.log('Error defining policies: ', err) | |
} else { | |
console.log('Successfully defined static hosting policies.') | |
} | |
}); | |
} | |
module.exports = { | |
setAwsCredentials, | |
createBucket | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment