问题描述
我已经在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
那就是我被困住的地方.那么我在做什么错了,错误是什么意思?
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部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!