简体   繁体   English

使用 Jenkins 嵌套部署 AWS Lambda 函数

[英]Nested deployment of AWS Lambda funtions with Jenkins

I am learning how to deploy AWS Lambda functions from Jenkins. I have following forlder structure:我正在学习如何从 Jenkins 部署 AWS Lambda 函数。我有以下 forlder 结构:

src -> favorites -> findAll -> index.js
src -> favorites -> insert -> index.js
src -> movies -> findAll -> index.js
src -> movies -> findOne -> index.js

Essentially 4x functions.本质上是 4x 函数。

Here's part of Jenkinsfile:这是 Jenkinsfile 的一部分:

def functions = ['MoviesStoreListMovies', 'MoviesStoreSearchMovie', MoviesStoreViewFavorites', 'MoviesStoreAddToFavorites']
stage('Build'){
            sh """
                docker build -t ${imageName} .
                containerName=\$(docker run -d ${imageName})
                docker cp \$containerName:/app/node_modules node_modules
                docker rm -f \$containerName
                zip -r ${commitID()}.zip node_modules src
            """
}
stage('Push'){
            functions.each { function ->
                sh "aws s3 cp ${commitID()}.zip s3://${bucket}/${function}/"
}

At the end I expect to have 4x AWS S3 buckets with same.zip content in it (ie all 4 same folders/functions present in each bucket).最后,我希望有 4 个 AWS S3 存储桶,其中包含 same.zip 内容(即每个存储桶中存在所有 4 个相同的文件夹/函数)。

Here now my issue.现在这是我的问题。 The build stage.构建阶段。

 stage('Deploy'){
      functions.each { 
        function ->
         sh "aws lambda update-function-code --function-name ${function} --s3-bucket
         ${bucket} --s3-key ${function}/${commitID()}.zip --region ${region}"
       }
}

Since the zip has same content, how can be that the 4 functions are deployed as exactly 4 functions?既然zip的内容一样,那4个函数怎么会部署成正好4个函数呢? Again, each of the 4x.zip file contains in turn the same 4x folders/functions.同样,每个 4x.zip 文件依次包含相同的 4x 文件夹/函数。 So I would expect 4x4=16 functions eventually.所以我希望最终有 4x4=16 个函数。

What am I missing?我错过了什么?

Maybe my mistake.也许是我的错误。 I missed to say that Lambda functions get created with Terraform first.我没有说 Lambda 函数首先是用 Terraform 创建的。 And indeed Terraform creates handlers pointing to the right src paths:实际上 Terraform 创建了指向正确 src 路径的处理程序:

  module "MoviesStoreListMovies" {
  source = "./modules/function"
  name = "MoviesStoreListMovies"
  handler = "src/movies/findAll/index.handler"
  runtime = "nodejs12.x"
  environment = {
    TABLE_NAME = aws_dynamodb_table.movies.id
  }
}

module "MoviesStoreSearchMovie" {
  source = "./modules/function"
  name = "MoviesStoreSearchMovie"
  handler = "src/movies/findOne/index.handler"
  runtime = "nodejs12.x"
  environment = {
    TABLE_NAME = aws_dynamodb_table.movies.id
  }
}

module "MoviesStoreViewFavorites" {
  source = "./modules/function"
  name = "MoviesStoreViewFavorites"
  handler = "src/favorites/findAll/index.handler"
  runtime = "nodejs12.x"
  environment = {
    TABLE_NAME = aws_dynamodb_table.favorites.id
  }
}

module "MoviesStoreAddToFavorites" {
  source = "./modules/function"
  name = "MoviesStoreAddToFavorites"
  handler = "src/favorites/insert/index.handler"
  runtime = "nodejs12.x"
  environment = {
    TABLE_NAME = aws_dynamodb_table.favorites.id
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AWS lambda ResourceConflictException 部署 - AWS lambda ResourceConflictException on deployment AWS CloudFront Lambda@Edge 部署 - AWS CloudFront Lambda@Edge deployment 部署后获取更新的 AWS Lambda URL - Get updated AWS Lambda URL after deployment 一个项目中的多个 Spring Cloud Functions 部署在 AWS Lambda - Multiple Spring Cloud Functions in one project for deployment on AWS Lambda Jenkins CI/CD 部署到 AWS EKS 没有 Docker 注册表 - Jenkins CI/CD deployment to AWS EKS without Docker registry 将简单的 node.js 应用程序部署到 AWS Lambda 无服务器失败并出现 GeneralServiceException - Deployment of simple node js application to AWS Lambda Serverless Failing with GeneralServiceException 一个项目中的多个 Spring Cloud Functions 部署在 AWS Lambda - Multiple Spring Cloud Functions in one project for deployment on AWS Lambda 在 AWS Lambda 中运行 .NET 6 Web API 项目,部署为 ZIP - Running .NET 6 Web API project in AWS Lambda with ZIP deployment 测试 aws lambda python function 嵌套 json - Testing aws lambda python function with nested json 使用 AWS IoT Core 规则和 AWS Lambda 处理嵌套的 JSON 消息 - Handling nested JSON messages with AWS IoT Core rules and AWS Lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM