如何创建代码管道以从存储在github的Java代码构建jar文件并将其部署到lambda函数? [英] How to create a codepipeline to build jar file from java code stored at github and deploy it to lambda function?

查看:284
本文介绍了如何创建代码管道以从存储在github的Java代码构建jar文件并将其部署到lambda函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建一个代码管道,该代码管道将从github获取代码(java)来构建jar文件并将其部署到aws lamda(或将jar存储在特定的S3存储桶中).我只想使用AWS平台提供的工具.

I want to build a codepipeline that will get the code(java) from github build a jar file and deploy it to aws lamda(or store the jar in a specific S3 bucket). I only want to use tools provided by AWS platform only.

如果仅使用Codebuild,则可以从github代码构建jar并将其存储到S3(

If I am using only Codebuild I am able to build jar from the github code and store it to S3(https://docs.aws.amazon.com/codebuild/latest/userguide/getting-started.html) and I am using a deployer lamda function to deploy the code to my service lamda. Whenever there is any change in the S3 bucket deployer lamda gets triggred.

DrawBack:问题是我在将更改提交到github后每次都要手动运行codebuild.我希望此代码构建可以自动检测来自github的更改.

DrawBack: Problem with this is I have to run codebuild manually everytime after commiting changes to github. I want this codebuild to detect changes automatically from github.

为解决上述问题,我创建了一个代码管道,该代码管道使用github webhooks检测代码更改,但此处创建的是zip文件而不是jar

To solve the above issue I have made a code pipeline which detect code changes using github webhooks but here it is creating zip file instead of jar

所以我实际上正在尝试的是:

So what I am actually trying is:

GitHub(changes)---> codebuild->将jar文件存储到具有特定名称的特定S3存储桶或部署到lambda

GitHub(changes)--->codebuild-->store jar file to specific S3 bucket with specific name or deploy to lambda

buildspec.yml

buildspec.yml

    version: 0.2

    phases:
  build:
    commands:
      - echo Build started on `date`
      - mvn test
  post_build:
    commands:
      - echo Build completed on `date`
      - mvn package
artifacts:
  files:
    - target/testfunction-1.0.0-jar-with-dependencies.jar

推荐答案

CodePipeline工件位置对于每个管道执行都是不同的,因此它们是隔离的.

CodePipeline artifact locations are different for each pipeline execution so they're isolated.

我认为您想要做的是在CodeBuild中生成一个JAR文件,该文件最终将以ZIP格式在CodePipeline工件中显示.您可以添加第二个CodeBuild动作,该动作接受第一个CodeBuild动作的输出(CodeBuild动作将为您解压缩输入工件)并部署到S3(使用AWS CLI编写脚本非常简单).

I think what you'll want to do is produce a JAR file in CodeBuild, which will end up in a CodePipeline artifact with a ZIP format. You can add a second CodeBuild action that accepts the output of the first CodeBuild action (the CodeBuild action will unzip the input artifact for you) and deploys to S3 (this is pretty trivial to script with the the AWS CLI).

完全可以将两个CodeBuild操作组合在一起,但是我想将"build"和"deploy"步骤分开.

It's entirely possible to combine both CodeBuild actions, but I like to keep the "build" and "deploy" steps separate.

这篇关于如何创建代码管道以从存储在github的Java代码构建jar文件并将其部署到lambda函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆