我正在通过自动部署基于Go的AWS Lambda,并遇到问题 .

我的AWS无服务器模板是:

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  HelloLambda:
    Type: AWS::Serverless::Function
    Properties:
      Handler: hello
      Runtime: go1.x
      CodeUri: ./deploy/hello.zip
      Environment:
        Variables: 
          S3_BUCKET: hello_lambda

我通过以下方式部署:

GOOS=linux GOARCH=amd64 go build -o ./deploy/hello
zip ./deploy/hello.zip ./deploy/hello
aws cloudformation package \
   --template-file hello.yaml \
   --output-template-file serverless-deploy_hello.yaml \
   --s3-bucket hello_deploy
aws cloudformation deploy\
 --template-file serverless-deploy_hello.yaml\
  --stack-name hello-lambda\
  --capabilities CAPABILITY_IAM

当Cloudformation做了它的事情时, serverless-deploy_hello.yamlCodeUri: s3://hello_deploy/17ab86653aab79eee51fc6f77d7a152e 并且s3桶包含zip文件(当我在本地下载并使用 cmp 它有点相同时) .

但是当我测试生成的Lambda时,它给了我:

{
  "errorMessage": "fork/exec /var/task/hello: no such file or directory",
  "errorType": "PathError"
}

不太确定我在这里做错了什么....

====已解决====

上面的zip命令也会压缩目录路径,因此可执行文件解压缩到 deploy/hello 而不是 ./hello .

因此,Lambda运行时无法连接到该进程 .