使用AWS S3和CodePipeline自动执行Angular 7 App部署 [英] Automating Angular 7 App Deployment with AWS S3 and CodePipeline

查看:100
本文介绍了使用AWS S3和CodePipeline自动执行Angular 7 App部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在AWS S3存储桶上托管了一个angular 7应用程序作为静态网站,现在想在我的github存储库更新时自动部署较新版本.

I have hosted an angular 7 app on AWS S3 bucket as a static website and now want to automate the deployment of newer version when my github repo is updated.

我希望新版本中的文件替换s3存储桶中先前版本的文件.这就是我要怎么做

I want the files from the newer version to replace the files of the previous version in the s3 bucket. Here's how I am going about it

我有一个buildspec文件

I have a buildspec file

version: 0.2

phases:
  install:
    commands:
      # install dependencies
      - echo Installng source NPM dependencies...
      - npm install npm@latest -g
      - npm install -g @angular/cli

  pre_build:
    commands:
      - echo Prebuild steps
      - npm install

  build:
    commandS:
      # build angular app
      - echo Build started on `date`
      - ng build

  post_build:
    commands:
      # clear S3 bucket
      - aws s3 rm s3://${S3_BUCKET} --recursive
      - echo S3 bucket cleared
      # copy files from dist folder into S3 bucket
      - aws s3 cp dist s3://${S3_BUCKET} --recursive
      - echo Build completed on `date`

代码流水线运行时,该过程在post_build失败,如此处的日志所示

when code pipeline runs, the process fails at post_build as shown in the log here

[容器] 2019/04/11 10:33:49运行命令aws s3 rm s3://$ {S3_BUCKET}-递归 /usr/local/lib/python2.7/dist-packages/urllib3/util/ssl_.py:354:SNIMissingWarning:已发出HTTPS请求,但是TLS的SNI(服务器名称指示)扩展名不可用平台.这可能会导致服务器出示不正确的TLS证书,从而可能导致验证失败.您可以升级到较新版本的Python来解决此问题.有关更多信息,请参见 https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings SNISSISSING警告 删除失败:s3://trips9ja-admin/3rdpartylicenses.txt调用DeleteObject操作时发生错误(AccessDenied):访问被拒绝 删除失败:s3://trips9ja-admin/Trips9jaPipeline/SourceArti/FyvYEvb.zip调用DeleteObject操作时发生错误(AccessDenied):访问被拒绝 删除失败:s3://trips9ja-admin/assets/bus.png调用DeleteObject操作时发生错误(AccessDenied):访问被拒绝

[Container] 2019/04/11 10:33:49 Running command aws s3 rm s3://${S3_BUCKET} --recursive /usr/local/lib/python2.7/dist-packages/urllib3/util/ssl_.py:354: SNIMissingWarning: An HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings SNIMissingWarning delete failed: s3://trips9ja-admin/3rdpartylicenses.txt An error occurred (AccessDenied) when calling the DeleteObject operation: Access Denied delete failed: s3://trips9ja-admin/Trips9jaPipeline/SourceArti/FyvYEvb.zip An error occurred (AccessDenied) when calling the DeleteObject operation: Access Denied delete failed: s3://trips9ja-admin/assets/bus.png An error occurred (AccessDenied) when calling the DeleteObject operation: Access Denied

那就是我被困住的地方.那么我在做什么错了,错误是什么意思?

And that's where I got stuck. So what is it I am doing wrong and what does the error mean?

我有一个S3存储桶策略,以允许这样的代码构建访问

I have an S3 bucket policy to allow Code build access like this

{
            "Sid": "CodeBuildPermision",
            "Effect": "Allow",
            "Principal": {
                "AWS": "arn:aws:iam::735681810231:role/service-role/codebuild-service-role"
            },
            "Action": "s3:*",
            "Resource": "arn:aws:s3:::<bucket name>"
        }

推荐答案

通过在S3存储桶策略的"Resource"中添加另一行来解决此问题,该行允许像这样访问存储桶的所有内容 "Resource": ["arn:aws:s3:::<bucket name>", "arn:aws:s3:::<bucket name>/*"]

Resolved the issue by adding another line to the "Resource" of the S3 bucket policy that allows access to all contents of the bucket like this "Resource": ["arn:aws:s3:::<bucket name>", "arn:aws:s3:::<bucket name>/*"]

这篇关于使用AWS S3和CodePipeline自动执行Angular 7 App部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆