简体   繁体   English

如何使用 AWS 代码部署而不使用 SAM 部署简单的 AWS lambda function?

[英]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 过程,流程如下:

  1. create an ECR repository创建 ECR 存储库
  2. create a docker image of your lambda function创建 lambda function 的 docker 映像
  3. push the docker image to the ECR将 docker 镜像推送到 ECR

in your buildspec.yml file:在您的buildspec.yml文件中:

  1. try to get credentials for ECR尝试获取 ECR 的凭据
  2. and build the lambda docker image based on the artifact coming from source section in codepipeline并基于来自代码管道中源部分的工件构建 lambda docker 图像
  3. push the new docker image to ECR将新的 docker 映像推送到 ECR
  4. update the lambda with the docker image.使用 docker 映像更新 lambda。

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.

相关问题 如何使用 lerna 将 monorepo 代码部署到 AWS Lambda? - How do I deploy monorepo code to AWS Lambda using lerna? 如何使用 SAM 对 AWS Lambda 环境变量进行编码? - How do I code AWS Lambda env variables using SAM? 如果没有 function 代码更改,如何使用 Codepipeline 部署 AWS Lambda 而无需重建它? - How to deploy AWS Lambda using Codepipeline without rebuilding it if there are no function code changes? 使用 sam init 部署 AWS Lambda“Hello World”,sam build sam deploy defaults 失败,无法为 sam-app 创建变更集 - Deploying AWS Lambda "Hello World" using sam init, sam build sam deploy defaults fails with Failed to create changeset for sam-app 如何构建、package 和部署 AWS SAM lambda function 从 azure Devops CI/CD 管道到 AWS - how to build, package and deploy AWS SAM lambda function of python from azure Devops CI/CD pipeline to AWS 如何使用 CodePipleline 部署 AWS lambda? - How to to deploy AWS lambda using CodePipleline? 使用AWS CDK部署带有测试事件的AWS Lambda函数 - Deploy an AWS Lambda function with test events using AWS CDK 如何使用适用于AWS Lambda的无服务器部署来部署环境变量 - How to deploy environment variable using serverless deploy for AWS lambda 如何让 AWS SAM 部署使用 aws 配置文件? - How do you make AWS SAM deploy use aws profile? 在源代码不可见的情况下部署 AWS Lambda 函数 - Deploy AWS Lambda function without source code being visible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM