Skip to content

Commit 8d2418e

Browse files
committed
Correctly display s3 url based on documentation
Also log the subdomained version of the url
1 parent 0d68f9a commit 8d2418e

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

index.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,24 @@ const _ = require('lodash');
77
const mime = require('mime');
88
const fs = require('fs');
99

10+
// per http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_website_region_endpoints
11+
const regionToUrlRootMap = region => ({
12+
'us-east-2': 's3-website.us-east-2.amazonaws.com',
13+
'us-east-1': 's3-website-us-east-1.amazonaws.com',
14+
'us-west-1': 's3-website-us-west-1.amazonaws.com',
15+
'us-west-2': 's3-website-us-west-2.amazonaws.com',
16+
'ca-central-1': 's3-website.ca-central-1.amazonaws.com',
17+
'ap-south-1': 's3-website.ap-south-1.amazonaws.com',
18+
'ap-northeast-2': 's3-website.ap-northeast-2.amazonaws.com',
19+
'ap-southeast-1': 's3-website-ap-southeast-1.amazonaws.com',
20+
'ap-southeast-2': 's3-website-ap-southeast-2.amazonaws.com',
21+
'ap-northeast-1': 's3-website-ap-northeast-1.amazonaws.com',
22+
'eu-central-1': 's3-website.eu-central-1.amazonaws.com',
23+
'eu-west-1': 's3-website-eu-west-1.amazonaws.com',
24+
'eu-west-2': 's3-website.eu-west-2.amazonaws.com',
25+
'sa-east-1': 's3-website-sa-east-1.amazonaws.com',
26+
}[region])
27+
1028
class Client {
1129
constructor(serverless, options){
1230
this.serverless = serverless;
@@ -247,10 +265,13 @@ class Client {
247265

248266
_uploadFile(filePath) {
249267
let _this = this,
250-
fileKey = filePath.replace(_this.clientPath, '').substr(1).replace(/\\/g, '/');
268+
fileKey = filePath.replace(_this.clientPath, '').substr(1).replace(/\\/g, '/'),
269+
urlRoot = regionToUrlRootMap(_this.region);
251270

252271
this.serverless.cli.log(`Uploading file ${fileKey} to bucket ${_this.bucketName}...`);
253-
this.serverless.cli.log(`If successful this should be deployed at: https://s3-${_this.region}.amazonaws.com/${_this.bucketName}/${fileKey}`)
272+
this.serverless.cli.log('If successful this should be deployed at:')
273+
this.serverless.cli.log(`https://${urlRoot}/${_this.bucketName}/${fileKey}`)
274+
this.serverless.cli.log(`http://${_this.bucketName}.${urlRoot}/${fileKey}`)
254275

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

0 commit comments

Comments
 (0)