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 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 Arcgis相交分析无法绘制一个或多个图形