【发布时间】:2020-04-04 18:42:57
【问题描述】:
我在 Golang 中开发了一组 Lambda 函数,并尝试使用 SAM 部署这些函数和 API 网关。
我在本地创建可执行文件,为每个 lambda 函数创建 zip 文件并将这些 zip 文件上传到 s3 存储桶。
我在 SAM 模板文件中给出了这个 S3 存储桶的引用。
我的 SAM 模板文件如下所示
myfunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://<<my-bucket>>/bin/handlers/myfunction.zip
Handler: myfunction
Role: !GetAtt CFLambdaExecutionRole.Arn
Events:
Getcfdemoapi:
Type: Api
Properties:
Path: /myfunction
Method: get
CreateCustomer:
Type: Api
Properties:
Path: /myfunction
Method: post
UpdateCustomer:
Type: Api
Properties:
Path: /customer
Method: put
DeleteCustomer:
Type: Api
Properties:
Path: /myfunction
Method: delete
部署成功。
我通过 API 网关调用了 lambda 函数。
我检查了 Cloud watch 日志并看到以下错误 -
错误 fork/exec /var/task/myfunction :没有这样的文件或目录: 路径错误
SAM模板有什么问题吗,与CodeUri和handler有关?
我正在 MacOS 上创建构建并使用以下命令进行构建 -
GOOS=linux GOARCH=amd64 go build
【问题讨论】:
-
myfunction.zip的结构是什么? -
你的问题可以添加功能代码吗?
-
您能否将创建 ZIP 文件的步骤包括在内?还有里面的目录/文件?
标签: amazon-web-services aws-lambda aws-api-gateway aws-sam