尝试调用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"
}

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.