dongzao9044 2019-09-16 21:27
浏览 128
已采纳

尝试调用Go AWS Lambda函数时权限被拒绝

I've created a AWS Lambda function that I'm using a Webhook to call an API Gateway Below is the code I've built with go build -o main.go since I've been reading that you have to specify the extension.

package main

import (
    "context"
    "fmt"

    "github.com/aws/aws-lambda-go/lambda"
)

func HandleRequest(ctx context.Context) (string, error) {
    return fmt.Sprintf("Hello!"), nil
}

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

The issue is even though I have public permissions on my uploaded S3 function .zip as well as role permissions I'm still getting a permissions error.

{
  "errorMessage": "fork/exec /var/task/main: permission denied",
  "errorType": "PathError"
}
  • 写回答

1条回答 默认 最新

  • doulu1907 2019-09-16 22:16
    关注

    You're attempting to run the go source code file. You need to run the binary:

    # Build the binary for your module
    GOOS=linux go build main.go
    
    # Package the binary, note we're packaging "main", not "main.go" here:
    zip function.zip main
    
    # And upload "function.zip" this package to Lambda
    

    For more details, including directions to run through this process on other platforms, see the AWS Lambda Deployment documentations

    Also, you'll need to set the executable bit in the zipfile. There are a bunch of ways to do this, if you want to do it on Windows, you'll need to run a python script like this:

    import zipfile
    import time
    
    def make_info(filename):
        info = zipfile.ZipInfo(filename)
        info.date_time = time.localtime()
        info.external_attr = 0x81ed0000
        info.create_system = 3
        return info
    
    zip_source = zipfile.ZipFile("source_file.zip")
    zip_file = zipfile.ZipFile("dest_file.zip", "w", zipfile.ZIP_DEFLATED)
    
    for cur in zip_source.infolist():
        zip_file.writestr(make_info(cur.filename), zip_source.open(cur.filename).read(), zipfile.ZIP_DEFLATED)
    
    zip_file.close()
    

    This will take a source_file.zip and repackage it as dest_file.zip with the same contents, but with the executable bit set for all of the files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据