[英]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.