2

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?

2
  • 1
    To be clear, you are posting at an API Gateway endpoint which is backed by a lambda function? The issue is with the api configuration. I'm guessing the X-Custom-Header there is part of your API authorization? I'd look to double check that side of things. Commented Aug 5, 2016 at 9:28
  • @stevepkr84 can you please explain how to send the params? Commented Aug 8, 2016 at 6:44

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.