Skip to content

Commit 55a5667

Browse files
author
Shankar Raju
committed
Merge remote-tracking branch 'origin/amplify-cli' into temp
2 parents 5abf786 + 2fa7f87 commit 55a5667

3 files changed

Lines changed: 38 additions & 12 deletions

File tree

amplifycli_react_tutorial.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ Without making any changes to your React application, add web hosting as follows
3636
amplify add hosting
3737
```
3838

39+
You would be prompted next to select the environment setup. Select **DEV (S3 only with HTTP)** for quick prototyping and testing, and once production ready you could run the `amplify update hosting` command to publish your app to Amazon Cloudfront (a CDN service).
3940
When you're prompted for information, such as the bucket name or application files, you can use the default values by pressing **Enter**.
4041

4142
**Note** You can use an order alias to add or remove category features. You can also run `amplify hosting add`.
4243

43-
Run `amplify status` to see that status (not deployed). Next, build and deploy your site by running `amplify publish`. After it's complete, your application is available in an S3 hosting bucket for testing. It's also fronted with an Amazon CloudFront distribution.
44+
Run `amplify status` to see that status (not deployed). Next, build and deploy your site by running `amplify publish` or `amplify publish -invalidate-cache` - for cache invalidation in the distribution network (if Cloudfront is added via the hosting category). After it's complete, your application is available in an S3 hosting bucket for testing. It's also fronted with an Amazon CloudFront distribution. (if it is added via the hosting category in the prior bucket)
4445

4546
# Add User Registration and Sign In
4647

@@ -70,7 +71,7 @@ You can now use `amplify publish` to build and publish your app again. This time
7071

7172
# Add Analytics and Storage
7273

73-
Next, we'll add some features, like tracking user behavior analytics and uploading/downloading images in the cloud. Start by running `amplify add analytics` in your project. You can enable analytics for authenticated users only, or for users that aren't authenticated. You've already added authentication to your project so you can choose `No` and then `Yes` to overwrite when you're prompted. Or, you an also try a new project without authentication configured to test this feature.
74+
Next, we'll add some features, like tracking user behavior analytics and uploading/downloading images in the cloud. Start by running `amplify add analytics` in your project. You can enable analytics for authenticated users only, or for users that aren't authenticated. You've already added authentication to your project so you can choose `No`. Or, you an also try a new project without authentication configured to test this feature.
7475

7576
Run `amplify add storage` and then select the Amazon S3 provider. When complete, run `amplify push` to create the cloud resources.
7677

packages/amplify-category-hosting/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@ async function add(context) {
2525
} else if (disabledServices.length === 1) {
2626
return categoryManager.runServiceAction(context, disabledServices[0], 'enable');
2727
}
28-
throw new Error('Hosting is already fully enabled.');
28+
const errorMessage = 'Hosting is already fully enabled.';
29+
context.print.error(errorMessage);
30+
throw new Error(errorMessage);
2931
} else {
30-
throw new Error('Hosting is not available from enabled providers.');
32+
const errorMessage = 'Hosting is not available from enabled providers.';
33+
context.print.error(errorMessage);
34+
throw new Error(errorMessage);
3135
}
3236
}
3337

packages/amplify-category-hosting/lib/S3AndCloudFront/index.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const fs = require('fs-extra');
2+
const inquirer = require('inquirer');
23
const Ora = require('ora');
34
const path = require('path');
45
const opn = require('opn');
@@ -12,12 +13,20 @@ const serviceName = 'S3AndCloudFront';
1213
const providerPlugin = 'awscloudformation';
1314
const templateFileName = 'template.json';
1415

16+
17+
const DEV = 'DEV (S3 only with HTTP)';
18+
const PROD = 'PROD (S3 with CloudFront using HTTPS)';
19+
const Environments = [
20+
DEV,
21+
PROD,
22+
];
23+
1524
async function enable(context) {
1625
let templateFilePath = path.join(__dirname, 'template.json');
1726
context.exeInfo.template = JSON.parse(fs.readFileSync(templateFilePath));
1827

1928
// will take this out once cloudformation invoke and wait are separated;
20-
checkCDN(context);
29+
await checkCDN(context);
2130

2231
await configManager.init(context);
2332

@@ -44,16 +53,27 @@ async function enable(context) {
4453
);
4554
}
4655

47-
48-
function checkCDN(context) {
49-
if (context.parameters.options.nocdn) {
50-
delete context.exeInfo.template.Resources.CloudFrontDistribution;
51-
delete context.exeInfo.template.Outputs.CloudFrontDistributionID;
52-
delete context.exeInfo.template.Outputs.CloudFrontDomainName;
53-
delete context.exeInfo.template.Outputs.CloudFrontSecureURL;
56+
async function checkCDN(context) {
57+
const selectEnvironment = {
58+
type: 'list',
59+
name: 'environment',
60+
message: 'Select the environment setup:',
61+
choices: Environments,
62+
default: DEV,
63+
};
64+
const answer = await inquirer.prompt(selectEnvironment);
65+
if (answer.environment === DEV) {
66+
removeCDN(context);
5467
}
5568
}
5669

70+
function removeCDN(context) {
71+
delete context.exeInfo.template.Resources.CloudFrontDistribution;
72+
delete context.exeInfo.template.Outputs.CloudFrontDistributionID;
73+
delete context.exeInfo.template.Outputs.CloudFrontDomainName;
74+
delete context.exeInfo.template.Outputs.CloudFrontSecureURL;
75+
}
76+
5777
async function configure(context) {
5878
const projectBackendDirPath = context.amplify.pathManager.getBackendDirPath();
5979
const serviceDirPath = path.join(projectBackendDirPath, constants.CategoryName, serviceName);
@@ -95,6 +115,7 @@ function console(context) {
95115
amplifyMeta[constants.CategoryName][serviceName].output;
96116
const consoleUrl =
97117
`https://s3.console.aws.amazon.com/s3/buckets/${bucket}/?region=${region}&tab=overview`;
118+
context.print.info(chalk.green(consoleUrl));
98119
opn(consoleUrl, { wait: false });
99120
}
100121

0 commit comments

Comments
 (0)