[英]CodeDeploy to S3
I have a site in a S3 bucket, configured for web access, for which I run an aws s3 sync
command every time I push on a specific git repository (I'm using Gitlab at the moment). 我在S3存储桶中有一个站点,配置为Web访问,每次我推送一个特定的git存储库时,我都会运行一个aws s3 sync
命令(我现在正在使用Gitlab)。
So if I push to stable
branch, a Gitlab runner performs the npm start build
command for building the site, and then aws s3 sync
to synchronize to a specific bucket. 因此,如果我推送到stable
分支,Gitlab npm start build
会执行npm start build
命令来构建站点,然后执行aws s3 sync
以同步到特定存储桶。
I want to migrate to CodeCommit and use pure AWS tools to do the same. 我想迁移到CodeCommit并使用纯AWS工具来做同样的事情。
So far I was able to successfully setup the repository, create a CodeBuild for building the artifact, and the artifact is being stored (not deployed) to a S3 bucket. 到目前为止,我能够成功设置存储库,创建用于构建工件的CodeBuild ,并将工件存储 (未部署)到S3存储桶。 Difference is that I can't get it to deploy to the root folder of the bucket instead of a subfolder, seems like the process is not made for that. 区别在于我无法将其部署到存储桶的根文件夹而不是子文件夹,似乎没有为此进行过程。 I need it to be on a root folder because how the web access is configured. 我需要它在根文件夹上,因为如何配置Web访问。
For the deployment process, I was taking a look at CodeDeploy but it doesn't actually let me deploy to S3 bucket, it only uses the bucket as an intermediary for deployment to a EC2 instance. 对于部署过程,我正在查看CodeDeploy,但它实际上并没有让我部署到S3存储桶,它只使用存储区作为部署到EC2实例的中介。 So far I get the feeling CodeDeploy is useful only for deployments involving EC2. 到目前为止,我感觉CodeDeploy仅对涉及EC2的部署有用。
This tutorial with a similar requirement than mine, uses CodePipeline and CodeBuild , but the deployment step is actually a aws s3 sync
command (same as I was doing on Gitlab), and the actual deployment step on CodePipeline is disabled. 本教程的要求与我的相似,使用CodePipeline和CodeBuild ,但部署步骤实际上是一个aws s3 sync
命令(与我在Gitlab上做的相同),并禁用了CodePipeline上的实际部署步骤。
I was looking into a solution which involves using AWS features made for this specific purpose, but I can't find any. 我正在寻找一个解决方案,其中涉及使用为此特定目的而制作的AWS功能,但我找不到任何解决方案。
I'm also aware of LambCI , but to me looks like what CodePipeline / CodeBuild is doing, storing artifacts (not deploying to the root folder of the bucket). 我也知道LambCI ,但对我来说看起来像CodePipeline / CodeBuild正在做什么,存储工件(不部署到存储桶的根文件夹)。 Plus, I'm looking for an option which doesn't require me to learn or deploy new configuration files (outside AWS config files). 另外,我正在寻找一个不需要我学习或部署新配置文件的选项(在AWS配置文件之外)。
Is this possible with the current state of AWS features? AWS功能的当前状态是否可以实现?
Today AWS has announced as a new feature the ability to target S3 in the deployment stage of CodePipeline. 今天,AWS已宣布在CodePipeline的部署阶段以新功能为目标S3。 The announcement is here , and the documentation contains a tutorial available here . 公告在这里 ,文档包含这里提供的教程。
Using your CodeBuild/CodePipeline approach, you should now be able to choose S3 as the deployment provider in the deployment stage rather than performing the sync in your build script. 使用CodeBuild / CodePipeline方法,您现在应该能够在部署阶段选择S3作为部署提供程序,而不是在构建脚本中执行同步。 To configure the phase, you provide an S3 bucket name, specify whether to extract the contents of the artifact zip, and if so provide an optional path for the extraction. 要配置阶段,请提供S3存储桶名称,指定是否提取工件zip的内容,如果是,则提供可选的提取路径。 This should allow you to deploy your content directly to the root of a bucket by omitting the path. 这应该允许您通过省略路径将内容直接部署到存储桶的根目录。
I was dealing with similar issue and as far as I was able to find out, there is no service which is suitable for deploying app to S3. 我正在处理类似的问题,据我所知,没有适合将应用程序部署到S3的服务。
AWS CodeDeploy is indeed for deploying code running as server. AWS CodeDeploy确实用于部署作为服务器运行的代码。
My solution was to use CodePipeline with three stages: 我的解决方案是使用CodePipeline有三个阶段:
I used this AWS lambda function from SeamusJ https://github.com/SeamusJ/deploy-build-to-s3 我在SeamusJ中使用了这个AWS lambda函数https://github.com/SeamusJ/deploy-build-to-s3
Several changes had to be made, I used node-unzip-2 instead of unzip-stream for unziping artifict from s3. 必须进行一些更改,我使用node-unzip-2而不是unzip-stream来解压缩来自s3的artifict。
Also I had to change ACLs in website.ts file 我还必须在website.ts文件中更改ACL
Uploading from CodeBuild is currently the best solution available. 从CodeBuild上传是目前最好的解决方案。
There's some suggestions on how to orchestrate this deployment via CodePipeline in this answer . 关于如何在此答案中通过CodePipeline协调此部署,有一些建议。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.