放大“发布”可创建S3存储桶,但不添加任何内容

时间:2019-04-11 00:54:46

标签: reactjs amazon-web-services amazon-s3 webpack aws-amplify

我正在使用AWS Amplify支持JS应用。我目前只有两个资源:API(appsync / graphql)和托管,这给了我一些问题。

amplify add hostingamplify push似乎都可以正常工作。 amplify publish(针对开发人员S3)给出了肯定的响应,并且在S3中创建了适当的存储桶,但该存储桶为空。该链接将我定向到出现错误的页面:

404 Not Found

    Code: NoSuchKey
    Message: The specified key does not exist.
    Key: index.html

我已经成功运行了JS amplify tutorial和当前应用程序的简单Alpha版本。当我调用amplify publish时,这些将正确填充新的S3存储桶。

index.html文件非常裸露,alpha版本和beta版本之间相同。只是一个标题,两个空div和一个<script>的调用main.bundle.js。旧的在index.html文件中包含CSS。

  • 请注意,npm start并在localhost中打开对于 ALL 变体来说都很好。

我只看到与alpha和当前的两个主要区别。

  1. 旧版本为.js,新版本为React的.jsx(均使用webpack)。
  2. 我的CSS现在位于外部文件中(使用webpack捆绑在一起)。

这是我的 app alpha 的webpack.config.js:

const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const path = require('path');

module.exports = {
    mode: 'development',
    entry: './src/app.js',
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/
            }
        ]
    },
    devServer: {
        contentBase: './dist',
        overlay: true,
        hot: true
    },
    plugins: [
        new CopyWebpackPlugin(['index.html']),
        new webpack.HotModuleReplacementPlugin()
    ]
};

这是 current 应用程序的webpack.config.js:

const CopyWebpackPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const path = require('path');

module.exports = {
    mode: 'development',
    entry: './src/app.jsx',
    output: {
        filename: '[name].bundle.js',
        path: path.resolve(__dirname, 'dist')
    },
    module: {
        rules: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: ['@babel/preset-env', '@babel/preset-react']
                }
            },{
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            }
        ]
    },
    devServer: {
        contentBase: './dist',
        overlay: true,
        hot: true
    },
    plugins: [
        new CopyWebpackPlugin(['index.html']),
        new webpack.HotModuleReplacementPlugin()
    ]
};

我不确定该问题是否与其他问题完全相关。

amplify add hosting的输出:

? Select the environment setup: DEV (S3 only with HTTP)
? hosting bucket name blahblahblahblahblahblahblahblah
? index doc for the website index.html
? error doc for the website index.html

You can now publish your app using the following command:
Command: amplify publish

amplify push的输出(肯定不需要此命令):

| Category | Resource name   | Operation | Provider plugin   |
| -------- | --------------- | --------- | ----------------- |
| Hosting  | S3AndCloudFront | Create    | awscloudformation |
| Api      | AppSyncResource | No Change |                   |
? Are you sure you want to continue? Yes
/ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS hostingS3AndCloudFront      AWS::CloudFormation::Stack Wed Apr 10 2019 20:34:27 GMT-0400 (Eastern Daylight Time) Resource creation Initiated
CREATE_IN_PROGRESS hostingS3AndCloudFront      AWS::CloudFormation::Stack Wed Apr 10 2019 20:34:26 GMT-0400 (Eastern Daylight Time)
UPDATE_IN_PROGRESS myapp-datetime AWS::CloudFormation::Stack Wed Apr 10 2019 20:34:20 GMT-0400 (Eastern Daylight Time) User Initiated
- Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS S3Bucket                                                         AWS::S3::Bucket            Wed Apr 10 2019 20:34:32 GMT-0400 (Eastern Daylight Time)
CREATE_IN_PROGRESS myapp-datetime-hostingS3AndCloudFront-16JS9AMKX3673 AWS::CloudFormation::Stack Wed Apr 10 2019 20:34:27 GMT-0400 (Eastern Daylight Time) User Initiated
\ Updating resources in the cloud. This may take a few minutes...

CREATE_IN_PROGRESS S3Bucket AWS::S3::Bucket Wed Apr 10 2019 20:34:33 GMT-0400 (Eastern Daylight Time) Resource creation Initiated
/ Updating resources in the cloud. This may take a few minutes...

CREATE_COMPLETE    myapp-datetime-hostingS3AndCloudFront-16JS9AMKX3673 AWS::CloudFormation::Stack Wed Apr 10 2019 20:35:00 GMT-0400 (Eastern Daylight Time)
CREATE_COMPLETE    BucketPolicy                                                     AWS::S3::BucketPolicy      Wed Apr 10 2019 20:34:58 GMT-0400 (Eastern Daylight Time)
CREATE_IN_PROGRESS BucketPolicy                                                     AWS::S3::BucketPolicy      Wed Apr 10 2019 20:34:58 GMT-0400 (Eastern Daylight Time) Resource creation Initiated
CREATE_IN_PROGRESS BucketPolicy                                                     AWS::S3::BucketPolicy      Wed Apr 10 2019 20:34:57 GMT-0400 (Eastern Daylight Time)
CREATE_COMPLETE    S3Bucket                                                         AWS::S3::Bucket            Wed Apr 10 2019 20:34:54 GMT-0400 (Eastern Daylight Time)
- Updating resources in the cloud. This may take a few minutes...

UPDATE_COMPLETE                     myapp-datetime AWS::CloudFormation::Stack Wed Apr 10 2019 20:35:06 GMT-0400 (Eastern Daylight Time)
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS myapp-datetime AWS::CloudFormation::Stack Wed Apr 10 2019 20:35:05 GMT-0400 (Eastern Daylight Time)
CREATE_COMPLETE                     hostingS3AndCloudFront      AWS::CloudFormation::Stack Wed Apr 10 2019 20:35:02 GMT-0400 (Eastern Daylight Time)
√ All resources are updated in the cloud

Hosting endpoint: http://myapp-datetime-hostingbucket.s3-website-us-east-1.amazonaws.com

amplify publish的输出:

| Category | Resource name   | Operation | Provider plugin   |
| -------- | --------------- | --------- | ----------------- |
| Api      | AppSyncResource | No Change |                   |
| Hosting  | S3AndCloudFront | No Change | awscloudformation |
? Are you sure you want to continue? Yes
√ All resources are updated in the cloud



> my-app@1.0.0 build C:\path\to\my-app
> webpack

Hash: 749f0c4a7f4c6cab8189
Version: webpack 4.29.6
Time: 4020ms
Built at: 04/10/2019 8:42:00 PM
         Asset       Size  Chunks             Chunk Names
    index.html  632 bytes          [emitted]
main.bundle.js   3.68 MiB    main  [emitted]  main
Entrypoint main = main.bundle.js
[0] fs (ignored) 15 bytes {main} [built]
[./css/style.css] 1.06 KiB {main} [built]
[./node_modules/css-loader/dist/cjs.js!./css/style.css] 1.15 KiB {main} [built]
[./node_modules/webpack/buildin/global.js] (webpack)/buildin/global.js 472 bytes {main} [built]
[./node_modules/webpack/buildin/harmony-module.js] (webpack)/buildin/harmony-module.js 573 bytes {main} [built]
[./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 497 bytes {main} [built]
[./src/app.jsx] 9.88 KiB {main} [built]
[./src/aws-exports.js] 689 bytes {main} [built]
[./src/graphql/mutations.js] 688 bytes {main} [built]
[./src/graphql/queries.js] 649 bytes {main} [built]
[./src/utils/client-handler.jsx] 3.97 KiB {main} [built]
[./src/utils/flag-form.jsx] 6.73 KiB {main} [built]
    + 500 hidden modules
frontend build command exited with code 0
√ Uploading files successful.
Your app is published successfully.
http://myapp-datetime-hostingbucket.s3-website-us-east-1.amazonaws.com

但是,当我点击链接时,出现上述错误404。

如果我尝试发布到产品,我的应用程序也会失败。我认为这是由相同的问题引起的。

0 个答案:

没有答案