我正在尝试使用AWS CodePipeline构建Go中最简单的Lambda函数。尽管我已经玩了大约2周了,但我还是没能把它部署好。
main.go
package main
import (
"context"
"github.com/aws/aws-lambda-go/lambda"
)
func HandleRequest(ctx context.Context) (string, error) {
return "Hello from Go!", nil
}
func main() {
lambda.Start(HandleRequest)
}
buildspec.yml
version: 0.2
env:
variables:
S3_BUCKET: dlp-queuetime
PACKAGE: dlp-queuetime-fetcher
phases:
install:
runtime-versions:
golang: 1.12
commands:
# AWS Codebuild Go images use /go for the $GOPATH so copy the src code into that dir structure
- mkdir -p "/go/src/$(dirname ${PACKAGE})"
- ln -s "${CODEBUILD_SRC_DIR}" "/go/src/${PACKAGE}"
# Print all environment variables (handy for AWS CodeBuild logs)
- env
# Install Lambda Go
- go get github.com/aws/aws-lambda-go/lambda
pre_build:
commands:
# Make sure we're in the project directory within our GOPATH
- cd "/go/src/${PACKAGE}"
# Fetch all dependencies
- go get -t ./...
build:
commands:
# Build our Go app
- go build -o main
post_build:
commands:
- echo Build completed on `date`
artifacts:
type: zip
files:
- appspec.yml
- main
appspec.yml
version: 0.0
Resources:
- dlpQueueTimeFetcher:
Type: AWS::Lambda::Function
Properties:
Name: "dlpQueueTimeFetcher"
Alias: "v0"
CurrentVersion: "1"
TargetVersion: "2"
在部署期间,CodeDeploy抛出以下错误:操作执行失败-- BundleType必须是YAML或JSON。
似乎CodeDeploy无法找到我的appspec.yml
文件,尽管它是在构建规范的artifacts
部分中定义的。我在这里做错什么了?
发布于 2019-10-09 11:36:32
在将CodePipeline与CodeDeploy连接用于Lambda部署时,您所面临的问题是众所周知的,因为CodeDeploy正在寻找Yaml或Json应用程序规范文件,而CodePipeline提供的工件是包含appspec的zip文件:
现在,您可以使用CloudFormation作为管道中Lambda函数的部署工具。部署Lambda函数的基本思想如下:
directory
$-模板--文件{your_S3_bucket}
$-模板--文件packaged.yaml --堆栈名称stk1 --功能stk1
您可以将模板代码(步骤1-2)保存在CodeCommit/Github中,并在一个Step4步骤中执行CodeBuild。对于Step5,我建议通过CodePipeline中的一个CloudFormation操作来完成它,该操作将"packaged.yaml“文件作为输入工件输入。
上面的过程在这里详细介绍:https://docs.aws.amazon.com/en_us/lambda/latest/dg/build-pipeline.html
https://stackoverflow.com/questions/58300554
复制相似问题