【发布时间】:2022-08-14 06:27:55
【问题描述】:
我有一个综合和部署一些基础设施的 CDK 管道堆栈。创建基础设施后,我想构建一个前端反应应用程序,该应用程序知道新构建的 API 网关的 URL。构建应用程序后,我想将构建的文件移动到新创建的 S3 存储桶中。
我的前两个步骤没有问题。我使用 CfnOutput 来获取 API URL 和存储桶名称。然后我在我的 shell 步骤中使用envFromCfnOutputs 来构建具有正确环境变量设置的反应应用程序。
我不知道如何将我的文件移动到 s3 存储桶。我已经尝试了几天来使用 s3deploy 找出一些东西,但遇到了各种权限问题。我以为我可以尝试只使用 aws cli 并手动移动文件,但我不知道如何授予 CLI 命令添加和删除对象的权限。为了让事情变得更复杂一些,我的基础设施被部署到与我的管道所在的单独帐户中。
知道如何使用 CLI 或其他关于如何将构建的文件移动到存储桶的想法吗?
// set up pipeline
const pipeline = new CodePipeline(this, id, {
crossAccountKeys: true,
pipelineName: id,
synth: mySynthStep
});
// add a stage with all my constructs
const pipelineStage = pipelineAddStage(myStage)
// create a shellstep that builds and moves the frontend assets
const frontend = new ShellStep(\'FrontendBuild\', {
input: source,
commands: [
\'npm install -g aws-cli\',
\'cd frontend\',
\'npm ci\',
\'VITE_API_BASE_URL=\"$AWS_API_BASE_URL\" npm run build\',
\'aws s3 sync ./dist/ s3://$AWS_FRONTEND_BUCKET_NAME/ --delete\'
],
envFromCfnOutputs: {
AWS_API_BASE_URL: myStage.apiURL,
AWS_FRONTEND_BUCKET_NAME: myStage.bucketName
}
})
// add my step as a poststep to my stage.
pipelineStage.addPost(frontendApp);
-
请改用
CodeBuidStep,它允许您向角色策略添加权限。
标签: amazon-web-services amazon-s3 aws-cdk aws-pipeline