错误-发布到AWS Lambda函数

I am new on AWS. I was trying to do an http post to an aws lambda function and received an error 403(Forbidden). I understood I had to pass AWS_SECRET and AWS_Key with post. How do I do it? My coding language for post is golang.

Code in Context

url := "https://xxxxx.xxxxx-api.us-west-x.amazonaws.com/prod/xxxxxx"
var jsonStr = []byte(`{"title":"Some data"}`)

req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))

req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")

client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    panic(err)
}
defer resp.Body.Close()
fmt.Println("response Status:", resp.Status) // response message

Respose Message

response Status: 403 Forbidden

How should I pass the authentication parameters? Is it to be passed along with the url?

How you invoke a Lambda function over HTTP via API Gateway very much depends on how the API Gateway is configured.

By default there is no authentication, so plain POST might work:

$ curl -X POST https://x19vpdk568.execute-api.us-east-1.amazonaws.com/Prod/users -d '{"username":"noah"}'
{
  "id": "4c47648f-e419-456b-97b8-22f82a9df6cb",
  "username": "noah"
}

Check out my HTTP Functions with API Gateway and Lambda guide for tips on setting this simple configuration up.

You can configure API Gateway to use IAM for authentication, which requires the AWS access key and secret. In this case, you have follow the AWS Signature V4 authentication scheme. There is a v4 signer package in the aws-sdk-go which can help.

Finally, you can also configure API Gateway custom authorizers to require a custom header, etc. These schemes don't need AWS access keys.

All said, take a close look at your API Gateway configuration to get your POST working.