使用Go&部署AWS Lambda云形成 [英] Deploying AWS Lambda with Go & Cloudformation

查看:101
本文介绍了使用Go&部署AWS Lambda云形成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working through an automated deployment of a Go-based AWS Lambda, and having issues.

我的AWS无服务器模板是:

My AWS Serverless template is:

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

我通过以下方式进行部署:

I deploy this via:

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.yaml具有CodeUri: s3://hello_deploy/17ab86653aab79eee51fc6f77d7a152e,并且s3存储桶包含zip文件(当我在本地下载它并使用cmp时,它有点相同).

When Cloudformation does its thing, serverless-deploy_hello.yaml has CodeUri: s3://hello_deploy/17ab86653aab79eee51fc6f77d7a152e and that s3 bucket contains the zip file (when I download it locally & use cmp it's bit-identical).

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

BUT when I test the resulting Lambda, it gives me:

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

不太确定我在做什么错....

Not quite sure what I'm doing wrong here....

====已解决====

==== RESOLVED ====

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

The zip command above zips the directory path as well, so the executable unzips to deploy/hello rather than ./hello.

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

Accordingly, the Lambda runtime can't connect to the process.

推荐答案

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

这将在zip文件中查找hello函数,作为应用程序的起点.如果要继续使用主要功能或其他一些功能

This will look for the hello function in your zipfile as an starting point of the Application. If you want to continue with the main function or some other function

func main() {
    lambda.Start(HandleLambdaEvent)
}

您需要在AWS Lambda函数模板上更改处理程序名称(默认情况下为hello).

You need to change the handler Name on AWS Lambda function template (By default it is hello).

这篇关于使用Go&部署AWS Lambda云形成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆