Amazon web services 为AWS SAM应用程序创建代码管道、部署阶段时出现问题
我已经为我的AWS SAM应用程序创建了一个工作代码管道。 它仅在以下Amazon web services 为AWS SAM应用程序创建代码管道、部署阶段时出现问题,amazon-web-services,amazon-cloudformation,aws-code-deploy,aws-codepipeline,aws-sam,Amazon Web Services,Amazon Cloudformation,Aws Code Deploy,Aws Codepipeline,Aws Sam,我已经为我的AWS SAM应用程序创建了一个工作代码管道。 它仅在以下buildspec.yaml文件中使用Source和Build阶段 version: 0.2 phases: install: runtime-versions: python: 3.7 commands: - pip install --user aws-sam-cli - USER_BASE_PATH=$(python -m site --user-base)
buildspec.yaml
文件中使用Source和Build阶段
version: 0.2
phases:
install:
runtime-versions:
python: 3.7
commands:
- pip install --user aws-sam-cli
- USER_BASE_PATH=$(python -m site --user-base)
- export PATH=$PATH:$USER_BASE_PATH/bin
build:
commands:
- sam build
post_build:
commands:
sam package --s3-bucket deploy-bucket --output-template-file deployment.yaml
# finally:
# sam deploy --template-file deployment.yaml --stack-name MyStackSAM--region us-east-1 --capabilities CAPABILITY_IAM
正如您所见,我已经注释掉了最后两行,因为我想将该操作移动到CodePipeline中的部署阶段
我的部署步骤如下所示:
此时,我的CloudFormationPipelineServiceRole
拥有完全的管理员权限,尽管如此,由于执行此阶段,我仍然会收到以下错误
Action execution failed
Access Denied (Service: Amazon S3; Status Code: 403; Error Code: AccessDenied; Request ID: XXXXFFFFFXXXX; S3 Extended Request ID: XXXXFFFFFXXXXFFFFFXXXXX=)
我一直在想我为什么会犯这个错误。任何帮助都将不胜感激。首先,
sam包
需要通过--模板文件
标志传递的源模板文件。我在你的代码中没有看到模板文件。您正在尝试打包哪个模板文件
其次,您没有将必要的工件上载到s3存储桶。您上传的唯一内容是压缩代码,但正如您从已注释掉的命令中所看到的:
sam deploy --template-file deployment.yaml --stack-name MyStackSAM--region us-east-1 --capabilities CAPABILITY_IAM
您还需要这个文件deployment.yaml
,但您没有在代码中指定它。代码构建无法猜测要保留哪些工件
您需要在buildspec文件的底部添加额外的工件
部分,并指定这些工件
artifacts:
type: zip
files:
- template.yaml # (where do you have this file?)
- outputtemplate.yaml # (deployment.yaml in your case)
请注意,工件
部分需要与版本
和阶段
version: 0.2
phases:
...
artifacts:
...
首先,
sam包
需要通过--模板文件
标志传递的源模板文件。我在你的代码中没有看到模板文件。您正在尝试打包哪个模板文件
其次,您没有将必要的工件上载到s3存储桶。您上传的唯一内容是压缩代码,但正如您从已注释掉的命令中所看到的:
sam deploy --template-file deployment.yaml --stack-name MyStackSAM--region us-east-1 --capabilities CAPABILITY_IAM
您还需要这个文件deployment.yaml
,但您没有在代码中指定它。代码构建无法猜测要保留哪些工件
您需要在buildspec文件的底部添加额外的工件
部分,并指定这些工件
artifacts:
type: zip
files:
- template.yaml # (where do you have this file?)
- outputtemplate.yaml # (deployment.yaml in your case)
请注意,工件
部分需要与版本
和阶段
version: 0.2
phases:
...
artifacts:
...
工作得很有魅力!为了回答您关于
template.yaml
的问题,我认为sam build
默认为这个特定的名称,如果没有指定任何内容。所以我最后只在文件:
部分添加了部署.yaml
,这就成功了。再次感谢!工作得很有魅力!为了回答您关于template.yaml
的问题,我认为sam build
默认为这个特定的名称,如果没有指定任何内容。所以我最后只在文件:
部分添加了部署.yaml
,这就成功了。再次感谢!