【发布时间】:2022-12-15 15:41:14
【问题描述】:
我试图在构建完成后使 Cloudfront 缓存无效,我得到的是 Codebuild 中的以下错误:[Container] 2022/05/16 15:46:11 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: aws cloudfront create-invalidation --distribution-id myid --paths '/*'. Reason: exit status 254
这是我的 BuildSpec 定义
version: 0.2
env:
variables:
APP_NAME: "managerui"
phases:
install:
runtime-versions:
nodejs: 14.x
commands:
- echo install process started
- cd src/UI/managerui/
- ls
- npm install && npm install -g @angular/cli
build:
commands:
- echo build process started now
- ls
- ng build --configuration=production
post_build:
commands:
- echo build process finished, we should uplload to S3 now
- ls
- cd dist/
- ls -la
- aws s3 sync . s3://ett-manager-ui --delete
- aws cloudfront create-invalidation --distribution-id=myid--paths '/*
你看有什么不对的地方吗??我试过在我正在运行的笔记本电脑上运行创建失效指令并且它有效..
提前致谢
#更新
我已经解决了……这是一个缺少权限的问题……我已经添加了
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor1",
"Effect": "Allow",
"Action": [
"cloudfront:UpdateDistribution",
"cloudfront:DeleteDistribution",
"cloudfront:CreateInvalidation"
],
"Resource": "arn:aws:cloudfront::<account_id>:distribution/<distribution_id>"
}
]
}
它工作正常。
这个可以关闭
【问题讨论】:
-
您在哪里添加该权限?
-
我刚刚尝试过,它通过将它们添加到 CodePipeline 使用的服务角色中来工作;)
标签: amazon-cloudfront aws-codebuild