Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly display s3 url based on documentation #2

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@ const _ = require('lodash');
const mime = require('mime');
const fs = require('fs');

// per http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints
const regionToUrlRootMap = region => ({
'us-east-2': 's3-website.us-east-2.amazonaws.com',
'us-east-1': 's3-website-us-east-1.amazonaws.com',
'us-west-1': 's3-website-us-west-1.amazonaws.com',
'us-west-2': 's3-website-us-west-2.amazonaws.com',
'ca-central-1': 's3-website.ca-central-1.amazonaws.com',
'ap-south-1': 's3-website.ap-south-1.amazonaws.com',
'ap-northeast-2': 's3-website.ap-northeast-2.amazonaws.com',
'ap-southeast-1': 's3-website-ap-southeast-1.amazonaws.com',
'ap-southeast-2': 's3-website-ap-southeast-2.amazonaws.com',
'ap-northeast-1': 's3-website-ap-northeast-1.amazonaws.com',
'eu-central-1': 's3-website.eu-central-1.amazonaws.com',
'eu-west-1': 's3-website-eu-west-1.amazonaws.com',
'eu-west-2': 's3-website.eu-west-2.amazonaws.com',
'sa-east-1': 's3-website-sa-east-1.amazonaws.com',
}[region])

class Client {
constructor(serverless, options){
this.serverless = serverless;
Expand Down Expand Up @@ -247,10 +265,13 @@ class Client {

_uploadFile(filePath) {
let _this = this,
fileKey = filePath.replace(_this.clientPath, '').substr(1).replace(/\\/g, '/');
fileKey = filePath.replace(_this.clientPath, '').substr(1).replace(/\\/g, '/'),
urlRoot = regionToUrlRootMap(_this.region);

this.serverless.cli.log(`Uploading file ${fileKey} to bucket ${_this.bucketName}...`);
this.serverless.cli.log(`If successful this should be deployed at: https://s3.amazonaws.com/${_this.bucketName}/${fileKey}`)
this.serverless.cli.log('If successful this should be deployed at:')
this.serverless.cli.log(`https://${urlRoot}/${_this.bucketName}/${fileKey}`)
this.serverless.cli.log(`http://${_this.bucketName}.${urlRoot}/${fileKey}`)

fs.readFile(filePath, function(err, fileBuffer) {

Expand Down