[英]How do i deploy a simple AWS lambda function using AWS code deploy without using SAM?
The docs say I should specify a application revision in either.yaml or.json format when calling codedeploy.文档说我应该在调用 codedeploy 时以.yaml 或.json 格式指定应用程序修订。 But how do I deploy the actual function code through code deploy?但是如何通过代码部署部署实际的 function 代码?
There is no option to provide a zip with the code inside it.没有提供 zip 及其内部代码的选项。 Only json and yaml files are accepted.仅接受 json 和 yaml 文件。 How do I actually update/add the lambda function code through codedeploy?如何通过 codedeploy 实际更新/添加 lambda function 代码? The below images shows even through aws console, I can only specify a yaml or json appspec file.下图显示即使通过 aws 控制台,我也只能指定 yaml 或 json appspec 文件。
How do I actually deploy my function code here?我如何在此处实际部署我的 function 代码? ![Text]() ![文本]()
You have to deploy it before your CodeDeploy (CD) stage.您必须在 CodeDeploy (CD) 阶段之前部署它。 You can use CodeBuild (CB) for that.您可以为此使用CodeBuild (CB)。 So in your CI/CD pipeline, your CD stage would be executed after CB stage.因此,在您的 CI/CD 管道中,您的 CD 阶段将在 CB 阶段之后执行。 The CB stage would deploy and create a version of your function, which then would be used as an input to CD. CB 阶段将部署并创建 function 的版本,然后将其用作 CD 的输入。
As @Marcin mentioned, you need to update the actual function through your codebuild specification yaml file.正如@Marcin 提到的,您需要通过您的代码构建规范 yaml 文件更新实际的 function 。
there are plenty of approaches for having CI/CD for serverless lambda functions.有很多方法可以让 CI/CD 用于无服务器 lambda 功能。 (Cloudformation, Terraform, CodeDeploy, using only CodeBuild and update the code there!) (Cloudformation,Terraform,CodeDeploy,仅使用 CodeBuild 并在那里更新代码!)
what I personally do is using ECR, Docker Images to handle the CI/CD proccess, here's the flow:我个人所做的是使用 ECR、Docker 图像来处理 CI/CD 过程,流程如下:
in your buildspec.yml
file:在您的buildspec.yml
文件中:
here's a sample:这是一个示例:
version: 0.2
phases:
pre_build:
commands:
- echo "Build on `date`"
- aws ecr get-login-password --region ca-central-1 | docker login --username AWS --password-stdin YOUR_ECR_ADDRESS
- npm run test
build:
commands:
- echo Building the Docker image ... | tee -a log.txt
- docker build -t YOUR_ECR_ADDRESS/your-lambda:latest . 2>&1 | tee -a log.txt
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push YOUR_ECR_ADDRESS/your-lambda:latest
- aws lambda update-function-code --function-name your-lambda --image-uri YOUR_ECR_ADDRESS/your-lambda:latest > /dev/null
You can also have cloudformation as last stage so you can change a function specifications ie roles, timeout, ram usage, etc by changing only a template yml file.您还可以将 cloudformation 作为最后阶段,因此您可以通过仅更改模板 yml 文件来更改 function 规范,即角色、超时、内存使用等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.